Repeats: Set scoped vars correctly for collapsed panel when toggled (#69707)

This commit is contained in:
Dominik Prokop 2023-06-12 11:59:05 +02:00 committed by GitHub
parent 38fc22538a
commit 1de8f48a53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -768,6 +768,7 @@ export class DashboardModel implements TimeModel {
for (let optionIndex = 0; optionIndex < selectedOptions.length; optionIndex++) {
const option = selectedOptions[optionIndex];
const rowCopy = this.getRowRepeatClone(panel, optionIndex, panelIndex);
setScopedVars(rowCopy, option);
const rowHeight = this.getRowHeight(rowCopy);
@ -955,6 +956,10 @@ export class DashboardModel implements TimeModel {
row.collapsed = false;
const rowPanels = row.panels ?? [];
const hasRepeat = rowPanels.some((p: PanelModel) => p.repeat);
// This is set only for the row being repeated.
const rowRepeatVariable = row.repeat;
if (rowPanels.length > 0) {
// Use first panel to figure out if it was moved or pushed
// If the panel doesn't have gridPos.y, use the row gridPos.y instead.
@ -969,6 +974,18 @@ export class DashboardModel implements TimeModel {
let yMax = row.gridPos.y;
for (const panel of rowPanels) {
// When expanding original row that's repeated, set scopedVars for repeated row panels.
if (rowRepeatVariable) {
const variable = this.getPanelRepeatVariable(row);
panel.scopedVars ??= {};
if (variable) {
const selectedOptions = this.getSelectedVariableOptions(variable);
panel.scopedVars = {
...panel.scopedVars,
[variable.name]: selectedOptions[0],
};
}
}
// set the y gridPos if it wasn't already set
panel.gridPos.y ?? (panel.gridPos.y = row.gridPos.y); // (Safari 13.1 lacks ??= support)
// make sure y is adjusted (in case row moved while collapsed)