From 1954c0609cac401670391dffb62eebdc727f6dc8 Mon Sep 17 00:00:00 2001 From: Fine Date: Thu, 14 Dec 2023 11:15:14 +0800 Subject: [PATCH] feat: parse tab expressions --- src/views/dashboard/configuration/Tab.vue | 6 ++--- src/views/dashboard/controls/Tab.vue | 32 ++++++++++++++++++++--- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/views/dashboard/configuration/Tab.vue b/src/views/dashboard/configuration/Tab.vue index 444aec18..0d1599b2 100644 --- a/src/views/dashboard/configuration/Tab.vue +++ b/src/views/dashboard/configuration/Tab.vue @@ -39,11 +39,11 @@ limitations under the License. --> const originConfig = dashboardStore.selectedGrid; const expressions = reactive<{ [key: string]: string }>({}); const widgetTabs = computed(() => - dashboardStore.selectedGrid.children.filter((child: any[]) => - child.find((item: any) => item.type === WidgetType.Widget), + (dashboardStore.selectedGrid.children || []).filter((child: any) => + child.children.find((item: any) => item.type === WidgetType.Widget), ), ); - console.log(widgetTabs.value); + for (const child of originConfig.children || []) { expressions[child.name] = child.expression || ""; } diff --git a/src/views/dashboard/controls/Tab.vue b/src/views/dashboard/controls/Tab.vue index 607e26c0..eed6c74a 100644 --- a/src/views/dashboard/controls/Tab.vue +++ b/src/views/dashboard/controls/Tab.vue @@ -127,7 +127,7 @@ limitations under the License. --> import type { LayoutConfig } from "@/types/dashboard"; import { useDashboardStore } from "@/store/modules/dashboard"; import controls from "./tab"; - import { dragIgnoreFrom, WidgetType } from "../data"; + import { dragIgnoreFrom, WidgetType, ListEntity } from "../data"; import copy from "@/utils/copy"; import { useExpressionsQueryProcessor } from "@/hooks/useExpressionsProcessor"; @@ -250,11 +250,28 @@ limitations under the License. --> async function queryExpressions() { const tabsProps = props.data; + console.log(tabsProps); const metrics = []; + const listMetrics = []; for (const child of tabsProps.children || []) { - child.expression && metrics.push(child.expression); + let isList = false; + if (child.expression) { + const expList = parseTabsExpression(child.expression); + for (const exp of expList) { + const item = child.children.find((d: any) => d.expressions.includes(exp)); + + if (item && item.graph && ListEntity.includes(item.graph.type)) { + isList = true; + } + } + if (isList) { + listMetrics.push(child.expression); + } else { + metrics.push(child.expression); + } + } } - if (!metrics.length) { + if (![...metrics, ...listMetrics].length) { return; } const params: { [key: string]: any } = (await useExpressionsQueryProcessor({ metrics })) || {}; @@ -271,6 +288,15 @@ limitations under the License. --> dashboardStore.setConfigs(tabsProps); } + function parseTabsExpression(inputString: string) { + const regex = /is_present\s*\(\s*([^,)\s]+)\s*,\s*([^,)\s]+)\s*\)/; + const match = inputString.match(regex); + + const result = match ? [match[1], match[2]] : []; + + return result; + } + watch( () => (props.data.children || []).map((d: any) => d.expression), (old: string[], data: string[]) => {