From 524d6055c0ced8cf82de2a601aa8cfcec931b712 Mon Sep 17 00:00:00 2001 From: Bogdan Matei Date: Mon, 7 Jul 2025 10:30:33 +0300 Subject: [PATCH] Dashboards: Fix persisting repeated panels resize after edit (#107386) --- .../layout-default/DashboardGridItem.tsx | 40 +++++++++++++------ 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/public/app/features/dashboard-scene/scene/layout-default/DashboardGridItem.tsx b/public/app/features/dashboard-scene/scene/layout-default/DashboardGridItem.tsx index 05bd804b77c..e19803ed5f9 100644 --- a/public/app/features/dashboard-scene/scene/layout-default/DashboardGridItem.tsx +++ b/public/app/features/dashboard-scene/scene/layout-default/DashboardGridItem.tsx @@ -57,17 +57,38 @@ export class DashboardGridItem public constructor(state: DashboardGridItemState) { super(state); - this.addActivationHandler(() => this.handleVariableName()); + this.addActivationHandler(() => this._activationHandler()); + } + + private _activationHandler() { + this.handleVariableName(); + + return () => { + this._handleGridSizeUnsubscribe(); + }; + } + + private _handleGridSizeSubscribe() { + if (!this._gridSizeSub) { + this._gridSizeSub = this.subscribeToState((newState, prevState) => this._handleGridResize(newState, prevState)); + } + } + + private _handleGridSizeUnsubscribe() { + if (this._gridSizeSub) { + this._gridSizeSub.unsubscribe(); + this._gridSizeSub = undefined; + } } private _handleGridResize(newState: DashboardGridItemState, prevState: DashboardGridItemState) { - const itemCount = this.state.repeatedPanels?.length ?? 1; - const stateChange: Partial = {}; - if (newState.height === prevState.height) { return; } + const itemCount = this.state.repeatedPanels?.length ?? 1; + const stateChange: Partial = {}; + if (this.getRepeatDirection() === 'v') { stateChange.itemHeight = Math.ceil(newState.height! / itemCount); } else { @@ -203,16 +224,9 @@ export class DashboardGridItem public handleVariableName() { if (this.state.variableName) { - if (!this._gridSizeSub) { - this._gridSizeSub = this.subscribeToState((newState, prevState) => this._handleGridResize(newState, prevState)); - this._subs.add(this._gridSizeSub); - } + this._handleGridSizeSubscribe(); } else { - if (this._gridSizeSub) { - this._gridSizeSub.unsubscribe(); - this._subs.remove(this._gridSizeSub); - this._gridSizeSub = undefined; - } + this._handleGridSizeUnsubscribe(); } this.performRepeat();