revert: service list

This commit is contained in:
Fine 2023-12-20 14:42:07 +08:00
parent 96f9328e90
commit 2a11d58d30
4 changed files with 24 additions and 94 deletions

View File

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
import { RespFields } from "./data"; 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 { ElMessage } from "element-plus";
import { useDashboardStore } from "@/store/modules/dashboard"; import { useDashboardStore } from "@/store/modules/dashboard";
import { useSelectorStore } from "@/store/modules/selectors"; 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 }) { function expressionsSource(resp: { errors: string; data: Indexable }) {
if (resp.errors) { if (resp.errors) {
ElMessage.error(resp.errors); ElMessage.error(resp.errors);
@ -175,8 +141,8 @@ export async function useExpressionsQueryProcessor(config: Indexable) {
return { source, tips, typesOfMQE }; return { source, tips, typesOfMQE };
} }
console.log(config);
const params = await (config.scopes ? isPresentGraphqlPods() : expressionsGraphqlPods()); const params = await expressionsGraphqlPods();
if (!params) { if (!params) {
return { source: {}, tips: [], typesOfMQE: [] }; return { source: {}, tips: [], typesOfMQE: [] };
} }

View File

@ -105,7 +105,6 @@ export const selectorStore = defineStore({
return res.data; return res.data;
} }
this.pods = res.data.data.pods || []; this.pods = res.data.data.pods || [];
console.log(this.pods);
} }
return res.data; return res.data;
}, },

View File

@ -32,7 +32,7 @@ limitations under the License. -->
import { reactive, computed } from "vue"; import { reactive, computed } from "vue";
import { useDashboardStore } from "@/store/modules/dashboard"; import { useDashboardStore } from "@/store/modules/dashboard";
import { ElMessage } from "element-plus"; import { ElMessage } from "element-plus";
import { WidgetType } from "@/views/dashboard/data"; import { WidgetType, ListEntity } from "@/views/dashboard/data";
const { t } = useI18n(); const { t } = useI18n();
const dashboardStore = useDashboardStore(); const dashboardStore = useDashboardStore();
@ -40,7 +40,11 @@ limitations under the License. -->
const expressions = reactive<{ [key: string]: string }>({}); const expressions = reactive<{ [key: string]: string }>({});
const widgetTabs = computed(() => const widgetTabs = computed(() =>
(dashboardStore.selectedGrid.children || []).filter((child: any) => (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),
),
), ),
); );

View File

@ -128,9 +128,9 @@ limitations under the License. -->
import { useDashboardStore } from "@/store/modules/dashboard"; import { useDashboardStore } from "@/store/modules/dashboard";
import { useSelectorStore } from "@/store/modules/selectors"; import { useSelectorStore } from "@/store/modules/selectors";
import controls from "./tab"; import controls from "./tab";
import { dragIgnoreFrom, WidgetType, ListEntity, ListChartTypes } from "../data"; import { dragIgnoreFrom, WidgetType, ListEntity } from "../data";
import copy from "@/utils/copy"; import copy from "@/utils/copy";
import { useExpressionsQueryProcessor, useExpressionsQueryPodsMetrics } from "@/hooks/useExpressionsProcessor"; import { useExpressionsQueryProcessor } from "@/hooks/useExpressionsProcessor";
const props = { const props = {
data: { data: {
@ -253,76 +253,37 @@ limitations under the License. -->
async function queryExpressions() { async function queryExpressions() {
const tabsProps = props.data; const tabsProps = props.data;
const metrics = []; const metrics = [];
const listExp = [];
const types: string[] = [];
const pods = [];
for (const child of tabsProps.children || []) { for (const child of tabsProps.children || []) {
let isList = false;
if (child.expression) { if (child.expression) {
const expList = parseTabsExpression(child.expression); const expList = parseTabsExpression(child.expression);
for (const exp of expList) { for (const exp of expList) {
let isList = false;
let item = child.children.find((d: any) => d.expressions.join(", ").includes(exp)); 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)) { if (item && item.graph && Object.keys(ListEntity).includes(item.graph.type as string)) {
isList = true; isList = true;
} }
if (!item) { if (item && !isList) {
item = child.children.find((d: any) => d.subExpressions && d.subExpressions.join(", ").includes(exp)); metrics.push(child.expression);
if (item) {
isList = true;
}
} }
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; return;
} }
if (listExp.length) { const params: { [key: string]: any } = (await useExpressionsQueryProcessor({ metrics })) || {};
const params: { [key: string]: any } = for (const child of tabsProps.children || []) {
(await useExpressionsQueryProcessor({ if (params.source[child.expression || ""]) {
metrics: listExp, child.enable =
pods, !!Number(params.source[child.expression || ""]) &&
metricConfig: [], !!child.children.find((item: { type: string }) => item.type === WidgetType.Widget);
scopes: types.length ? types : undefined, } else {
})) || {}; child.enable = true;
}
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;
}
} }
} }
dashboardStore.setConfigs(tabsProps); 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) { function parseTabsExpression(inputString: string) {
const resultString = inputString.replace(/is_present\(|\)/g, ""); const resultString = inputString.replace(/is_present\(|\)/g, "");
const result = resultString.replace(/\s/g, "").split(","); const result = resultString.replace(/\s/g, "").split(",");