Merge pull request #3273 from vvlladd28/bug/update/state-id

[3.0] Fix update state id value
This commit is contained in:
Igor Kulikov 2020-08-10 16:34:16 +03:00 committed by GitHub
commit 6b53e84c84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -35,7 +35,7 @@ import { fromEvent, merge } from 'rxjs';
import { debounceTime, distinctUntilChanged, tap } from 'rxjs/operators'; import { debounceTime, distinctUntilChanged, tap } from 'rxjs/operators';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { DialogService } from '@core/services/dialog.service'; import { DialogService } from '@core/services/dialog.service';
import { deepClone } from '@core/utils'; import { deepClone, isUndefined } from '@core/utils';
import { import {
DashboardStateDialogComponent, DashboardStateDialogComponent,
DashboardStateDialogData DashboardStateDialogData
@ -198,8 +198,9 @@ export class ManageDashboardStatesDialogComponent extends
root: state.root, root: state.root,
layouts: state.layouts layouts: state.layouts
}; };
if (prevStateId) { if (prevStateId && prevStateId !== state.id) {
this.states[prevStateId] = newState; delete this.states[prevStateId];
this.states[state.id] = newState;
} else { } else {
this.states[state.id] = newState; this.states[state.id] = newState;
} }
@ -210,6 +211,19 @@ export class ManageDashboardStatesDialogComponent extends
otherState.root = false; otherState.root = false;
} }
} }
} else {
let rootFound = false;
for (const id of Object.keys(this.states)) {
const otherState = this.states[id];
if (otherState.root) {
rootFound = true;
break;
}
}
if (!rootFound) {
const firstStateId = Object.keys(this.states)[0];
this.states[firstStateId].root = true;
}
} }
this.onStatesUpdated(); this.onStatesUpdated();
} }