From 6b6e0abe4073a70d1b665e6dc4e1ae247e13cd46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D0=BE=D0=B2=20=D0=90=D1=80=D1=82?= =?UTF-8?q?=D0=B5=D0=BC?= Date: Wed, 17 Jun 2026 11:22:24 +0300 Subject: [PATCH] add translation for tags --- src/api/cloud.ts | 28 +++++++++++++++++ src/components/HistoryChart.tsx | 5 ++-- src/components/MetricCard.tsx | 11 +++++-- src/pages/EdgeDetailPage.tsx | 53 ++++++++++++++++++++++++++++----- src/styles/components.css | 16 +++++++++- src/styles/detail.css | 20 +++++++++++-- 6 files changed, 118 insertions(+), 15 deletions(-) diff --git a/src/api/cloud.ts b/src/api/cloud.ts index d6cd8ab..c4ab647 100644 --- a/src/api/cloud.ts +++ b/src/api/cloud.ts @@ -67,6 +67,21 @@ export type HistoryResponse = { valueMode?: 'raw' | 'avg' | 'last' | 'first' | 'min' | 'max'; }; +export type TagTranslationItem = { + edge: string; + tag: string; + locale: string; + displayName: string; + source: string | null; + updatedAt: string; +}; + +export type TagTranslationResponse = { + edge: string; + locale: string; + items: TagTranslationItem[]; +}; + /** Выполняет типизированный GET-запрос к cloud-v2 и централизованно обрабатывает ошибки HTTP. */ async function request(path: string, params?: Record): Promise { const url = new URL(path, API_URL); @@ -133,3 +148,16 @@ export function getHistory(params: { valueMode: params.valueMode, }); } + +/** Загружает русскоязычный справочник названий тегов для выбранного edge. */ +export function getTagTranslations(params: { + edge: string; + locale?: string; + tags?: string[]; +}): Promise { + return request('/tag-translations', { + edge: params.edge, + locale: params.locale ?? 'ru', + tags: params.tags?.join(','), + }); +} diff --git a/src/components/HistoryChart.tsx b/src/components/HistoryChart.tsx index 0778d8e..2571709 100644 --- a/src/components/HistoryChart.tsx +++ b/src/components/HistoryChart.tsx @@ -28,6 +28,7 @@ type HistoryChartProps = { loading: boolean; from?: string; to?: string; + tagLabels?: Record; }; /** Подбирает подпись оси времени под текущий масштаб графика. */ @@ -46,7 +47,7 @@ function formatAxisDate(value: number, spanMs?: number): string { } /** Рисует исторические ряды показателей через ECharts с динамической временной шкалой. */ -export function HistoryChart({ data, loading, from, to }: HistoryChartProps) { +export function HistoryChart({ data, loading, from, to, tagLabels = {} }: HistoryChartProps) { const xMin = from ? new Date(from).getTime() : undefined; const xMax = to ? new Date(to).getTime() : undefined; const xSpan = Number.isFinite(xMin) && Number.isFinite(xMax) ? Number(xMax) - Number(xMin) : undefined; @@ -115,7 +116,7 @@ export function HistoryChart({ data, loading, from, to }: HistoryChartProps) { ], series: data?.series.map((series, index) => ({ - name: series.tag, + name: tagLabels[series.tag] ?? series.tag, type: 'line', showSymbol: false, smooth: false, diff --git a/src/components/MetricCard.tsx b/src/components/MetricCard.tsx index 542dafe..b56059e 100644 --- a/src/components/MetricCard.tsx +++ b/src/components/MetricCard.tsx @@ -5,28 +5,33 @@ import { getMetricStatus, type MetricStatusInfo } from '../utils/metricStatus'; type MetricCardProps = { item: CurrentItem; + displayName?: string; selected: boolean; statusInfo?: MetricStatusInfo; onToggle: (tag: string) => void; }; /** Показывает детальную карточку текущего показателя и управляет добавлением тега на график. */ -export function MetricCard({ item, selected, statusInfo = getMetricStatus(item), onToggle }: MetricCardProps) { +export function MetricCard({ item, displayName, selected, statusInfo = getMetricStatus(item), onToggle }: MetricCardProps) { const { ageSeconds, label, status } = statusInfo; const ageLabel = ageSeconds < 60 ? `${ageSeconds}с` : `${Math.floor(ageSeconds / 60)}м ${ageSeconds % 60}с`; + const title = displayName ?? item.tag; return ( ); @@ -525,6 +560,7 @@ function ArchiveView({ loading={historyLoading} from={toIsoFromInput(range.from)} to={toIsoFromInput(range.to)} + tagLabels={tagLabels} /> ) : (
Разверните список показателей и выберите серии для графика
@@ -566,6 +602,7 @@ function IndicatorsView({ isError, error, selectedTags, + getTagLabel, onSearchChange, onToggleTag, }: { @@ -574,6 +611,7 @@ function IndicatorsView({ isError: boolean; error: unknown; selectedTags: string[]; + getTagLabel: (tag: string) => string; onSearchChange: (value: string) => void; onToggleTag: (tag: string) => void; }) { @@ -656,11 +694,11 @@ function IndicatorsView({ key={`${item.edge}:${item.tag}`} type="button" className={`metric-tile metric-tile--${statusInfo.status} ${selectedTags.includes(item.tag) ? 'metric-tile--selected' : ''}`} - title={`${item.tag}: ${formatNumber(item.value)} · ${statusInfo.label}`} + title={`${getTagLabel(item.tag)} (${item.tag}): ${formatNumber(item.value)} · ${statusInfo.label}`} onClick={() => onToggleTag(item.tag)} > - {item.tag} + {getTagLabel(item.tag)} {formatNumber(item.value)} ))} @@ -671,6 +709,7 @@ function IndicatorsView({