From 569c4f6301d6d31f94447f86b881bb17e8c9d5b5 Mon Sep 17 00:00:00 2001 From: Fine Date: Tue, 12 Dec 2023 17:14:53 +0800 Subject: [PATCH] feat: add widget type --- src/components/Graph.vue | 3 +- src/store/data.ts | 22 ++++--- src/store/modules/dashboard.ts | 26 ++++---- src/views/dashboard/List.vue | 16 ++++- src/views/dashboard/configuration/Tab.vue | 10 ++- src/views/dashboard/controls/Tab.vue | 2 +- src/views/dashboard/data.ts | 18 ++++++ src/views/dashboard/graphs/TopList.vue | 3 +- src/views/dashboard/panel/Tool.vue | 63 ++++++++++--------- src/views/dashboard/related/event/Content.vue | 5 +- .../related/log/LogTable/LogService.vue | 3 +- src/views/dashboard/related/trace/Detail.vue | 3 +- 12 files changed, 110 insertions(+), 64 deletions(-) diff --git a/src/components/Graph.vue b/src/components/Graph.vue index 5ed35d1d..174d6de4 100644 --- a/src/components/Graph.vue +++ b/src/components/Graph.vue @@ -53,6 +53,7 @@ limitations under the License. --> import { addResizeListener, removeResizeListener } from "@/utils/event"; import Trace from "@/views/dashboard/related/trace/Index.vue"; import associateProcessor from "@/hooks/useAssociateProcessor"; + import { WidgetType } from "@/views/dashboard/data"; /*global Nullable, defineProps, defineEmits, Indexable*/ const emits = defineEmits(["select"]); @@ -63,7 +64,7 @@ limitations under the License. --> const currentParams = ref>(null); const showTrace = ref(false); const traceOptions = ref<{ type: string; filters?: unknown }>({ - type: "Trace", + type: WidgetType.Trace, }); const menuPos = reactive<{ x: number; y: number }>({ x: NaN, y: NaN }); const props = defineProps({ diff --git a/src/store/data.ts b/src/store/data.ts index 43d0d4d2..24749b4d 100644 --- a/src/store/data.ts +++ b/src/store/data.ts @@ -14,13 +14,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { WidgetType } from "@/views/dashboard/data"; + export const NewControl = { x: 0, y: 0, w: 24, h: 12, i: "0", - type: "Widget", + type: WidgetType.Widget, }; export const TextConfig = { fontColor: "white", @@ -39,15 +41,15 @@ export const TimeRangeConfig = { }; export const ControlsTypes = [ - "Trace", - "Profile", - "Log", - "DemandLog", - "Ebpf", - "NetworkProfiling", - "ThirdPartyApp", - "ContinuousProfiling", - "TaskTimeline", + WidgetType.Trace, + WidgetType.Profile, + WidgetType.Log, + WidgetType.DemandLog, + WidgetType.Ebpf, + WidgetType.NetworkProfiling, + WidgetType.ThirdPartyApp, + WidgetType.ContinuousProfiling, + WidgetType.TaskTimeline, ]; export enum EBPFProfilingTriggerType { FIXED_TIME = "FIXED_TIME", diff --git a/src/store/modules/dashboard.ts b/src/store/modules/dashboard.ts index 5fd55921..6aa3da63 100644 --- a/src/store/modules/dashboard.ts +++ b/src/store/modules/dashboard.ts @@ -25,7 +25,7 @@ import { NewControl, TextConfig, TimeRangeConfig, ControlsTypes } from "../data" import type { AxiosResponse } from "axios"; import { ElMessage } from "element-plus"; import { useI18n } from "vue-i18n"; -import { EntityType, MetricModes } from "@/views/dashboard/data"; +import { EntityType, MetricModes, WidgetType } from "@/views/dashboard/data"; interface DashboardState { showConfig: boolean; layout: LayoutConfig[]; @@ -78,7 +78,7 @@ export const dashboardStore = defineStore({ setCurrentDashboard(item: DashboardItem) { this.currentDashboard = item; }, - addControl(type: string) { + addControl(type: WidgetType) { const arr = this.layout.map((d: Recordable) => Number(d.i)); let index = String(Math.max(...arr) + 1); if (!this.layout.length) { @@ -93,10 +93,10 @@ export const dashboardStore = defineStore({ metrics: [""], }; - if (type === "Widget") { + if (type === WidgetType.Widget) { newItem.metricMode = MetricModes.Expression; } - if (type === "Tab") { + if (type === WidgetType.Tab) { newItem.h = 36; newItem.activedTabIndex = 0; newItem.children = [ @@ -110,7 +110,7 @@ export const dashboardStore = defineStore({ }, ]; } - if (type === "Topology") { + if (type === WidgetType.Topology) { newItem.h = 36; newItem.graph = { showDepth: true, @@ -120,11 +120,11 @@ export const dashboardStore = defineStore({ if (ControlsTypes.includes(type)) { newItem.h = 36; } - if (type === "Text") { + if (type === WidgetType.Text) { newItem.h = 6; newItem.graph = TextConfig; } - if (type === "TimeRange") { + if (type === WidgetType.TimeRange) { newItem.w = 8; newItem.h = 6; newItem.graph = TimeRangeConfig; @@ -149,7 +149,7 @@ export const dashboardStore = defineStore({ }; this.layout[idx].children?.push(i); }, - addTabControls(type: string) { + addTabControls(type: WidgetType) { const activedGridItem = this.activedGridItem.split("-")[0]; const idx = this.layout.findIndex((d: LayoutConfig) => d.i === activedGridItem); if (idx < 0) { @@ -171,10 +171,10 @@ export const dashboardStore = defineStore({ metricTypes: [""], metrics: [""], }; - if (type === "Widget") { + if (type === WidgetType.Widget) { newItem.metricMode = MetricModes.Expression; } - if (type === "Topology") { + if (type === WidgetType.Topology) { newItem.h = 32; newItem.graph = { showDepth: true, @@ -184,11 +184,11 @@ export const dashboardStore = defineStore({ if (ControlsTypes.includes(type)) { newItem.h = 32; } - if (type === "Text") { + if (type === WidgetType.Text) { newItem.h = 6; newItem.graph = TextConfig; } - if (type === "TimeRange") { + if (type === WidgetType.TimeRange) { newItem.w = 8; newItem.h = 6; newItem.graph = TextConfig; @@ -292,7 +292,7 @@ export const dashboardStore = defineStore({ }, setWidget(param: LayoutConfig) { for (let i = 0; i < this.layout.length; i++) { - if (this.layout[i].type === "Tab") { + if (this.layout[i].type === WidgetType.Tab) { if ((this.layout[i].children || []).length) { for (const child of this.layout[i].children || []) { if (child.children && child.children.length) { diff --git a/src/views/dashboard/List.vue b/src/views/dashboard/List.vue index 25b4997a..d1c372dd 100644 --- a/src/views/dashboard/List.vue +++ b/src/views/dashboard/List.vue @@ -139,6 +139,7 @@ limitations under the License. --> import { saveFile, readFile } from "@/utils/file"; import { EntityType } from "./data"; import { isEmptyObject } from "@/utils/is"; + import { WidgetType } from "@/views/dashboard/data"; /*global Nullable*/ const { t } = useI18n(); @@ -271,12 +272,23 @@ limitations under the License. --> if (!(child.metricConfig && child.metricConfig.length)) { delete child.metricConfig; } - if (child.type === "Tab") { + if (child.type === WidgetType.Tab) { for (const item of child.children || []) { optimizeTemplate(item.children); } } - if (["Trace", "Topology", "Tab", "Profile", "Ebpf", "Log"].includes(child.type)) { + if ( + ( + [ + WidgetType.Trace, + WidgetType.Topology, + WidgetType.Tab, + WidgetType.Profile, + WidgetType.Ebpf, + WidgetType.Log, + ] as string[] + ).includes(child.type) + ) { delete child.widget; } } diff --git a/src/views/dashboard/configuration/Tab.vue b/src/views/dashboard/configuration/Tab.vue index d9d81894..41f50462 100644 --- a/src/views/dashboard/configuration/Tab.vue +++ b/src/views/dashboard/configuration/Tab.vue @@ -29,15 +29,21 @@ limitations under the License. --> diff --git a/src/views/dashboard/related/trace/Detail.vue b/src/views/dashboard/related/trace/Detail.vue index 53f5ce7d..f58f80fc 100644 --- a/src/views/dashboard/related/trace/Detail.vue +++ b/src/views/dashboard/related/trace/Detail.vue @@ -101,6 +101,7 @@ limitations under the License. --> import type { LayoutConfig } from "@/types/dashboard"; import { dateFormat } from "@/utils/dateFormat"; import { useAppStoreWithOut } from "@/store/modules/app"; + import { WidgetType } from "@/views/dashboard/data"; const props = { serviceId: { type: String, default: "" }, @@ -145,7 +146,7 @@ limitations under the License. --> traceId: traceId.value || traceStore.currentTrace.traceIds[0].value, id: props.serviceId || undefined, }, - "Log", + WidgetType.Log, ); } return {