From 2a11d58d30d27f32ed1d1f522c41aef0cb48cef3 Mon Sep 17 00:00:00 2001 From: Fine Date: Wed, 20 Dec 2023 14:42:07 +0800 Subject: [PATCH] revert: service list --- src/hooks/useExpressionsProcessor.ts | 40 +------------ src/store/modules/selectors.ts | 1 - src/views/dashboard/configuration/Tab.vue | 8 ++- src/views/dashboard/controls/Tab.vue | 69 +++++------------------ 4 files changed, 24 insertions(+), 94 deletions(-) diff --git a/src/hooks/useExpressionsProcessor.ts b/src/hooks/useExpressionsProcessor.ts index 55439b73..e237cb0d 100644 --- a/src/hooks/useExpressionsProcessor.ts +++ b/src/hooks/useExpressionsProcessor.ts @@ -15,7 +15,7 @@ * limitations under the License. */ import { RespFields } from "./data"; -import { EntityType, ExpressionResultType, ListChartTypes } from "@/views/dashboard/data"; +import { EntityType, ExpressionResultType } from "@/views/dashboard/data"; import { ElMessage } from "element-plus"; import { useDashboardStore } from "@/store/modules/dashboard"; import { useSelectorStore } from "@/store/modules/selectors"; @@ -88,40 +88,6 @@ export async function useExpressionsQueryProcessor(config: Indexable) { }; } - function isPresentGraphqlPods() { - if (!(config.metrics && config.metrics[0])) { - return; - } - const appStore = useAppStoreWithOut(); - const selectorStore = useSelectorStore(); - const conditions: Recordable = { - duration: appStore.durationTime, - }; - const variables: string[] = [`$duration: Duration!`]; - const fragment = config.metrics.map((name: string, index: number) => { - variables.push(`$expression${index}: String!`, `$entity${index}: Entity!`); - conditions[`expression${index}`] = name; - const entity = { - serviceName: - config.scopes[index] === ListChartTypes[2] ? config.pods[index].value : selectorStore.currentService.value, - normal: - config.scopes[index] === ListChartTypes[2] ? config.pods[index].normal : selectorStore.currentService.normal, - serviceInstanceName: config.scopes[index] === ListChartTypes[1] ? config.pods[index].value : undefined, - endpointName: config.scopes[index] === ListChartTypes[0] ? config.pods[index].value : undefined, - }; - conditions[`entity${index}`] = entity; - - return `expression${index}: execExpression(expression: $expression${index}, entity: $entity${index}, duration: $duration)${RespFields.execExpression}`; - }); - - const queryStr = `query queryData(${variables}) {${fragment}}`; - - return { - queryStr, - conditions, - }; - } - function expressionsSource(resp: { errors: string; data: Indexable }) { if (resp.errors) { ElMessage.error(resp.errors); @@ -175,8 +141,8 @@ export async function useExpressionsQueryProcessor(config: Indexable) { return { source, tips, typesOfMQE }; } - console.log(config); - const params = await (config.scopes ? isPresentGraphqlPods() : expressionsGraphqlPods()); + + const params = await expressionsGraphqlPods(); if (!params) { return { source: {}, tips: [], typesOfMQE: [] }; } diff --git a/src/store/modules/selectors.ts b/src/store/modules/selectors.ts index b741edec..4101b850 100644 --- a/src/store/modules/selectors.ts +++ b/src/store/modules/selectors.ts @@ -105,7 +105,6 @@ export const selectorStore = defineStore({ return res.data; } this.pods = res.data.data.pods || []; - console.log(this.pods); } return res.data; }, diff --git a/src/views/dashboard/configuration/Tab.vue b/src/views/dashboard/configuration/Tab.vue index 0d1599b2..130a8ffc 100644 --- a/src/views/dashboard/configuration/Tab.vue +++ b/src/views/dashboard/configuration/Tab.vue @@ -32,7 +32,7 @@ limitations under the License. --> import { reactive, computed } from "vue"; import { useDashboardStore } from "@/store/modules/dashboard"; import { ElMessage } from "element-plus"; - import { WidgetType } from "@/views/dashboard/data"; + import { WidgetType, ListEntity } from "@/views/dashboard/data"; const { t } = useI18n(); const dashboardStore = useDashboardStore(); @@ -40,7 +40,11 @@ limitations under the License. --> const expressions = reactive<{ [key: string]: string }>({}); const widgetTabs = computed(() => (dashboardStore.selectedGrid.children || []).filter((child: any) => - child.children.find((item: any) => item.type === WidgetType.Widget), + child.children.find( + (item: any) => + item.type === WidgetType.Widget && + !(Object.keys(ListEntity).includes(item.graph.type as string) && child.children === 1), + ), ), ); diff --git a/src/views/dashboard/controls/Tab.vue b/src/views/dashboard/controls/Tab.vue index ec7e3b58..cafdaf5b 100644 --- a/src/views/dashboard/controls/Tab.vue +++ b/src/views/dashboard/controls/Tab.vue @@ -128,9 +128,9 @@ limitations under the License. --> import { useDashboardStore } from "@/store/modules/dashboard"; import { useSelectorStore } from "@/store/modules/selectors"; import controls from "./tab"; - import { dragIgnoreFrom, WidgetType, ListEntity, ListChartTypes } from "../data"; + import { dragIgnoreFrom, WidgetType, ListEntity } from "../data"; import copy from "@/utils/copy"; - import { useExpressionsQueryProcessor, useExpressionsQueryPodsMetrics } from "@/hooks/useExpressionsProcessor"; + import { useExpressionsQueryProcessor } from "@/hooks/useExpressionsProcessor"; const props = { data: { @@ -253,76 +253,37 @@ limitations under the License. --> async function queryExpressions() { const tabsProps = props.data; const metrics = []; - const listExp = []; - const types: string[] = []; - const pods = []; for (const child of tabsProps.children || []) { - let isList = false; if (child.expression) { const expList = parseTabsExpression(child.expression); for (const exp of expList) { + let isList = false; let item = child.children.find((d: any) => d.expressions.join(", ").includes(exp)); if (item && item.graph && Object.keys(ListEntity).includes(item.graph.type as string)) { isList = true; } - if (!item) { - item = child.children.find((d: any) => d.subExpressions && d.subExpressions.join(", ").includes(exp)); - if (item) { - isList = true; - } + if (item && !isList) { + metrics.push(child.expression); } - if (item && item.graph && isList && item.graph.type) { - types.push(item.graph.type); - getPods(item.graph.type) && pods.push(getPods(item.graph.type)); - } - } - if (isList) { - listExp.push(child.expression); - } else { - metrics.push(child.expression); } } } - if (![...metrics, ...listExp].length) { + if (!metrics.length) { return; } - if (listExp.length) { - const params: { [key: string]: any } = - (await useExpressionsQueryProcessor({ - metrics: listExp, - pods, - metricConfig: [], - scopes: types.length ? types : undefined, - })) || {}; - } - if (metrics.length) { - const params: { [key: string]: any } = (await useExpressionsQueryProcessor({ metrics })) || {}; - for (const child of tabsProps.children || []) { - if (params.source[child.expression || ""]) { - child.enable = - !!Number(params.source[child.expression || ""]) && - !!child.children.find((item: { type: string }) => item.type === WidgetType.Widget); - } else { - child.enable = true; - } + const params: { [key: string]: any } = (await useExpressionsQueryProcessor({ metrics })) || {}; + for (const child of tabsProps.children || []) { + if (params.source[child.expression || ""]) { + child.enable = + !!Number(params.source[child.expression || ""]) && + !!child.children.find((item: { type: string }) => item.type === WidgetType.Widget); + } else { + child.enable = true; } } + dashboardStore.setConfigs(tabsProps); } - - function getPods(type: string) { - let pod = null; - - switch (type) { - case ListChartTypes[2]: - pod = selectorStore.services[0]; - break; - default: - pod = selectorStore.pods[0]; - } - return pod; - } - function parseTabsExpression(inputString: string) { const resultString = inputString.replace(/is_present\(|\)/g, ""); const result = resultString.replace(/\s/g, "").split(",");