Files
grafana/packages/grafana-data/src/transformations/matchers/valueMatchers/numericMatchers.ts
Oscar Kilhed 40cdb30336 Transformations: Add support for dashboard variable in limit, sort by, filter by value, heatmap and histogram (#75372)
* 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>
2023-10-04 17:28:46 +03:00

93 lines
3.0 KiB
TypeScript

import { Field, FieldType } from '../../../types/dataFrame';
import { ValueMatcherInfo } from '../../../types/transformations';
import { ValueMatcherID } from '../ids';
import { BasicValueMatcherOptions } from './types';
const isGreaterValueMatcher: ValueMatcherInfo<BasicValueMatcherOptions> = {
id: ValueMatcherID.greater,
name: 'Is greater',
description: 'Match when field value is greater than option.',
get: (options) => {
return (valueIndex: number, field: Field) => {
const value = field.values[valueIndex];
if (isNaN(value)) {
return false;
}
return value > options.value;
};
},
getOptionsDisplayText: (options) => {
return `Matches all rows where field value is greater than: ${options.value}.`;
},
isApplicable: (field) => field.type === FieldType.number,
getDefaultOptions: () => ({ value: 0 }),
};
const isGreaterOrEqualValueMatcher: ValueMatcherInfo<BasicValueMatcherOptions> = {
id: ValueMatcherID.greaterOrEqual,
name: 'Is greater or equal',
description: 'Match when field value is greater than or equal to option.',
get: (options) => {
return (valueIndex: number, field: Field) => {
const value = field.values[valueIndex];
if (isNaN(value)) {
return false;
}
return value >= options.value;
};
},
getOptionsDisplayText: (options) => {
return `Matches all rows where field value is greater than or equal to: ${options.value}.`;
},
isApplicable: (field) => field.type === FieldType.number,
getDefaultOptions: () => ({ value: 0 }),
};
const isLowerValueMatcher: ValueMatcherInfo<BasicValueMatcherOptions> = {
id: ValueMatcherID.lower,
name: 'Is lower',
description: 'Match when field value is lower than option.',
get: (options) => {
return (valueIndex: number, field: Field) => {
const value = field.values[valueIndex];
if (isNaN(value)) {
return false;
}
return value < options.value;
};
},
getOptionsDisplayText: (options) => {
return `Matches all rows where field value is lower than: ${options.value}.`;
},
isApplicable: (field) => field.type === FieldType.number,
getDefaultOptions: () => ({ value: 0 }),
};
const isLowerOrEqualValueMatcher: ValueMatcherInfo<BasicValueMatcherOptions> = {
id: ValueMatcherID.lowerOrEqual,
name: 'Is lower or equal',
description: 'Match when field value is lower or equal than option.',
get: (options) => {
return (valueIndex: number, field: Field) => {
const value = field.values[valueIndex];
if (isNaN(value)) {
return false;
}
return value <= options.value;
};
},
getOptionsDisplayText: (options) => {
return `Matches all rows where field value is lower or equal than: ${options.value}.`;
},
isApplicable: (field) => field.type === FieldType.number,
getDefaultOptions: () => ({ value: 0 }),
};
export const getNumericValueMatchers = (): ValueMatcherInfo[] => [
isGreaterValueMatcher,
isGreaterOrEqualValueMatcher,
isLowerValueMatcher,
isLowerOrEqualValueMatcher,
];