Do not use dashboard state param from url location inside embed dashboard dialog

This commit is contained in:
Igor Kulikov 2021-02-05 11:50:35 +02:00
parent 6f2a4409c1
commit 03fa7dcd41
6 changed files with 39 additions and 21 deletions

View File

@ -53,6 +53,7 @@
[isMobile]="isMobile" [isMobile]="isMobile"
[state]="dashboardCtx.state" [state]="dashboardCtx.state"
[currentState]="currentState" [currentState]="currentState"
[syncStateWithQueryParam]="syncStateWithQueryParam"
[states]="dashboardConfiguration.states"> [states]="dashboardConfiguration.states">
</tb-states-component> </tb-states-component>
</div> </div>

View File

@ -123,6 +123,9 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC
@Input() @Input()
hideToolbar: boolean; hideToolbar: boolean;
@Input()
syncStateWithQueryParam = true;
@Input() @Input()
dashboard: Dashboard; dashboard: Dashboard;
dashboardConfiguration: DashboardConfiguration; dashboardConfiguration: DashboardConfiguration;

View File

@ -88,6 +88,8 @@ export abstract class StateControllerComponent implements IStateControllerCompon
currentState: string; currentState: string;
syncStateWithQueryParam: boolean;
private rxSubscriptions = new Array<Subscription>(); private rxSubscriptions = new Array<Subscription>();
private inited = false; private inited = false;
@ -99,6 +101,7 @@ export abstract class StateControllerComponent implements IStateControllerCompon
} }
ngOnInit(): void { ngOnInit(): void {
if (this.syncStateWithQueryParam) {
this.rxSubscriptions.push(this.route.queryParamMap.subscribe((paramMap) => { this.rxSubscriptions.push(this.route.queryParamMap.subscribe((paramMap) => {
const dashboardId = this.route.snapshot.params.dashboardId || ''; const dashboardId = this.route.snapshot.params.dashboardId || '';
if (this.dashboardId === dashboardId) { if (this.dashboardId === dashboardId) {
@ -111,6 +114,7 @@ export abstract class StateControllerComponent implements IStateControllerCompon
} }
} }
})); }));
}
this.init(); this.init();
this.inited = true; this.inited = true;
} }
@ -124,6 +128,7 @@ export abstract class StateControllerComponent implements IStateControllerCompon
protected updateStateParam(newState: string) { protected updateStateParam(newState: string) {
this.currentState = newState; this.currentState = newState;
if (this.syncStateWithQueryParam) {
const queryParams: Params = {state: this.currentState}; const queryParams: Params = {state: this.currentState};
this.ngZone.run(() => { this.ngZone.run(() => {
this.router.navigate( this.router.navigate(
@ -135,6 +140,7 @@ export abstract class StateControllerComponent implements IStateControllerCompon
}); });
}); });
} }
}
public openRightLayout(): void { public openRightLayout(): void {
this.dashboardCtrl.openRightLayout(); this.dashboardCtrl.openRightLayout();

View File

@ -24,6 +24,7 @@ export interface IStateControllerComponent extends IStateController {
stateControllerInstanceId: string; stateControllerInstanceId: string;
state: string; state: string;
currentState: string; currentState: string;
syncStateWithQueryParam: boolean;
isMobile: boolean; isMobile: boolean;
states: {[id: string]: DashboardState }; states: {[id: string]: DashboardState };
dashboardId: string; dashboardId: string;

View File

@ -53,6 +53,9 @@ export class StatesComponentDirective implements OnInit, OnDestroy, OnChanges {
@Input() @Input()
currentState: string; currentState: string;
@Input()
syncStateWithQueryParam: boolean;
@Input() @Input()
isMobile: boolean; isMobile: boolean;
@ -89,6 +92,8 @@ export class StatesComponentDirective implements OnInit, OnDestroy, OnChanges {
this.stateControllerComponent.state = this.state; this.stateControllerComponent.state = this.state;
} else if (propName === 'currentState') { } else if (propName === 'currentState') {
this.stateControllerComponent.currentState = this.currentState; this.stateControllerComponent.currentState = this.currentState;
} else if (propName === 'syncStateWithQueryParam') {
this.stateControllerComponent.syncStateWithQueryParam = this.syncStateWithQueryParam;
} }
} }
} }
@ -119,6 +124,7 @@ export class StatesComponentDirective implements OnInit, OnDestroy, OnChanges {
this.stateControllerComponent.stateControllerInstanceId = stateControllerInstanceId; this.stateControllerComponent.stateControllerInstanceId = stateControllerInstanceId;
this.stateControllerComponent.state = this.state; this.stateControllerComponent.state = this.state;
this.stateControllerComponent.currentState = this.currentState; this.stateControllerComponent.currentState = this.currentState;
this.stateControllerComponent.syncStateWithQueryParam = this.syncStateWithQueryParam;
this.stateControllerComponent.isMobile = this.isMobile; this.stateControllerComponent.isMobile = this.isMobile;
this.stateControllerComponent.states = this.states; this.stateControllerComponent.states = this.states;
this.stateControllerComponent.dashboardId = this.dashboardId; this.stateControllerComponent.dashboardId = this.dashboardId;

View File

@ -27,7 +27,8 @@
</mat-progress-bar> </mat-progress-bar>
<div style="height: 4px;" *ngIf="!(isLoading$ | async)"></div> <div style="height: 4px;" *ngIf="!(isLoading$ | async)"></div>
<div class="dashboard-state-dialog-content" mat-dialog-content fxFlex fxLayout="column" style="padding: 8px;"> <div class="dashboard-state-dialog-content" mat-dialog-content fxFlex fxLayout="column" style="padding: 8px;">
<tb-dashboard-page [embedded]="true" [hideToolbar]="hideToolbar" [currentState]="state" [dashboard]="dashboard" style="width: 100%; height: 100%;"></tb-dashboard-page> <tb-dashboard-page [embedded]="true" [syncStateWithQueryParam]="false" [hideToolbar]="hideToolbar"
[currentState]="state" [dashboard]="dashboard" style="width: 100%; height: 100%;"></tb-dashboard-page>
</div> </div>
<div mat-dialog-actions fxLayoutAlign="end center"> <div mat-dialog-actions fxLayoutAlign="end center">
<button mat-button color="primary" <button mat-button color="primary"