Transformations: Preserve base threshold when using Config from query results (#96781)
* Merge in default threshold base if exists
* Fix tests to not expect default threshold
* Add config from query example to gdev
* Add a test around the merging of thresholds
* Revert "Add config from query example to gdev"
This reverts commit a239224ebb.
* update gdev
* Add note about keeping the base threshold
* Update public/app/features/transformers/docs/content.ts
Co-authored-by: Isabel Matwawana <76437239+imatwawana@users.noreply.github.com>
* Merge in generated code
---------
Co-authored-by: Leon Sorokin <leeoniya@gmail.com>
Co-authored-by: Isabel Matwawana <76437239+imatwawana@users.noreply.github.com>
This commit is contained in:
co-authored by
Isabel Matwawana
Leon Sorokin
parent
e9fae5bd7f
commit
f9eb013334
@@ -0,0 +1,17 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`setFieldConfigDefaults applies the base threshold when one does not exist in the config 1`] = `
|
||||
{
|
||||
"mode": "absolute",
|
||||
"steps": [
|
||||
{
|
||||
"color": "red",
|
||||
"value": -Infinity,
|
||||
},
|
||||
{
|
||||
"color": "green",
|
||||
"value": 50,
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
@@ -730,6 +730,33 @@ describe('setFieldConfigDefaults', () => {
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
it('applies the base threshold when one does not exist in the config', () => {
|
||||
const defaultConfig: FieldConfig = {
|
||||
thresholds: {
|
||||
mode: ThresholdsMode.Absolute,
|
||||
steps: [{ value: -Infinity, color: 'red' }],
|
||||
},
|
||||
};
|
||||
|
||||
const config: FieldConfig = {
|
||||
thresholds: {
|
||||
mode: ThresholdsMode.Absolute,
|
||||
steps: [{ value: 50, color: 'green' }],
|
||||
},
|
||||
};
|
||||
|
||||
const context: FieldOverrideEnv = {
|
||||
data: [],
|
||||
field: { type: FieldType.number } as Field,
|
||||
dataFrameIndex: 0,
|
||||
fieldConfigRegistry: customFieldRegistry,
|
||||
};
|
||||
|
||||
setFieldConfigDefaults(config, defaultConfig, context);
|
||||
|
||||
expect(config.thresholds).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
describe('setDynamicConfigValue', () => {
|
||||
|
||||
@@ -2,7 +2,7 @@ import { isNumber, set, unset, get, cloneDeep } from 'lodash';
|
||||
import { useMemo, useRef } from 'react';
|
||||
import usePrevious from 'react-use/lib/usePrevious';
|
||||
|
||||
import { VariableFormatID } from '@grafana/schema';
|
||||
import { ThresholdsMode, VariableFormatID } from '@grafana/schema';
|
||||
|
||||
import { compareArrayValues, compareDataFrameStructures } from '../dataframe/frameComparisons';
|
||||
import { guessFieldTypeForField } from '../dataframe/processDataFrame';
|
||||
@@ -347,6 +347,18 @@ export function setFieldConfigDefaults(config: FieldConfig, defaults: FieldConfi
|
||||
// Combine the data source links and the panel default config links
|
||||
config.links = [...config.links, ...defaults.links];
|
||||
}
|
||||
|
||||
// if we have a base threshold set by default but not on the config, we need to merge it in
|
||||
const defaultBaseStep =
|
||||
defaults?.thresholds?.mode === ThresholdsMode.Absolute &&
|
||||
defaults.thresholds?.steps.find((step) => step.value === -Infinity);
|
||||
if (
|
||||
config.thresholds?.mode === ThresholdsMode.Absolute &&
|
||||
!config.thresholds.steps.some((step) => step.value === -Infinity) &&
|
||||
defaultBaseStep
|
||||
) {
|
||||
config.thresholds.steps = [defaultBaseStep, ...config.thresholds.steps];
|
||||
}
|
||||
for (const fieldConfigProperty of context.fieldConfigRegistry.list()) {
|
||||
if (fieldConfigProperty.isCustom && !config.custom) {
|
||||
config.custom = {};
|
||||
|
||||
Reference in New Issue
Block a user