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
alerting/fix-evaluation-interval
Oscar Kilhed 9 months ago committed by GitHub
parent f0ce33e569
commit 4d50cb2b7b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 3
      .betterer.results
  2. 18
      public/app/features/dashboard-scene/scene/RowRepeaterBehavior.test.tsx
  3. 33
      public/app/features/dashboard-scene/scene/RowRepeaterBehavior.ts

@ -2771,9 +2771,6 @@ exports[`better eslint`] = {
"public/app/features/dashboard-scene/scene/PanelMenuBehavior.tsx:5381": [
[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": [
[0, 0, 0, "No untranslated strings. Wrap text with <Trans />", "0"],
[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', () => {
let scene: DashboardScene;
let grid: SceneGridLayout;

@ -141,12 +141,7 @@ export class RowRepeaterBehavior extends SceneObjectBase<RowRepeaterBehaviorStat
return;
}
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 {
if (!(variable instanceof MultiValueVariable)) {
console.error('RepeatedRowBehavior: Variable is not a MultiValueVariable');
return;
}
@ -222,7 +217,8 @@ export class RowRepeaterBehavior extends SceneObjectBase<RowRepeaterBehaviorStat
localValue,
variableTexts[index],
rowContentHeight,
children
children,
variable
);
this._clonedRows.push(rowClone);
}
@ -239,13 +235,22 @@ export class RowRepeaterBehavior extends SceneObjectBase<RowRepeaterBehaviorStat
value: VariableValueSingle,
text: VariableValueSingle,
rowContentHeight: number,
children: SceneGridItemLike[]
children: SceneGridItemLike[],
variable: MultiValueVariable
): SceneGridRow {
if (index === 0) {
rowToRepeat.setState({
// not activated
$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,
});
@ -257,7 +262,15 @@ export class RowRepeaterBehavior extends SceneObjectBase<RowRepeaterBehaviorStat
return rowToRepeat.clone({
key: `${rowToRepeat.state.key}-clone-${value}`,
$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: [],
children,

Loading…
Cancel
Save