From 4e47242053a045866cbb76e3d6128dfb489af752 Mon Sep 17 00:00:00 2001 From: Fine Date: Thu, 9 Jan 2025 17:33:01 +0800 Subject: [PATCH] add type --- src/hooks/useSnapshot.ts | 5 +++-- src/types/dashboard.d.ts | 14 ++++++++++++++ src/views/alarm/Content.vue | 3 ++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/hooks/useSnapshot.ts b/src/hooks/useSnapshot.ts index 0448418c..3afb795c 100644 --- a/src/hooks/useSnapshot.ts +++ b/src/hooks/useSnapshot.ts @@ -14,10 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import type { MetricsResults } from "@/types/dashboard"; -export function useSnapshot(metrics: { name: string; results: any[] }[]) { +export function useSnapshot(metrics: { name: string; results: MetricsResults[] }[]) { function processResults() { - const sources = metrics.map((metric: { name: string; results: any[] }) => { + const sources = metrics.map((metric: { name: string; results: MetricsResults[] }) => { const values = metric.results.map( (r: { values: { value: string }[]; metric: { labels: { key: string; value: string }[] } }) => { const arr = r.values.map((v: { value: string }) => Number(v.value)); diff --git a/src/types/dashboard.d.ts b/src/types/dashboard.d.ts index 564a87c7..5ddb9130 100644 --- a/src/types/dashboard.d.ts +++ b/src/types/dashboard.d.ts @@ -198,3 +198,17 @@ export type LegendOptions = { toTheRight: boolean; width: number; }; +export type MetricsResults = { + metric: { labels: MetricLabel[] }; + values: MetricValue[]; +}; +type MetricLabel = { + key: string; + value: string; +}; +type MetricValue = { + name: string; + value: string; + owner: null | string; + refId: null | string; +}; diff --git a/src/views/alarm/Content.vue b/src/views/alarm/Content.vue index ac859653..6201fa1f 100644 --- a/src/views/alarm/Content.vue +++ b/src/views/alarm/Content.vue @@ -139,6 +139,7 @@ limitations under the License. --> import { useSnapshot } from "@/hooks/useSnapshot"; import Snapshot from "./components/Snapshot.vue"; import Line from "@/views/dashboard/graphs/Line.vue"; + import type { MetricsResults } from "@/types/dashboard"; const { t } = useI18n(); const alarmStore = useAlarmStore(); @@ -164,7 +165,7 @@ limitations under the License. --> showEventDetails.value = true; } - function handleMetrics(snapshot: any) { + function handleMetrics(snapshot: { metrics: { name: string; results: MetricsResults[] }[] }) { const { getMetricsMap } = useSnapshot(snapshot.metrics); return getMetricsMap();