V2: Fix ad hoc filter defaultKeys incorrectly set to static mode (#115508)
* V2: Fix ad hoc filter defaultKeys incorrectly set to static mode * Fixture update
This commit is contained in:
@@ -554,7 +554,7 @@ export function sceneVariablesSetToSchemaV2Variables(
|
||||
...validateFiltersOrigin(variable.state.originFilters),
|
||||
...validateFiltersOrigin(variable.state.filters),
|
||||
],
|
||||
defaultKeys: variable.state.defaultKeys || [], //FIXME what is the default value?
|
||||
defaultKeys: variable.state.defaultKeys || [],
|
||||
allowCustomValue: variable.state.allowCustomValue ?? true,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1137,7 +1137,13 @@
|
||||
"datasource": { "name": "esmce00tbim8" },
|
||||
"group": "opensearch",
|
||||
"spec": {
|
||||
"allowCustomValue": true
|
||||
"name": "adhocVar",
|
||||
"allowCustomValue": true,
|
||||
"filters": [],
|
||||
"baseFilters": [],
|
||||
"defaultKeys": [],
|
||||
"hide": "dontHide",
|
||||
"skipUrlSync": false
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
+52
@@ -365,6 +365,35 @@ describe('transformSaveModelSchemaV2ToScene', () => {
|
||||
expect(getQueryRunnerFor(vizPanels[0])?.state.datasource?.uid).toBe(MIXED_DATASOURCE_NAME);
|
||||
});
|
||||
|
||||
describe('adhoc variables', () => {
|
||||
it('should convert empty defaultKeys array to undefined', () => {
|
||||
const dashboard = cloneDeep(defaultDashboard);
|
||||
const adhocVar = dashboard.spec.variables.find((v) => v.kind === 'AdhocVariable') as AdhocVariableKind;
|
||||
adhocVar.spec.defaultKeys = [];
|
||||
|
||||
const scene = transformSaveModelSchemaV2ToScene(dashboard);
|
||||
|
||||
const adhocVariable = scene.state.$variables?.getByName('adhocVar') as AdHocFiltersVariable;
|
||||
expect(adhocVariable).toBeInstanceOf(AdHocFiltersVariable);
|
||||
|
||||
expect(adhocVariable.state.defaultKeys).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should preserve non-empty defaultKeys array', () => {
|
||||
const dashboard = cloneDeep(defaultDashboard);
|
||||
|
||||
const adhocVar = dashboard.spec.variables.find((v) => v.kind === 'AdhocVariable') as AdhocVariableKind;
|
||||
expect(adhocVar.spec.defaultKeys.length).toBeGreaterThan(0);
|
||||
|
||||
const scene = transformSaveModelSchemaV2ToScene(dashboard);
|
||||
|
||||
const adhocVariable = scene.state.$variables?.getByName('adhocVar') as AdHocFiltersVariable;
|
||||
expect(adhocVariable).toBeInstanceOf(AdHocFiltersVariable);
|
||||
|
||||
expect(adhocVariable.state.defaultKeys).toEqual(adhocVar.spec.defaultKeys);
|
||||
});
|
||||
});
|
||||
|
||||
describe('When creating a snapshot dashboard scene', () => {
|
||||
it('should initialize a dashboard scene with SnapshotVariables', () => {
|
||||
const snapshot: DashboardWithAccessInfo<DashboardV2Spec> = {
|
||||
@@ -401,6 +430,29 @@ describe('transformSaveModelSchemaV2ToScene', () => {
|
||||
expect(intervalSnapshot.state.text).toBe('1m');
|
||||
expect(intervalSnapshot.state.isReadOnly).toBe(true);
|
||||
});
|
||||
|
||||
it('should convert empty defaultKeys array to undefined for adhoc variables', () => {
|
||||
const snapshot: DashboardWithAccessInfo<DashboardV2Spec> = cloneDeep({
|
||||
...defaultDashboard,
|
||||
metadata: {
|
||||
...defaultDashboard.metadata,
|
||||
annotations: {
|
||||
...defaultDashboard.metadata.annotations,
|
||||
[AnnoKeyDashboardIsSnapshot]: 'true',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const adhocVar = snapshot.spec.variables.find((v) => v.kind === 'AdhocVariable') as AdhocVariableKind;
|
||||
adhocVar.spec.defaultKeys = [];
|
||||
|
||||
const scene = transformSaveModelSchemaV2ToScene(snapshot);
|
||||
|
||||
const adhocVariable = scene.state.$variables?.getByName('adhocVar') as AdHocFiltersVariable;
|
||||
expect(adhocVariable).toBeInstanceOf(AdHocFiltersVariable);
|
||||
|
||||
expect(adhocVariable.state.defaultKeys).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('meta', () => {
|
||||
|
||||
+2
-2
@@ -329,7 +329,7 @@ function createSceneVariableFromVariableModel(variable: TypedVariableModelV2): S
|
||||
applyMode: 'auto',
|
||||
filters: variable.spec.filters ?? [],
|
||||
baseFilters: variable.spec.baseFilters ?? [],
|
||||
defaultKeys: variable.spec.defaultKeys,
|
||||
defaultKeys: variable.spec.defaultKeys.length ? variable.spec.defaultKeys : undefined,
|
||||
useQueriesAsFilterForOptions: true,
|
||||
drilldownRecommendationsEnabled: config.featureToggles.drilldownRecommendations,
|
||||
layout: config.featureToggles.newFiltersUI ? 'combobox' : undefined,
|
||||
@@ -538,7 +538,7 @@ export function createVariablesForSnapshot(dashboard: DashboardV2Spec): SceneVar
|
||||
applyMode: 'auto',
|
||||
filters: v.spec.filters ?? [],
|
||||
baseFilters: v.spec.baseFilters ?? [],
|
||||
defaultKeys: v.spec.defaultKeys,
|
||||
defaultKeys: v.spec.defaultKeys?.length ? v.spec.defaultKeys : undefined,
|
||||
useQueriesAsFilterForOptions: true,
|
||||
layout: config.featureToggles.newFiltersUI ? 'combobox' : undefined,
|
||||
supportsMultiValueOperators: Boolean(
|
||||
|
||||
Reference in New Issue
Block a user