From 3a3771db64b83c731caa3a5dbd629b6fef7c5c88 Mon Sep 17 00:00:00 2001 From: Igor Kulikov Date: Wed, 7 Dec 2022 15:34:42 +0200 Subject: [PATCH] UI: Fix handling dashboard page router data --- .../dashboard-page.component.ts | 33 ++++++++++++------- .../dashboard-page/dashboard-page.models.ts | 7 ++++ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.ts b/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.ts index 5acb6751f9..04cc676d95 100644 --- a/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.ts +++ b/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.ts @@ -56,7 +56,7 @@ import { WINDOW } from '@core/services/window.service'; import { WindowMessage } from '@shared/models/window-message.model'; import { deepClone, guid, isDefined, isDefinedAndNotNull, isNotEmptyStr } from '@app/core/utils'; import { - DashboardContext, + DashboardContext, DashboardPageInitData, DashboardPageLayout, DashboardPageLayoutContext, DashboardPageLayouts, @@ -365,15 +365,23 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC ngOnInit() { this.rxSubscriptions.push(this.route.data.subscribe( (data) => { + let dashboardPageInitData: DashboardPageInitData; if (this.embedded) { - data.dashboard = this.dashboardUtils.validateAndUpdateDashboard(this.dashboard); - data.currentDashboardId = this.dashboard.id ? this.dashboard.id.id : null; - data.widgetEditMode = false; - data.singlePageMode = false; + dashboardPageInitData = { + dashboard: this.dashboardUtils.validateAndUpdateDashboard(this.dashboard), + currentDashboardId: this.dashboard.id ? this.dashboard.id.id : null, + widgetEditMode: false, + singlePageMode: false + }; } else { - data.currentDashboardId = this.route.snapshot.params.dashboardId; + dashboardPageInitData = { + dashboard: data.dashboard, + currentDashboardId: this.route.snapshot.params.dashboardId, + widgetEditMode: data.widgetEditMode, + singlePageMode: data.singlePageMode + }; } - this.init(data); + this.init(dashboardPageInitData); this.runChangeDetection(); } )); @@ -406,7 +414,7 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC } } - private init(data: any) { + private init(data: DashboardPageInitData) { this.reset(); @@ -1492,11 +1500,12 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC versionControlPopover.tbComponentRef.instance.versionRestored.subscribe(() => { this.dashboardService.getDashboard(this.currentDashboardId).subscribe((dashboard) => { dashboard = this.dashboardUtils.validateAndUpdateDashboard(dashboard); - const data = { + const data: DashboardPageInitData = { dashboard, - widgetEditMode: false, - currentDashboardId: this.currentDashboardId - } as any; + currentDashboardId: this.currentDashboardId, + widgetEditMode: this.widgetEditMode, + singlePageMode: this.singlePageMode + }; this.init(data); this.dashboardCtx.stateController.cleanupPreservedStates(); this.dashboardCtx.stateController.resetState(); diff --git a/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.models.ts b/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.models.ts index 4fadc96039..92c5847b54 100644 --- a/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.models.ts +++ b/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.models.ts @@ -24,6 +24,13 @@ import { Observable } from 'rxjs'; export declare type DashboardPageScope = 'tenant' | 'customer'; +export interface DashboardPageInitData { + dashboard: Dashboard; + currentDashboardId?: string; + widgetEditMode?: boolean; + singlePageMode?: boolean; +} + export interface DashboardContext { instanceId: string; state: string;