feat: update query

This commit is contained in:
Fine 2024-08-20 15:35:29 +08:00
parent a196eea960
commit 6dbb072360
2 changed files with 24 additions and 17 deletions

View File

@ -36,19 +36,16 @@ export async function useDashboardQueryProcessor(configArr: Indexable[]) {
if (!selectorStore.currentService && dashboardStore.entity !== "All") { if (!selectorStore.currentService && dashboardStore.entity !== "All") {
return; return;
} }
const conditions: Recordable = { const conditions: Recordable = {};
duration: appStore.durationTime, const variables: string[] = [];
};
const variables: string[] = [`$duration: Duration!`];
const isRelation = ["ServiceRelation", "ServiceInstanceRelation", "EndpointRelation", "ProcessRelation"].includes( const isRelation = ["ServiceRelation", "ServiceInstanceRelation", "EndpointRelation", "ProcessRelation"].includes(
dashboardStore.entity, dashboardStore.entity,
); );
if (isRelation && !selectorStore.currentDestService) { if (isRelation && !selectorStore.currentDestService) {
return; return;
} }
const fragment = config.metrics.map((name: string, index: number) => { if (idx === 0) {
variables.push(`$expression${idx}${index}: String!`, `$entity${idx}${index}: Entity!`); variables.push(`$entity: Entity!`);
conditions[`expression${idx}${index}`] = name;
const entity = { const entity = {
serviceName: dashboardStore.entity === "All" ? undefined : selectorStore.currentService.value, serviceName: dashboardStore.entity === "All" ? undefined : selectorStore.currentService.value,
normal: dashboardStore.entity === "All" ? undefined : selectorStore.currentService.normal, normal: dashboardStore.entity === "All" ? undefined : selectorStore.currentService.normal,
@ -76,12 +73,14 @@ export async function useDashboardQueryProcessor(configArr: Indexable[]) {
? selectorStore.currentDestProcess && selectorStore.currentDestProcess.value ? selectorStore.currentDestProcess && selectorStore.currentDestProcess.value
: undefined, : undefined,
}; };
conditions[`entity${idx}${index}`] = entity; conditions[`entity`] = entity;
}
const fragment = config.metrics.map((name: string, index: number) => {
variables.push(`$expression${idx}${index}: String!`);
conditions[`expression${idx}${index}`] = name;
return `expression${idx}${index}: execExpression(expression: $expression${idx}${index}, entity: $entity${idx}${index}, duration: $duration)${RespFields.execExpression}`; return `expression${idx}${index}: execExpression(expression: $expression${idx}${index}, entity: $entity, duration: $duration)${RespFields.execExpression}`;
}); });
// const queryStr = `query queryData(${variables}) {${fragment}}`;
return { return {
variables, variables,
fragment, fragment,
@ -136,7 +135,7 @@ export async function useDashboardQueryProcessor(configArr: Indexable[]) {
} }
const appStore = useAppStoreWithOut(); const appStore = useAppStoreWithOut();
const variables: string[] = [`$duration: Duration!`]; const variables: string[] = [`$duration: Duration!`];
let fragments; let fragments = "";
let conditions: Recordable = { let conditions: Recordable = {
duration: appStore.durationTime, duration: appStore.durationTime,
}; };
@ -151,7 +150,6 @@ export async function useDashboardQueryProcessor(configArr: Indexable[]) {
if (!fragments) { if (!fragments) {
return { 0: { source: {}, tips: [], typesOfMQE: [] } }; return { 0: { source: {}, tips: [], typesOfMQE: [] } };
} }
const queryStr = `query queryData(${variables}) {${fragments}}`; const queryStr = `query queryData(${variables}) {${fragments}}`;
const dashboardStore = useDashboardStore(); const dashboardStore = useDashboardStore();
const json = await dashboardStore.fetchMetricValue({ const json = await dashboardStore.fetchMetricValue({

View File

@ -39,7 +39,7 @@ limitations under the License. -->
<div class="no-data-tips" v-else>{{ t("noWidget") }}</div> <div class="no-data-tips" v-else>{{ t("noWidget") }}</div>
</template> </template>
<script lang="ts"> <script lang="ts">
import { defineComponent, onBeforeUnmount } from "vue"; import { defineComponent, onBeforeUnmount, watch } from "vue";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import { useDashboardStore } from "@/store/modules/dashboard"; import { useDashboardStore } from "@/store/modules/dashboard";
import { useSelectorStore } from "@/store/modules/selectors"; import { useSelectorStore } from "@/store/modules/selectors";
@ -47,6 +47,7 @@ limitations under the License. -->
import controls from "../controls/index"; import controls from "../controls/index";
import { dragIgnoreFrom } from "../data"; import { dragIgnoreFrom } from "../data";
import { useDashboardQueryProcessor } from "@/hooks/useExpressionsProcessor"; import { useDashboardQueryProcessor } from "@/hooks/useExpressionsProcessor";
import { EntityType } from "../data";
export default defineComponent({ export default defineComponent({
name: "Layout", name: "Layout",
@ -55,7 +56,6 @@ limitations under the License. -->
const { t } = useI18n(); const { t } = useI18n();
const dashboardStore = useDashboardStore(); const dashboardStore = useDashboardStore();
const selectorStore = useSelectorStore(); const selectorStore = useSelectorStore();
console.log(dashboardStore.layout);
function clickGrid(item: LayoutConfig, event: Event) { function clickGrid(item: LayoutConfig, event: Event) {
dashboardStore.activeGridItem(item.i); dashboardStore.activeGridItem(item.i);
@ -76,12 +76,13 @@ limitations under the License. -->
widgets.push(item); widgets.push(item);
} }
if (item.type === "Tab") { if (item.type === "Tab") {
widgets.push(...item.children[item.activedTabIndex].children); const index = isNaN(item.activedTabIndex) ? 0 : item.activedTabIndex;
widgets.push(...item.children[index].children);
} }
} }
const configList = widgets.map((d: any) => ({ const configList = widgets.map((d: any) => ({
metrics: d.expressions || [], metrics: d.expressions || [],
metricConfig: d.data.metricConfig || [], metricConfig: d.metricConfig || [],
})); }));
const params = (await useDashboardQueryProcessor(configList)) || {}; const params = (await useDashboardQueryProcessor(configList)) || {};
console.log(params); console.log(params);
@ -93,6 +94,14 @@ limitations under the License. -->
dashboardStore.setEntity(""); dashboardStore.setEntity("");
dashboardStore.setConfigPanel(false); dashboardStore.setConfigPanel(false);
}); });
watch(
() => [selectorStore.currentService, selectorStore.currentDestService],
() => {
if ([EntityType[0].value, EntityType[4].value].includes(dashboardStore.entity)) {
queryMetrics();
}
},
);
return { return {
dashboardStore, dashboardStore,
clickGrid, clickGrid,