From b07c090458342d79549d2de4579fc23947789bf5 Mon Sep 17 00:00:00 2001 From: Fine Date: Mon, 26 Feb 2024 19:02:26 +0800 Subject: [PATCH] fix: data --- src/hooks/useExpressionsProcessor.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/hooks/useExpressionsProcessor.ts b/src/hooks/useExpressionsProcessor.ts index 63db0e29..f32ff64c 100644 --- a/src/hooks/useExpressionsProcessor.ts +++ b/src/hooks/useExpressionsProcessor.ts @@ -114,7 +114,8 @@ export async function useExpressionsQueryProcessor(config: Indexable) { if (!obj.error) { if (type === ExpressionResultType.TIME_SERIES_VALUES) { if (results.length === 1) { - const label = results[0].metric && results[0].metric.labels[0] && results[0].metric.labels[0].value; + const label = + results[0] && results[0].metric && results[0].metric.labels[0] && results[0].metric.labels[0].value; source[c.label || label || name] = results[0].values.map((d: { value: unknown }) => d.value) || []; } else { const labels = (c.label || "").split(",").map((item: string) => item.replace(/^\s*|\s*$/g, "")); @@ -131,10 +132,10 @@ export async function useExpressionsQueryProcessor(config: Indexable) { } } if (type === ExpressionResultType.SINGLE_VALUE) { - source[c.label || name] = (results[0].values[0] || {}).value; + source[c.label || name] = ((results[0] && results[0].values[0]) || {}).value; } if (([ExpressionResultType.RECORD_LIST, ExpressionResultType.SORTED_LIST] as string[]).includes(type)) { - source[name] = results[0].values; + source[name] = results[0] && results[0].values; } } }