From 989212810bf2a39c199f8ed39d2d6cc0897af92d Mon Sep 17 00:00:00 2001 From: Fine Date: Sun, 30 Oct 2022 10:03:01 +0800 Subject: [PATCH] refactor query source --- src/hooks/useProcessor.ts | 42 ++++++++++++++------------------------- 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/src/hooks/useProcessor.ts b/src/hooks/useProcessor.ts index b0b23e2f..3615df83 100644 --- a/src/hooks/useProcessor.ts +++ b/src/hooks/useProcessor.ts @@ -381,35 +381,23 @@ export function usePodsSource( aggregation(Number(d.value), c) ); const indexNum = labelsIdx.findIndex((d: string) => d === item.label); + let key = item.label; if (labels[indexNum] && indexNum > -1) { - if (!d[labels[indexNum]]) { - d[labels[indexNum]] = {}; - } - if ( - [ - Calculations.Average, - Calculations.ApdexAvg, - Calculations.PercentageAvg, - ].includes(c.calculation) - ) { - d[labels[indexNum]]["avg"] = calculateExp(item.values.values, c); - } - d[labels[indexNum]]["values"] = values; - } else { - if (!d[item.label]) { - d[item.label] = {}; - } - if ( - [ - Calculations.Average, - Calculations.ApdexAvg, - Calculations.PercentageAvg, - ].includes(c.calculation) - ) { - d[item.label]["avg"] = calculateExp(item.values.values, c); - } - d[item.label]["values"] = values; + key = labels[indexNum]; } + if (!d[key]) { + d[key] = {}; + } + if ( + [ + Calculations.Average, + Calculations.ApdexAvg, + Calculations.PercentageAvg, + ].includes(c.calculation) + ) { + d[key]["avg"] = calculateExp(item.values.values, c); + } + d[key]["values"] = values; if (idx === 0) { names.push(item.label); metricConfigArr.push({ ...c, index: i });