TextBoxVariable: Fix change detection for query prop (#109895)
* fix textbox variable model save on change * better test name * betterer * fix test * fix test
This commit is contained in:
+3
-1
@@ -1765,7 +1765,9 @@ exports[`better eslint`] = {
|
||||
[0, 0, 0, "Do not use any type assertions.", "3"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "4"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "5"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "6"]
|
||||
[0, 0, 0, "Do not use any type assertions.", "6"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "7"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "8"]
|
||||
],
|
||||
"public/app/features/dashboard-scene/scene/PanelMenuBehavior.tsx:5381": [
|
||||
[0, 0, 0, "Do not use any type assertions.", "0"]
|
||||
|
||||
@@ -326,6 +326,64 @@ describe('getDashboardChanges', () => {
|
||||
expect(result).toEqual(expectedChanges);
|
||||
});
|
||||
|
||||
it('should not see any changes on modified textbox var when we do not update variable values', () => {
|
||||
const newDashboard: Dashboard = {
|
||||
...initial,
|
||||
templating: {
|
||||
list: [
|
||||
{
|
||||
name: 'var1',
|
||||
type: 'textbox',
|
||||
query: '',
|
||||
current: {
|
||||
value: 'value1',
|
||||
text: 'text1',
|
||||
},
|
||||
options: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
const changedDashboard: Dashboard = {
|
||||
...newDashboard,
|
||||
templating: {
|
||||
list: [
|
||||
{
|
||||
name: 'var1',
|
||||
type: 'textbox',
|
||||
query: 'query',
|
||||
current: {
|
||||
value: 'value1',
|
||||
text: 'text1',
|
||||
},
|
||||
options: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
const expectedChanges = {
|
||||
initialSaveModel: {
|
||||
...newDashboard,
|
||||
},
|
||||
changedSaveModel: {
|
||||
...changedDashboard,
|
||||
},
|
||||
diffs: {},
|
||||
diffCount: 0,
|
||||
hasChanges: false,
|
||||
hasTimeChanges: false,
|
||||
isNew: false,
|
||||
hasVariableValueChanges: false,
|
||||
hasRefreshChange: false,
|
||||
};
|
||||
|
||||
const result = getRawDashboardChanges(newDashboard, changedDashboard, false, false, false);
|
||||
|
||||
expect(result).toEqual(expectedChanges);
|
||||
});
|
||||
|
||||
it('should return the correct result when the variable value changes', () => {
|
||||
const changed = {
|
||||
...initial,
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
// @ts-ignore
|
||||
|
||||
import type { AdHocVariableModel, TypedVariableModel } from '@grafana/data';
|
||||
import type { AdHocVariableModel, TextBoxVariableModel, TypedVariableModel } from '@grafana/data';
|
||||
import { Dashboard, Panel, VariableOption } from '@grafana/schema';
|
||||
import {
|
||||
AdHocFilterWithLabels,
|
||||
AdhocVariableSpec,
|
||||
Spec as DashboardV2Spec,
|
||||
TextVariableSpec,
|
||||
VariableKind,
|
||||
} from '@grafana/schema/dist/esm/schema/dashboard/v2';
|
||||
import { ResponseTransformers } from 'app/features/dashboard/api/ResponseTransformers';
|
||||
@@ -217,7 +218,11 @@ export function applyVariableChangesV2(
|
||||
if (!saveVariables) {
|
||||
if (variable.kind === 'AdhocVariable') {
|
||||
variable.spec.filters = (original.spec as AdhocVariableSpec).filters;
|
||||
} else {
|
||||
} else if (variable.kind === 'TextVariable') {
|
||||
variable.spec.query = (original.spec as TextVariableSpec).query;
|
||||
}
|
||||
|
||||
if (variable.kind !== 'AdhocVariable') {
|
||||
if (hasCurrentValueToSave(variable) && hasCurrentValueToSave(original)) {
|
||||
variable.spec.current = original.spec.current;
|
||||
}
|
||||
@@ -262,9 +267,14 @@ export function applyVariableChanges(saveModel: Dashboard, originalSaveModel: Da
|
||||
|
||||
if (!saveVariables) {
|
||||
const typed = variable as TypedVariableModel;
|
||||
|
||||
if (typed.type === 'adhoc') {
|
||||
typed.filters = (original as AdHocVariableModel).filters;
|
||||
} else {
|
||||
} else if (typed.type === 'textbox') {
|
||||
typed.query = (original as TextBoxVariableModel).query;
|
||||
}
|
||||
|
||||
if (typed.type !== 'adhoc') {
|
||||
variable.current = original.current;
|
||||
variable.options = original.options;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user