feat(ui): simplify labels of flux results

pull/5997/head
Pavel Zavora 2022-08-16 10:35:04 +02:00
parent 3b181b1d9c
commit 4d1feefcc6
1 changed files with 17 additions and 4 deletions

View File

@ -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)