2021-07-13 03:51:34 -05:00
|
|
|
import { useMemo } from 'react';
|
|
|
|
|
2023-07-04 08:34:22 -05:00
|
|
|
import { DataFrame, getFieldDisplayName, TransformerCategory } from '@grafana/data';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
2021-07-13 03:51:34 -05:00
|
|
|
export function useAllFieldNamesFromDataFrames(input: DataFrame[]): string[] {
|
|
|
|
return useMemo(() => {
|
|
|
|
if (!Array.isArray(input)) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
return Object.keys(
|
2023-08-01 06:56:21 -05:00
|
|
|
input.reduce<Record<string, boolean>>((names, frame) => {
|
|
|
|
if (!frame || !Array.isArray(frame.fields)) {
|
|
|
|
return names;
|
|
|
|
}
|
2021-07-13 03:51:34 -05:00
|
|
|
|
2023-08-01 06:56:21 -05:00
|
|
|
return frame.fields.reduce((names, field) => {
|
|
|
|
const t = getFieldDisplayName(field, frame, input);
|
|
|
|
names[t] = true;
|
|
|
|
return names;
|
|
|
|
}, names);
|
|
|
|
}, {})
|
2021-07-13 03:51:34 -05:00
|
|
|
);
|
|
|
|
}, [input]);
|
|
|
|
}
|
2022-07-25 18:16:58 -05:00
|
|
|
|
|
|
|
export function getDistinctLabels(input: DataFrame[]): Set<string> {
|
|
|
|
const distinct = new Set<string>();
|
|
|
|
for (const frame of input) {
|
|
|
|
for (const field of frame.fields) {
|
|
|
|
if (field.labels) {
|
|
|
|
for (const k of Object.keys(field.labels)) {
|
|
|
|
distinct.add(k);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return distinct;
|
|
|
|
}
|
2023-07-04 08:34:22 -05:00
|
|
|
|
|
|
|
export const categoriesLabels: { [K in TransformerCategory]: string } = {
|
|
|
|
combine: 'Combine',
|
|
|
|
calculateNewFields: 'Calculate new fields',
|
|
|
|
createNewVisualization: 'Create new visualization',
|
|
|
|
filter: 'Filter',
|
|
|
|
performSpatialOperations: 'Perform spatial operations',
|
|
|
|
reformat: 'Reformat',
|
|
|
|
reorderAndRename: 'Reorder and rename',
|
|
|
|
};
|