From 52929d48861349f473bfc66e6853cc68ddf5ef13 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Fri, 15 Jan 2021 11:02:17 -0500 Subject: [PATCH] add computed isEnabled getter to Workspace, use it everywhere Signed-off-by: Sebastian Malton --- src/common/__tests__/workspace-store.test.ts | 2 +- src/common/workspace-store.ts | 27 ++++++++----------- .../components/+workspaces/workspaces.tsx | 5 ++-- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/common/__tests__/workspace-store.test.ts b/src/common/__tests__/workspace-store.test.ts index e69ebda0aa..37209b396f 100644 --- a/src/common/__tests__/workspace-store.test.ts +++ b/src/common/__tests__/workspace-store.test.ts @@ -66,7 +66,7 @@ describe("workspace store tests", () => { const workspace = ws.getById("123"); expect(workspace.name).toBe("foobar"); - expect(workspace.enabled).toBe(true); + expect(workspace.isEnabled).toBe(true); }); it("cannot set a non-existent workspace to be active", () => { diff --git a/src/common/workspace-store.ts b/src/common/workspace-store.ts index 7688516af2..bc907a182e 100644 --- a/src/common/workspace-store.ts +++ b/src/common/workspace-store.ts @@ -83,6 +83,13 @@ export class Workspace implements WorkspaceModel, WorkspaceState { } } + /** + * Is this workspace not manged by an extension or is it managed and explicitly enabled + */ + get isEnabled(): boolean { + return !this.isManaged || this.enabled; + } + /** * Is workspace managed by an extension */ @@ -204,7 +211,7 @@ export class WorkspaceStore extends BaseStore { } @computed get enabledWorkspacesList() { - return this.workspacesList.filter((w) => w.enabled); + return this.workspacesList.filter((w) => w.isEnabled); } pushState() { @@ -244,10 +251,6 @@ export class WorkspaceStore extends BaseStore { } this.workspaces.set(id, workspace); - if (!workspace.isManaged) { - workspace.enabled = true; - } - appEventBus.emit({name: "workspace", action: "add"}); return workspace; @@ -288,21 +291,13 @@ export class WorkspaceStore extends BaseStore { } @action - protected fromStore({ currentWorkspace, workspaces = [] }: WorkspaceStoreModel) { + protected fromStore({ currentWorkspace, workspaces }: WorkspaceStoreModel) { if (currentWorkspace) { this.currentWorkspaceId = currentWorkspace; } - if (workspaces.length) { - this.workspaces.clear(); - workspaces.forEach(ws => { - const workspace = new Workspace(ws); - - if (!workspace.isManaged) { - workspace.enabled = true; - } - this.workspaces.set(workspace.id, workspace); - }); + if (workspaces?.length) { + this.workspaces.replace(workspaces.map(ws => [ws.id, new Workspace(ws)])); } } diff --git a/src/renderer/components/+workspaces/workspaces.tsx b/src/renderer/components/+workspaces/workspaces.tsx index 932306adab..a6f3cffd97 100644 --- a/src/renderer/components/+workspaces/workspaces.tsx +++ b/src/renderer/components/+workspaces/workspaces.tsx @@ -129,12 +129,11 @@ export class Workspaces extends React.Component { Workspaces
- {this.workspaces.map(({ id: workspaceId, name, description, ownerRef }) => { + {this.workspaces.map(({ id: workspaceId, name, description, isManaged}) => { const isActive = workspaceStore.currentWorkspaceId === workspaceId; const isDefault = workspaceStore.isDefault(workspaceId); const isEditing = this.editingWorkspaces.has(workspaceId); const editingWorkspace = this.editingWorkspaces.get(workspaceId); - const managed = !!ownerRef; const className = cssNames("workspace flex gaps align-center", { active: isActive, editing: isEditing, @@ -154,7 +153,7 @@ export class Workspaces extends React.Component { {isActive && (current)} {description} - {!isDefault && !managed && ( + {!isDefault && !isManaged && (