Fix workspace overview switching and enabled state storage (#2342)

This commit is contained in:
Sebastian Malton authored and GitHub committed 2021-03-16 13:48:07 -04:00
1 parent a9a5766920
commit 1aff341f0e
3 files changed
+50 -30

No files matched your search

+26 -10
View File
@@ -26,6 +26,8 @@ export interface WorkspaceState {
enabled: boolean;
}
const updateFromModel = Symbol("updateFromModel");
/**
* Workspace
*
@@ -114,7 +116,7 @@ export class Workspace implements WorkspaceModel, WorkspaceState {
/**
* Push state
*
* @interal
* @internal
* @param state workspace state
*/
pushState(state = this.getState()) {
@@ -130,6 +132,10 @@ export class Workspace implements WorkspaceModel, WorkspaceState {
Object.assign(this, state);
}
[updateFromModel] = action((model: WorkspaceModel) => {
Object.assign(this, model);
});
toJSON(): WorkspaceModel {
return toJS({
id: this.id,
@@ -303,16 +309,26 @@ export class WorkspaceStore extends BaseStore<WorkspaceStoreModel> {
this.currentWorkspaceId = currentWorkspace;
}
if (workspaces.length) {
this.workspaces.clear();
workspaces.forEach(ws => {
const workspace = new Workspace(ws);
const currentWorkspaces = this.workspaces.toJS();
const newWorkspaceIds = new Set<WorkspaceId>([WorkspaceStore.defaultId]); // never delete default
if (!workspace.isManaged) {
workspace.enabled = true;
}
this.workspaces.set(workspace.id, workspace);
});
for (const workspaceModel of workspaces) {
const oldWorkspace = this.workspaces.get(workspaceModel.id);
if (oldWorkspace) {
oldWorkspace[updateFromModel](workspaceModel);
} else {
this.workspaces.set(workspaceModel.id, new Workspace(workspaceModel));
}
newWorkspaceIds.add(workspaceModel.id);
}
// remove deleted workspaces
for (const workspaceId of currentWorkspaces.keys()) {
if (!newWorkspaceIds.has(workspaceId)) {
this.workspaces.delete(workspaceId);
}
}
}