mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
add computed isEnabled getter to Workspace, use it everywhere
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
dfe6d72505
commit
52929d4886
@ -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", () => {
|
||||
|
||||
@ -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<WorkspaceStoreModel> {
|
||||
}
|
||||
|
||||
@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<WorkspaceStoreModel> {
|
||||
}
|
||||
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<WorkspaceStoreModel> {
|
||||
}
|
||||
|
||||
@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)]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -129,12 +129,11 @@ export class Workspaces extends React.Component {
|
||||
Workspaces
|
||||
</h2>
|
||||
<div className="items flex column gaps">
|
||||
{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 && <span> (current)</span>}
|
||||
</span>
|
||||
<span className="description">{description}</span>
|
||||
{!isDefault && !managed && (
|
||||
{!isDefault && !isManaged && (
|
||||
<Fragment>
|
||||
<Icon
|
||||
material="edit"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user