mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Scenes: Ensure scenes dashboards interpolate variables in sql queries the same as old arch (#93270)
Ensure scenes dashboards interpolate variables in sql queries the same as old arch
This commit is contained in:
parent
f0ce33e569
commit
4d50cb2b7b
@ -2771,9 +2771,6 @@ exports[`better eslint`] = {
|
|||||||
"public/app/features/dashboard-scene/scene/PanelMenuBehavior.tsx:5381": [
|
"public/app/features/dashboard-scene/scene/PanelMenuBehavior.tsx:5381": [
|
||||||
[0, 0, 0, "Do not use any type assertions.", "0"]
|
[0, 0, 0, "Do not use any type assertions.", "0"]
|
||||||
],
|
],
|
||||||
"public/app/features/dashboard-scene/scene/RowRepeaterBehavior.ts:5381": [
|
|
||||||
[0, 0, 0, "Do not use any type assertions.", "0"]
|
|
||||||
],
|
|
||||||
"public/app/features/dashboard-scene/scene/row-actions/RowActions.tsx:5381": [
|
"public/app/features/dashboard-scene/scene/row-actions/RowActions.tsx:5381": [
|
||||||
[0, 0, 0, "No untranslated strings. Wrap text with <Trans />", "0"],
|
[0, 0, 0, "No untranslated strings. Wrap text with <Trans />", "0"],
|
||||||
[0, 0, 0, "No untranslated strings. Wrap text with <Trans />", "1"],
|
[0, 0, 0, "No untranslated strings. Wrap text with <Trans />", "1"],
|
||||||
|
@ -167,24 +167,6 @@ describe('RowRepeaterBehavior', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Should not repeat row', () => {
|
|
||||||
it('Should ignore repeat process if the variable is not a multi select variable', async () => {
|
|
||||||
const { scene, grid, repeatBehavior } = buildScene({ variableQueryTime: 0 }, undefined, { isMulti: false });
|
|
||||||
const gridStateUpdates = [];
|
|
||||||
grid.subscribeToState((state) => gridStateUpdates.push(state));
|
|
||||||
|
|
||||||
activateFullSceneTree(scene);
|
|
||||||
await new Promise((r) => setTimeout(r, 1));
|
|
||||||
|
|
||||||
// trigger another repeat cycle by changing the variable
|
|
||||||
repeatBehavior.performRepeat();
|
|
||||||
|
|
||||||
await new Promise((r) => setTimeout(r, 1));
|
|
||||||
|
|
||||||
expect(gridStateUpdates.length).toBe(0);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Given scene with DashboardGridItem', () => {
|
describe('Given scene with DashboardGridItem', () => {
|
||||||
let scene: DashboardScene;
|
let scene: DashboardScene;
|
||||||
let grid: SceneGridLayout;
|
let grid: SceneGridLayout;
|
||||||
|
@ -141,12 +141,7 @@ export class RowRepeaterBehavior extends SceneObjectBase<RowRepeaterBehaviorStat
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (variable instanceof MultiValueVariable) {
|
if (!(variable instanceof MultiValueVariable)) {
|
||||||
if (!(variable as MultiValueVariable).state.isMulti) {
|
|
||||||
// There is no use in repeating a row for a variable that is not a multi value select variable.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
console.error('RepeatedRowBehavior: Variable is not a MultiValueVariable');
|
console.error('RepeatedRowBehavior: Variable is not a MultiValueVariable');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -222,7 +217,8 @@ export class RowRepeaterBehavior extends SceneObjectBase<RowRepeaterBehaviorStat
|
|||||||
localValue,
|
localValue,
|
||||||
variableTexts[index],
|
variableTexts[index],
|
||||||
rowContentHeight,
|
rowContentHeight,
|
||||||
children
|
children,
|
||||||
|
variable
|
||||||
);
|
);
|
||||||
this._clonedRows.push(rowClone);
|
this._clonedRows.push(rowClone);
|
||||||
}
|
}
|
||||||
@ -239,13 +235,22 @@ export class RowRepeaterBehavior extends SceneObjectBase<RowRepeaterBehaviorStat
|
|||||||
value: VariableValueSingle,
|
value: VariableValueSingle,
|
||||||
text: VariableValueSingle,
|
text: VariableValueSingle,
|
||||||
rowContentHeight: number,
|
rowContentHeight: number,
|
||||||
children: SceneGridItemLike[]
|
children: SceneGridItemLike[],
|
||||||
|
variable: MultiValueVariable
|
||||||
): SceneGridRow {
|
): SceneGridRow {
|
||||||
if (index === 0) {
|
if (index === 0) {
|
||||||
rowToRepeat.setState({
|
rowToRepeat.setState({
|
||||||
// not activated
|
// not activated
|
||||||
$variables: new SceneVariableSet({
|
$variables: new SceneVariableSet({
|
||||||
variables: [new LocalValueVariable({ name: this.state.variableName, value, text: String(text) })],
|
variables: [
|
||||||
|
new LocalValueVariable({
|
||||||
|
name: this.state.variableName,
|
||||||
|
value,
|
||||||
|
text: String(text),
|
||||||
|
isMulti: variable.state.isMulti,
|
||||||
|
includeAll: variable.state.includeAll,
|
||||||
|
}),
|
||||||
|
],
|
||||||
}),
|
}),
|
||||||
children,
|
children,
|
||||||
});
|
});
|
||||||
@ -257,7 +262,15 @@ export class RowRepeaterBehavior extends SceneObjectBase<RowRepeaterBehaviorStat
|
|||||||
return rowToRepeat.clone({
|
return rowToRepeat.clone({
|
||||||
key: `${rowToRepeat.state.key}-clone-${value}`,
|
key: `${rowToRepeat.state.key}-clone-${value}`,
|
||||||
$variables: new SceneVariableSet({
|
$variables: new SceneVariableSet({
|
||||||
variables: [new LocalValueVariable({ name: this.state.variableName, value, text: String(text) })],
|
variables: [
|
||||||
|
new LocalValueVariable({
|
||||||
|
name: this.state.variableName,
|
||||||
|
value,
|
||||||
|
text: String(text),
|
||||||
|
isMulti: variable.state.isMulti,
|
||||||
|
includeAll: variable.state.includeAll,
|
||||||
|
}),
|
||||||
|
],
|
||||||
}),
|
}),
|
||||||
$behaviors: [],
|
$behaviors: [],
|
||||||
children,
|
children,
|
||||||
|
Loading…
Reference in New Issue
Block a user