From 54a700bf19ec82263c2facc0f4970afb01d3013d Mon Sep 17 00:00:00 2001 From: Fine0830 Date: Thu, 14 Aug 2025 18:25:40 +0800 Subject: [PATCH] refactor: optimize data types for widgets and dashboards (#490) --- src/__tests__/main.spec.ts | 4 +- src/components/Graph/Graph.vue | 27 +++- src/components/Radio.vue | 2 +- src/graphql/base.ts | 3 + src/hooks/__tests__/useDuration.spec.ts | 12 +- src/hooks/useAssociateProcessor.ts | 13 +- src/hooks/useDashboardsSession.ts | 8 +- src/hooks/useDuration.ts | 6 +- src/hooks/useExpressionsProcessor.ts | 14 +- src/layout/components/NavBar.vue | 22 +-- src/store/data.ts | 2 + src/store/modules/__tests__/app.spec.ts | 4 +- src/store/modules/alarm.ts | 2 +- src/store/modules/app.ts | 10 +- src/store/modules/async-profiling.ts | 24 ++-- src/store/modules/continous-profiling.ts | 20 +-- src/store/modules/dashboard.ts | 16 +-- src/store/modules/demand-log.ts | 4 +- src/store/modules/ebpf.ts | 16 +-- src/store/modules/event.ts | 6 +- src/store/modules/log.ts | 7 +- src/store/modules/network-profiling.ts | 19 ++- src/store/modules/profile.ts | 35 ++--- src/store/modules/selectors.ts | 10 +- src/store/modules/settings.ts | 13 +- src/store/modules/task-timeline.ts | 10 +- src/store/modules/topology.ts | 6 +- src/store/modules/trace.ts | 18 +-- src/types/async-profiling.ts | 6 +- src/types/continous-profiling.ts | 1 + src/types/dashboard.ts | 130 ++++++++++++++---- src/types/demand-log.ts | 2 +- src/types/ebpf.ts | 11 +- src/types/events.ts | 10 +- src/types/profile.ts | 22 +-- src/types/selector.ts | 12 +- src/types/settings.ts | 4 +- src/types/topology.ts | 1 + src/types/trace.ts | 21 ++- src/views/Layer.vue | 3 +- src/views/alarm/Header.vue | 2 +- src/views/dashboard/Edit.vue | 10 +- src/views/dashboard/List.vue | 7 +- src/views/dashboard/Widget.vue | 20 +-- src/views/dashboard/components/WidgetLink.vue | 6 +- .../configuration/ContinuousProfiling.vue | 10 +- src/views/dashboard/configuration/Event.vue | 13 +- src/views/dashboard/configuration/Tab.vue | 11 +- src/views/dashboard/configuration/Text.vue | 10 +- .../dashboard/configuration/ThirdPartyApp.vue | 9 +- .../dashboard/configuration/TimeRange.vue | 9 +- .../dashboard/configuration/Topology.vue | 13 +- src/views/dashboard/configuration/Widget.vue | 35 +++-- .../configuration/widget/AssociateOptions.vue | 13 +- .../widget/RelatedTraceOptions.vue | 20 +-- .../configuration/widget/WidgetOptions.vue | 10 +- .../widget/graph-styles/Area.vue | 7 +- .../configuration/widget/graph-styles/Bar.vue | 7 +- .../widget/graph-styles/Card.vue | 9 +- .../widget/graph-styles/EndpointList.vue | 7 +- .../widget/graph-styles/HeatMap.vue | 7 +- .../widget/graph-styles/InstanceList.vue | 7 +- .../widget/graph-styles/Line.vue | 7 +- .../widget/graph-styles/ServiceList.vue | 7 +- .../widget/graph-styles/Table.vue | 7 +- .../widget/graph-styles/TopList.vue | 7 +- .../widget/graph-styles/components/Legend.vue | 14 +- .../graph-styles/components/ValueMappings.vue | 11 +- .../configuration/widget/metric/Index.vue | 44 +++--- .../configuration/widget/metric/Standard.vue | 16 ++- .../dashboard/controls/AsyncProfiling.vue | 3 +- .../controls/ContinuousProfiling.vue | 3 +- src/views/dashboard/controls/DemandLog.vue | 4 +- src/views/dashboard/controls/Ebpf.vue | 3 +- src/views/dashboard/controls/Event.vue | 4 +- .../dashboard/controls/NetworkProfiling.vue | 4 +- src/views/dashboard/controls/Profile.vue | 3 +- src/views/dashboard/controls/Tab.vue | 16 +-- src/views/dashboard/controls/TaskTimeline.vue | 3 +- src/views/dashboard/controls/Text.vue | 5 +- .../dashboard/controls/ThirdPartyApp.vue | 3 +- src/views/dashboard/controls/TimeRange.vue | 5 +- src/views/dashboard/controls/Topology.vue | 3 +- src/views/dashboard/controls/Trace.vue | 3 +- src/views/dashboard/controls/Widget.vue | 6 +- src/views/dashboard/graphs/EndpointList.vue | 2 +- src/views/dashboard/graphs/InstanceList.vue | 2 +- src/views/dashboard/graphs/ServiceList.vue | 24 ++-- src/views/dashboard/graphs/TopList.vue | 24 ++-- src/views/dashboard/panel/Layout.vue | 11 +- src/views/dashboard/panel/Tool.vue | 51 +++---- .../related/async-profiling/Content.vue | 6 +- .../async-profiling/components/Filter.vue | 12 +- .../async-profiling/components/NewTask.vue | 5 +- .../async-profiling/components/TaskList.vue | 24 ++-- .../related/components/TaskDetails.vue | 18 +-- .../components/InstanceList.vue | 11 +- .../components/PolicyList.vue | 4 +- .../dashboard/related/demand-log/Content.vue | 2 +- .../dashboard/related/demand-log/Header.vue | 12 +- src/views/dashboard/related/ebpf/Header.vue | 2 +- .../related/ebpf/components/EBPFSchedules.vue | 6 +- .../related/ebpf/components/EBPFStack.vue | 25 ++-- .../related/ebpf/components/NewTask.vue | 8 +- .../related/ebpf/components/TaskList.vue | 11 +- src/views/dashboard/related/event/Content.vue | 29 ++-- src/views/dashboard/related/event/Header.vue | 1 - src/views/dashboard/related/log/Header.vue | 50 ++++--- .../related/log/LogTable/LogService.vue | 12 +- .../components/ProcessTopology.vue | 3 +- .../network-profiling/components/Settings.vue | 17 ++- .../network-profiling/components/Tasks.vue | 9 +- .../network-profiling/components/TimeLine.vue | 6 +- .../dashboard/related/profile/Content.vue | 2 +- .../dashboard/related/profile/Header.vue | 2 +- .../related/profile/components/NewTask.vue | 8 +- .../profile/components/SegmentList.vue | 2 +- .../related/profile/components/SpanTree.vue | 42 +++--- .../related/profile/components/TaskList.vue | 2 +- .../components/ProfilingPanel.vue | 6 +- .../task-timeline/components/Timeline.vue | 11 +- .../related/topology/components/Graph.vue | 6 +- .../topology/components/utils/layout.ts | 8 +- .../related/topology/config/Metrics.vue | 17 +-- .../related/topology/config/Settings.vue | 38 ++--- .../related/topology/pod/InstanceMap.vue | 6 +- .../dashboard/related/topology/pod/PodMap.vue | 16 +-- .../dashboard/related/topology/pod/Sankey.vue | 12 +- .../related/topology/service/HierarchyMap.vue | 6 +- .../related/topology/service/ServiceMap.vue | 26 ++-- src/views/dashboard/related/trace/Detail.vue | 17 ++- src/views/dashboard/related/trace/Filter.vue | 32 +++-- src/views/dashboard/related/trace/Header.vue | 22 +-- src/views/dashboard/related/trace/Index.vue | 4 +- .../dashboard/related/trace/TraceList.vue | 2 +- .../trace/components/D3Graph/Index.vue | 7 +- .../trace/components/D3Graph/SpanDetail.vue | 17 ++- .../related/trace/components/Table.vue | 3 +- .../trace/components/Table/TableItem.vue | 25 ++-- src/views/settings/components/TTL.vue | 6 +- src/views/settings/components/TTLTable.vue | 4 +- 141 files changed, 972 insertions(+), 743 deletions(-) diff --git a/src/__tests__/main.spec.ts b/src/__tests__/main.spec.ts index 59ad2afc..ce31bd64 100644 --- a/src/__tests__/main.spec.ts +++ b/src/__tests__/main.spec.ts @@ -166,8 +166,8 @@ describe("Main Application", () => { const mockStore = useAppStoreWithOut(); // Mock async operations to take time - mockStore.getActivateMenus.mockImplementation(() => new Promise((resolve) => setTimeout(resolve, 100))); - mockStore.queryOAPTimeInfo.mockImplementation(() => new Promise((resolve) => setTimeout(resolve, 100))); + vi.mocked(mockStore.getActivateMenus).mockImplementation(() => new Promise((resolve) => setTimeout(resolve, 100))); + vi.mocked(mockStore.queryOAPTimeInfo).mockImplementation(() => new Promise((resolve) => setTimeout(resolve, 100))); // Test async operations const promises = [mockStore.getActivateMenus(), mockStore.queryOAPTimeInfo()]; diff --git a/src/components/Graph/Graph.vue b/src/components/Graph/Graph.vue index 76e668df..23a5c74d 100644 --- a/src/components/Graph/Graph.vue +++ b/src/components/Graph/Graph.vue @@ -55,11 +55,11 @@ limitations under the License. --> import type { PropType, Ref } from "vue"; import { useI18n } from "vue-i18n"; import type { EventParams } from "@/types/app"; - import type { Filters, RelatedTrace } from "@/types/dashboard"; + import type { Filters, RelatedTrace, AssociateProcessorProps } from "@/types/dashboard"; import { useECharts } from "@/hooks/useEcharts"; import { addResizeListener, removeResizeListener } from "@/utils/event"; import Trace from "@/views/dashboard/related/trace/Index.vue"; - import associateProcessor from "@/hooks/useAssociateProcessor"; + import useAssociateProcessor from "@/hooks/useAssociateProcessor"; import { WidgetType } from "@/views/dashboard/data"; import SelectorLegend from "./Legend.vue"; @@ -71,7 +71,7 @@ limitations under the License. --> const { setOptions, resize, getInstance } = useECharts(chartRef as Ref); const currentParams = ref>(null); const showTrace = ref(false); - const traceOptions = ref<{ type: string; filters?: unknown }>({ + const traceOptions = ref<{ type: string; filters?: unknown } | any>({ type: WidgetType.Trace, }); const menuPos = reactive<{ x: number; y: number }>({ x: NaN, y: NaN }); @@ -187,7 +187,11 @@ limitations under the License. --> return; } if (props.filters.isRange) { - const { eventAssociate } = associateProcessor(props); + const { eventAssociate } = useAssociateProcessor({ + filters: props.filters, + option: props.option, + relatedTrace: props.relatedTrace, + } as AssociateProcessorProps); const options = eventAssociate(); setOptions(options || props.option); } else { @@ -200,7 +204,12 @@ limitations under the License. --> } function viewTrace() { - const item = associateProcessor(props).traceFilters(currentParams.value); + const item = useAssociateProcessor({ + filters: props.filters, + option: props.option, + relatedTrace: props.relatedTrace, + } as AssociateProcessorProps).traceFilters(currentParams.value); + traceOptions.value = { ...traceOptions.value, filters: item, @@ -243,8 +252,12 @@ limitations under the License. --> return; } let options; - if (props.filters && props.filters.isRange) { - const { eventAssociate } = associateProcessor(props); + if (props.filters?.isRange) { + const { eventAssociate } = useAssociateProcessor({ + filters: props.filters, + option: props.option, + relatedTrace: props.relatedTrace, + } as AssociateProcessorProps); options = eventAssociate(); } setOptions(options || props.option); diff --git a/src/components/Radio.vue b/src/components/Radio.vue index 17e21593..4fe4318e 100644 --- a/src/components/Radio.vue +++ b/src/components/Radio.vue @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. -->