From 297536db72e024a63aaaef00ee891a461e739b57 Mon Sep 17 00:00:00 2001 From: Fine Date: Mon, 12 Jun 2023 18:13:00 +0800 Subject: [PATCH] fix: clean instances --- src/store/modules/continous-profiling.ts | 42 ++++++++++++++----- .../components/InstanceList.vue | 30 ++++--------- 2 files changed, 39 insertions(+), 33 deletions(-) diff --git a/src/store/modules/continous-profiling.ts b/src/store/modules/continous-profiling.ts index bcc87459..19f74f37 100644 --- a/src/store/modules/continous-profiling.ts +++ b/src/store/modules/continous-profiling.ts @@ -20,7 +20,9 @@ import type { EBPFTaskList, EBPFProfilingSchedule, AnalyzationTrees } from "@/ty import type { Instance } from "@/types/selector"; import { store } from "@/store"; import graphql from "@/graphql"; +import type { MonitorInstance, MonitorProcess } from "@/types/continous-profiling"; import type { AxiosResponse } from "axios"; +import { dateFormat } from "@/utils/dateFormat"; interface ContinousProfilingState { strategyList: Array>; @@ -106,19 +108,20 @@ export const continousProfilingStore = defineStore({ if (res.data.errors) { return res.data; } - const arr = (res.data.data.strategyList || []).length - ? res.data.data.strategyList - : [{ type: "", checkItems: [{ type: "" }] }]; + const list = res.data.data.strategyList || []; + if (!list.length) { + this.taskList = []; + this.instances = []; + this.instance = null; + } + const arr = list.length ? res.data.data.strategyList : [{ type: "", checkItems: [{ type: "" }] }]; this.strategyList = arr.map((d: StrategyItem, index: number) => { return { ...d, id: index, }; }); - this.setSelectedStrategy(this.strategyList[0] || {}); - if (!this.strategyList.length) { - this.taskList = []; - } + this.setSelectedStrategy(list[0] || {}); if (!this.selectedStrategy.type) { return res.data; } @@ -135,10 +138,29 @@ export const continousProfilingStore = defineStore({ target: this.selectedStrategy.type, }); this.instancesLoading = false; - if (!res.data.errors) { - this.instances = res.data.data.instances || []; - this.instance = this.instances[0] || null; + if (res.data.errors) { + return res.data; } + this.instances = (res.data.data.instances || []) + .map((d: MonitorInstance) => { + const processes = (d.processes || []) + .sort((c: MonitorProcess, d: MonitorProcess) => d.lastTriggerTimestamp - c.lastTriggerTimestamp) + .map((p: MonitorProcess) => { + return { + ...p, + lastTriggerTime: d.lastTriggerTimestamp ? dateFormat(d.lastTriggerTimestamp) : "", + labels: p.labels.join("; "), + }; + }); + + return { + ...d, + processes, + lastTriggerTime: d.lastTriggerTimestamp ? dateFormat(d.lastTriggerTimestamp) : "", + }; + }) + .sort((a: MonitorInstance, b: MonitorInstance) => b.lastTriggerTimestamp - a.lastTriggerTimestamp); + this.instance = this.instances[0] || null; return res.data; }, }, diff --git a/src/views/dashboard/related/continuous-profiling/components/InstanceList.vue b/src/views/dashboard/related/continuous-profiling/components/InstanceList.vue index e059b996..bb8d641f 100644 --- a/src/views/dashboard/related/continuous-profiling/components/InstanceList.vue +++ b/src/views/dashboard/related/continuous-profiling/components/InstanceList.vue @@ -68,14 +68,14 @@ limitations under the License. --> background layout="prev, pager, next" :page-size="pageSize" - :total="instances.length" + :total="continousProfilingStore.instances.length" @current-change="changePage" @prev-click="changePage" @next-click="changePage" />