From 504a8b8ebaff5e72c9d59765fb03f590188ddcf3 Mon Sep 17 00:00:00 2001 From: Maksym Tsymbarov Date: Fri, 27 Nov 2026 16:44:33 +0100 Subject: [PATCH] Fixed "Navigate to other dashboard" losing the entity when the target dashboard state is empty or missing (#16841) * Fixed "Navigate to other dashboard" losing the entity when the target dashboard state is empty or missing * PR comments fixes --- .../states/default-state-controller.component.ts | 2 +- .../states/entity-state-controller.component.ts | 2 +- .../dashboard-page/states/state-controller.component.ts | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/dashboard-page/states/default-state-controller.component.ts b/ui-ngx/src/app/modules/home/components/dashboard-page/states/default-state-controller.component.ts index a8e96124c3..30cc481643 100644 --- a/ui-ngx/src/app/modules/home/components/dashboard-page/states/default-state-controller.component.ts +++ b/ui-ngx/src/app/modules/home/components/dashboard-page/states/default-state-controller.component.ts @@ -217,7 +217,7 @@ export class DefaultStateControllerComponent extends StateControllerComponent im if (result && result.length > 1) { result = [ result[result.length - 1] ]; } - return this.normalizeStateObject(result); + return this.normalizeIncomingStateObject(result); } private gotoState(stateId: string, update: boolean, openRightLayout?: boolean) { diff --git a/ui-ngx/src/app/modules/home/components/dashboard-page/states/entity-state-controller.component.ts b/ui-ngx/src/app/modules/home/components/dashboard-page/states/entity-state-controller.component.ts index 03917752a3..d6b13f4855 100644 --- a/ui-ngx/src/app/modules/home/components/dashboard-page/states/entity-state-controller.component.ts +++ b/ui-ngx/src/app/modules/home/components/dashboard-page/states/entity-state-controller.component.ts @@ -258,7 +258,7 @@ export class EntityStateControllerComponent extends StateControllerComponent imp result = []; } } - return this.normalizeStateObject(result); + return this.normalizeIncomingStateObject(result); } private gotoState(stateId: string, update: boolean, openRightLayout?: boolean, replaceCurrentHistoryUrl?: boolean) { diff --git a/ui-ngx/src/app/modules/home/components/dashboard-page/states/state-controller.component.ts b/ui-ngx/src/app/modules/home/components/dashboard-page/states/state-controller.component.ts index 8f33c61860..5f46b0f528 100644 --- a/ui-ngx/src/app/modules/home/components/dashboard-page/states/state-controller.component.ts +++ b/ui-ngx/src/app/modules/home/components/dashboard-page/states/state-controller.component.ts @@ -133,6 +133,14 @@ export abstract class StateControllerComponent implements IStateControllerCompon return result; } + protected normalizeIncomingStateObject(stateObject: StateControllerState): StateControllerState { + const result = Array.isArray(stateObject) ? [...stateObject] : []; + if (result.length && (!result[0]?.id || !this.states[result[0].id])) { + result[0] = { ...result[0], id: this.dashboardUtils.getRootStateId(this.states) }; + } + return this.normalizeStateObject(result); + } + protected updateStateParam(newState: string, replaceCurrentHistoryUrl = false) { this.currentState = newState; if (this.syncStateWithQueryParam) {