1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Enable default workspace on first boot (#1965)

* enable default workspace on first boot

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* refactor

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* use get/set

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Jari Kolehmainen 2021-01-19 06:30:05 +02:00 committed by GitHub
parent 41e012d83f
commit 31aa3cb571
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 17 deletions

View File

@ -36,6 +36,13 @@ describe("workspace store tests", () => {
expect(ws.getById(WorkspaceStore.defaultId)).not.toBe(null); expect(ws.getById(WorkspaceStore.defaultId)).not.toBe(null);
}); });
it("default workspace should be enabled", () => {
const ws = WorkspaceStore.getInstance<WorkspaceStore>();
expect(ws.workspaces.size).toBe(1);
expect(ws.getById(WorkspaceStore.defaultId).enabled).toBe(true);
});
it("cannot remove the default workspace", () => { it("cannot remove the default workspace", () => {
const ws = WorkspaceStore.getInstance<WorkspaceStore>(); const ws = WorkspaceStore.getInstance<WorkspaceStore>();

View File

@ -58,14 +58,7 @@ export class Workspace implements WorkspaceModel, WorkspaceState {
* @observable * @observable
*/ */
@observable ownerRef?: string; @observable ownerRef?: string;
/**
* Is workspace enabled
*
* Workspaces that don't have ownerRef will be enabled by default. Workspaces with ownerRef need to explicitly enable a workspace.
*
* @observable
*/
@observable enabled: boolean;
/** /**
* Last active cluster id * Last active cluster id
* *
@ -73,6 +66,9 @@ export class Workspace implements WorkspaceModel, WorkspaceState {
*/ */
@observable lastActiveClusterId?: ClusterId; @observable lastActiveClusterId?: ClusterId;
@observable private _enabled: boolean;
constructor(data: WorkspaceModel) { constructor(data: WorkspaceModel) {
Object.assign(this, data); Object.assign(this, data);
@ -83,6 +79,21 @@ export class Workspace implements WorkspaceModel, WorkspaceState {
} }
} }
/**
* Is workspace enabled
*
* Workspaces that don't have ownerRef will be enabled by default. Workspaces with ownerRef need to explicitly enable a workspace.
*
* @observable
*/
get enabled(): boolean {
return !this.isManaged || this._enabled;
}
set enabled(enabled: boolean) {
this._enabled = enabled;
}
/** /**
* Is workspace managed by an extension * Is workspace managed by an extension
*/ */
@ -134,10 +145,18 @@ export class WorkspaceStore extends BaseStore<WorkspaceStoreModel> {
static readonly defaultId: WorkspaceId = "default"; static readonly defaultId: WorkspaceId = "default";
private static stateRequestChannel = "workspace:states"; private static stateRequestChannel = "workspace:states";
@observable currentWorkspaceId = WorkspaceStore.defaultId;
@observable workspaces = observable.map<WorkspaceId, Workspace>();
private constructor() { private constructor() {
super({ super({
configName: "lens-workspace-store", configName: "lens-workspace-store",
}); });
this.workspaces.set(WorkspaceStore.defaultId, new Workspace({
id: WorkspaceStore.defaultId,
name: "default"
}));
} }
async load() { async load() {
@ -186,15 +205,6 @@ export class WorkspaceStore extends BaseStore<WorkspaceStoreModel> {
ipcRenderer.removeAllListeners("workspace:state"); ipcRenderer.removeAllListeners("workspace:state");
} }
@observable currentWorkspaceId = WorkspaceStore.defaultId;
@observable workspaces = observable.map<WorkspaceId, Workspace>({
[WorkspaceStore.defaultId]: new Workspace({
id: WorkspaceStore.defaultId,
name: "default"
})
});
@computed get currentWorkspace(): Workspace { @computed get currentWorkspace(): Workspace {
return this.getById(this.currentWorkspaceId); return this.getById(this.currentWorkspaceId);
} }