mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* variables for filterforvalue * use datalinkinput for basic matcher * fix user select issue * heatmap transformation variable interpolation * clean code * interpolate sort by * add options interpolation in histogram transformation * interpolation for limit * Add suggestions UI to Filter by data value Transformation Co-authored-by: oscarkilhed <oscar.kilhed@grafana.com> * add validation for number/variable fields * Add variables to add field from calculation * Add validator to limit transformation * Refactor validator * Refactor suggestionInput styles * Add variable support in heatmap calculate options to be in sync with tranform * Refactor SuggestionsInput * Fix histogram, limit and filter by value matchers * clean up weird state ref * Only interpolate when the feature toggle is set * Add feature toggle to ui * Fix number of variable test * Fix issue with characters typed after opening suggestions still remains after selecting a suggestion * Clean up from review * Add more tests for numberOrVariableValidator --------- Co-authored-by: Victor Marin <victor.marin@grafana.com>
64 lines
1.7 KiB
TypeScript
64 lines
1.7 KiB
TypeScript
import { useMemo } from 'react';
|
|
|
|
import { DataFrame, getFieldDisplayName, TransformerCategory } from '@grafana/data';
|
|
import { config } from '@grafana/runtime';
|
|
|
|
export function useAllFieldNamesFromDataFrames(input: DataFrame[]): string[] {
|
|
return useMemo(() => {
|
|
if (!Array.isArray(input)) {
|
|
return [];
|
|
}
|
|
|
|
return Object.keys(
|
|
input.reduce<Record<string, boolean>>((names, frame) => {
|
|
if (!frame || !Array.isArray(frame.fields)) {
|
|
return names;
|
|
}
|
|
|
|
return frame.fields.reduce((names, field) => {
|
|
const t = getFieldDisplayName(field, frame, input);
|
|
names[t] = true;
|
|
return names;
|
|
}, names);
|
|
}, {})
|
|
);
|
|
}, [input]);
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
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',
|
|
};
|
|
|
|
export const numberOrVariableValidator = (value: string | number) => {
|
|
if (typeof value === 'number') {
|
|
return true;
|
|
}
|
|
if (!Number.isNaN(Number(value))) {
|
|
return true;
|
|
}
|
|
if (/^\$[A-Za-z0-9_]+$/.test(value) && config.featureToggles.transformationsVariableSupport) {
|
|
return true;
|
|
}
|
|
return false;
|
|
};
|