mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Color: Fixes issue where colors where reset to gray when switch panels (#31611)
This commit is contained in:
parent
8016b3c5ca
commit
4c5321bd99
@ -8,6 +8,7 @@ import {
|
||||
standardEditorsRegistry,
|
||||
standardFieldConfigEditorRegistry,
|
||||
StandardOptionConfig,
|
||||
ThresholdsMode,
|
||||
} from '@grafana/data';
|
||||
import { getPanelPlugin } from 'app/features/plugins/__mocks__/pluginMocks';
|
||||
import { mockStandardFieldConfigOptions } from 'test/helpers/fieldConfig';
|
||||
@ -59,9 +60,7 @@ describe('getPanelOptionsWithDefaults', () => {
|
||||
expect(result).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"fieldConfig": Object {
|
||||
"defaults": Object {
|
||||
"custom": Object {},
|
||||
},
|
||||
"defaults": Object {},
|
||||
"overrides": Array [],
|
||||
},
|
||||
"options": Object {},
|
||||
@ -232,6 +231,30 @@ describe('getPanelOptionsWithDefaults', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('when changing panel type to one that does not use standard field config', () => {
|
||||
it('should clean defaults', () => {
|
||||
const plugin = getPanelPlugin({ id: 'graph' });
|
||||
|
||||
const result = getPanelOptionsWithDefaults({
|
||||
plugin,
|
||||
currentOptions: {},
|
||||
currentFieldConfig: {
|
||||
defaults: {
|
||||
color: { mode: FieldColorModeId.Thresholds },
|
||||
thresholds: {
|
||||
mode: ThresholdsMode.Absolute,
|
||||
steps: [],
|
||||
},
|
||||
},
|
||||
overrides: [],
|
||||
},
|
||||
isAfterPluginChange: true,
|
||||
});
|
||||
|
||||
expect(result.fieldConfig.defaults.thresholds).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when applying defaults clean properties that are no longer part of the registry', () => {
|
||||
it('should remove custom defaults that no longer exist', () => {
|
||||
const result = runScenario({
|
||||
|
@ -105,6 +105,8 @@ export function filterFieldConfigOverrides(
|
||||
}
|
||||
|
||||
function cleanProperties(obj: any, parentPath: string, fieldConfigRegistry: FieldConfigOptionsRegistry) {
|
||||
let found = false;
|
||||
|
||||
for (const propName of Object.keys(obj)) {
|
||||
const value = obj[propName];
|
||||
const fullPath = `${parentPath}${propName}`;
|
||||
@ -112,6 +114,7 @@ function cleanProperties(obj: any, parentPath: string, fieldConfigRegistry: Fiel
|
||||
|
||||
// need to check early here as some standard properties have nested properies
|
||||
if (existsInRegistry) {
|
||||
found = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -120,9 +123,15 @@ function cleanProperties(obj: any, parentPath: string, fieldConfigRegistry: Fiel
|
||||
unset(obj, propName);
|
||||
}
|
||||
} else {
|
||||
cleanProperties(value, `${fullPath}.`, fieldConfigRegistry);
|
||||
const childPropFound = cleanProperties(value, `${fullPath}.`, fieldConfigRegistry);
|
||||
// If no child props found unset the main object
|
||||
if (!childPropFound) {
|
||||
unset(obj, propName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
function adaptFieldColorMode(
|
||||
|
Loading…
Reference in New Issue
Block a user