From 11dc1813068e24ed66c3b256c08227697cd20d79 Mon Sep 17 00:00:00 2001 From: Qiuxia Fan Date: Thu, 14 Apr 2022 12:59:10 +0800 Subject: [PATCH] add component --- src/hooks/useListConfig.ts | 11 +- src/views/dashboard/graphs/EndpointList.vue | 57 +------ src/views/dashboard/graphs/InstanceList.vue | 60 +------ src/views/dashboard/graphs/ServiceList.vue | 125 +------------- .../graphs/components/MetricGraph.vue | 161 ++++++++++++++++++ 5 files changed, 185 insertions(+), 229 deletions(-) create mode 100644 src/views/dashboard/graphs/components/MetricGraph.vue diff --git a/src/hooks/useListConfig.ts b/src/hooks/useListConfig.ts index e48e9edd..47e7269e 100644 --- a/src/hooks/useListConfig.ts +++ b/src/hooks/useListConfig.ts @@ -15,16 +15,17 @@ * limitations under the License. */ import { MetricQueryTypes, Calculations } from "./data"; -export function useListConfig(config: any, index: number) { +export function useListConfig(config: any, index: string) { + const i = Number(index); const calculation = config.metricConfig && - config.metricConfig[index] && - config.metricConfig[index].calculation; + config.metricConfig[i] && + config.metricConfig[i].calculation; const line = - config.metricTypes[index] === MetricQueryTypes.ReadMetricsValues && + config.metricTypes[i] === MetricQueryTypes.ReadMetricsValues && calculation !== Calculations.Average; const isAvg = - config.metricTypes[index] === MetricQueryTypes.ReadMetricsValues && + config.metricTypes[i] === MetricQueryTypes.ReadMetricsValues && calculation === Calculations.Average; return { isLinear: line, diff --git a/src/views/dashboard/graphs/EndpointList.vue b/src/views/dashboard/graphs/EndpointList.vue index c43c7827..9bc86313 100644 --- a/src/views/dashboard/graphs/EndpointList.vue +++ b/src/views/dashboard/graphs/EndpointList.vue @@ -42,34 +42,11 @@ limitations under the License. --> - - - + @@ -83,13 +60,11 @@ import { EndpointListConfig } from "@/types/dashboard"; import { Endpoint } from "@/types/selector"; import { useDashboardStore } from "@/store/modules/dashboard"; import { useQueryPodsMetrics, usePodsSource } from "@/hooks/useProcessor"; -import { useListConfig } from "@/hooks/useListConfig"; -import Line from "./Line.vue"; -import Card from "./Card.vue"; import { EntityType } from "../data"; import router from "@/router"; import getDashboard from "@/hooks/useDashboardsSession"; import { MetricConfigOpt } from "@/types/dashboard"; +import MetricGraph from "./components/MetricGraph.vue"; /*global defineProps */ const props = defineProps({ @@ -185,26 +160,6 @@ function clickEndpoint(scope: any) { async function searchList() { await queryEndpoints(); } -function getUnit(index: number) { - const u = - props.config.metricConfig && - props.config.metricConfig[index] && - props.config.metricConfig[index].unit; - if (u) { - return `(${encodeURIComponent(u)})`; - } - return encodeURIComponent(""); -} -function getLabel(metric: string, index: number) { - const label = - props.config.metricConfig && - props.config.metricConfig[index] && - props.config.metricConfig[index].label; - if (label) { - return encodeURIComponent(label); - } - return encodeURIComponent(metric); -} watch( () => [...(props.config.metricTypes || []), ...(props.config.metrics || [])], (data, old) => { diff --git a/src/views/dashboard/graphs/InstanceList.vue b/src/views/dashboard/graphs/InstanceList.vue index 94dd0716..8a572eb2 100644 --- a/src/views/dashboard/graphs/InstanceList.vue +++ b/src/views/dashboard/graphs/InstanceList.vue @@ -42,35 +42,11 @@ limitations under the License. --> - - - + - - - + [...(props.config.metricTypes || []), ...(props.config.metrics || [])], @@ -360,35 +275,7 @@ watch( diff --git a/src/views/dashboard/graphs/components/MetricGraph.vue b/src/views/dashboard/graphs/components/MetricGraph.vue new file mode 100644 index 00000000..7801f6e4 --- /dev/null +++ b/src/views/dashboard/graphs/components/MetricGraph.vue @@ -0,0 +1,161 @@ + + + + + +