From 4d1feefcc6412e3d48a5cccfe122925de0828bcb Mon Sep 17 00:00:00 2001 From: Pavel Zavora Date: Tue, 16 Aug 2022 10:35:04 +0200 Subject: [PATCH] feat(ui): simplify labels of flux results --- .../shared/parsing/flux/parseTablesByTime.ts | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/ui/src/shared/parsing/flux/parseTablesByTime.ts b/ui/src/shared/parsing/flux/parseTablesByTime.ts index 313298b6a..43152dc28 100644 --- a/ui/src/shared/parsing/flux/parseTablesByTime.ts +++ b/ui/src/shared/parsing/flux/parseTablesByTime.ts @@ -20,6 +20,22 @@ interface ParseTablesByTimeResult { nonNumericColumns: string[] } +const IGNORED_TABLE_KEYS = ['_start', '_stop', '_field'] + +function fluxTableKey(table: FluxTable, columnName: string): string { + const name = + columnName === '_value' && table.groupKey._field + ? table.groupKey._field + : columnName + const groupKeys = Object.entries(table.groupKey).reduce((acc, [k, v]) => { + if (!IGNORED_TABLE_KEYS.includes(k)) { + acc.push(`${k === '_measurement' ? 'measurement' : k}=${v}`) + } + return acc + }, []) + return groupKeys.length ? `${name} (${groupKeys.join(' ')})` : name +} + export const parseTablesByTime = ( tables: FluxTable[] ): ParseTablesByTimeResult => { @@ -47,10 +63,7 @@ export const parseTablesByTime = ( continue } - const uniqueColumnName = Object.entries(table.groupKey).reduce( - (acc, [k, v]) => acc + `[${k}=${v}]`, - columnName - ) + const uniqueColumnName = fluxTableKey(table, columnName) columnNames[i] = uniqueColumnName allColumnNames.push(uniqueColumnName)