From 58b80755833d464f2c4f06df658b5ba394d5d6ff Mon Sep 17 00:00:00 2001 From: Sergey Krylov Date: Sat, 27 Jun 2026 13:52:37 +0300 Subject: [PATCH] refactor(frontend): deduplicate analytics metric cells and restore text states --- .../ui/BrokerDashboardAnalyticsCard.tsx | 139 +++++------------- .../ui/BrokerDashboardCard.tsx | 3 +- 2 files changed, 40 insertions(+), 102 deletions(-) diff --git a/apps/frontend/src/widgets/broker-dashboard/ui/BrokerDashboardAnalyticsCard.tsx b/apps/frontend/src/widgets/broker-dashboard/ui/BrokerDashboardAnalyticsCard.tsx index 28dd785..5695160 100644 --- a/apps/frontend/src/widgets/broker-dashboard/ui/BrokerDashboardAnalyticsCard.tsx +++ b/apps/frontend/src/widgets/broker-dashboard/ui/BrokerDashboardAnalyticsCard.tsx @@ -1,4 +1,4 @@ -import { Metric } from '@moex-vibe/design-system' +import { Metric, Text } from '@moex-vibe/design-system' import { Box } from '@mui/material' import type { BrokerAnalytics } from '@/shared/api' import { @@ -17,6 +17,19 @@ type AnalyticsField = | 'totalCoupons' | 'totalReceived' +const ANALYTICS_METRICS: readonly { + field: AnalyticsField + label: string + testId: string +}[] = [ + { field: 'totalDeposits', label: 'Пополнения', testId: 'dashboard-analytics-totalDeposits' }, + { field: 'totalWithdrawn', label: 'Выводы', testId: 'dashboard-analytics-totalWithdrawn' }, + { field: 'netInvested', label: 'Нетто', testId: 'dashboard-analytics-netInvested' }, + { field: 'totalDividends', label: 'Дивиденды', testId: 'dashboard-analytics-totalDividends' }, + { field: 'totalCoupons', label: 'Купоны', testId: 'dashboard-analytics-totalCoupons' }, + { field: 'totalReceived', label: 'Всего получено', testId: 'dashboard-analytics-totalReceived' }, +] + function analyticsTone(field: AnalyticsField, value: number): MoneyTone { if (field === 'totalWithdrawn') { return value > 0 ? 'negative' : moneyTone(value) @@ -40,13 +53,13 @@ export function BrokerDashboardAnalyticsCard({ isError: boolean }) { return ( - + {isError ? ( - + Не удалось загрузить аналитику ) : isLoading ? ( - + Загрузка аналитики… ) : !data ? ( - + Нет данных для аналитики ) : ( - - {analyticsDisplay('totalDeposits', data.totalDeposits, data.currency)} - - } - /> - - {analyticsDisplay('totalWithdrawn', data.totalWithdrawn, data.currency)} - - } - /> - - {analyticsDisplay('netInvested', data.netInvested, data.currency)} - - } - /> - - {analyticsDisplay('totalDividends', data.totalDividends, data.currency)} - - } - /> - - {analyticsDisplay('totalCoupons', data.totalCoupons, data.currency)} - - } - /> - - {analyticsDisplay('totalReceived', data.totalReceived, data.currency)} - - } - /> + {ANALYTICS_METRICS.map(({ field, label, testId }) => { + const value = data[field] + const tone = analyticsTone(field, value) + return ( + + {analyticsDisplay(field, value, data.currency)} + + } + /> + ) + })} )} diff --git a/apps/frontend/src/widgets/broker-dashboard/ui/BrokerDashboardCard.tsx b/apps/frontend/src/widgets/broker-dashboard/ui/BrokerDashboardCard.tsx index 50ea7ff..3981c36 100644 --- a/apps/frontend/src/widgets/broker-dashboard/ui/BrokerDashboardCard.tsx +++ b/apps/frontend/src/widgets/broker-dashboard/ui/BrokerDashboardCard.tsx @@ -19,10 +19,11 @@ export function BrokerDashboardCard({ sx, ariaLabel, }: BrokerDashboardCardProps) { + const resolvedAriaLabel = ariaLabel ?? title return (