refactor: update

This commit is contained in:
Fine 2023-06-02 15:59:08 +08:00
parent 980f8fa650
commit 0db3c06770

View File

@ -114,10 +114,10 @@ export function useExpressionsSourceProcessor(
} }
const source: { [key: string]: unknown } = {}; const source: { [key: string]: unknown } = {};
const keys = Object.keys(resp.data); const keys = Object.keys(resp.data);
for (let i = 0; i < config.metricTypes.length; i++) {
config.metricTypes.forEach((type: string, index) => { const type = config.metricTypes[i];
const c = (config.metricConfig && config.metricConfig[index]) || {}; const c = (config.metricConfig && config.metricConfig[i]) || {};
const results = (resp.data[keys[index]] && resp.data[keys[index]].results) || []; const results = (resp.data[keys[i]] && resp.data[keys[i]].results) || [];
const name = ((results[0] || {}).metric || {}).name; const name = ((results[0] || {}).metric || {}).name;
if (type === ExpressionResultType.TIME_SERIES_VALUES) { if (type === ExpressionResultType.TIME_SERIES_VALUES) {
@ -131,7 +131,7 @@ export function useExpressionsSourceProcessor(
if (([ExpressionResultType.RECORD_LIST, ExpressionResultType.SORTED_LIST] as string[]).includes(type)) { if (([ExpressionResultType.RECORD_LIST, ExpressionResultType.SORTED_LIST] as string[]).includes(type)) {
source[name] = results[0].values; source[name] = results[0].values;
} }
}); }
return source; return source;
} }