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

hide disabled workspaces/clusters

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Jari Kolehmainen 2020-11-30 13:36:24 +02:00
parent 07e6df9fdc
commit 3bd484f92a
6 changed files with 46 additions and 9 deletions

View File

@ -48,6 +48,7 @@ describe("empty config", () => {
expect(storedCluster.id).toBe("foo"); expect(storedCluster.id).toBe("foo");
expect(storedCluster.preferences.terminalCWD).toBe("/tmp"); expect(storedCluster.preferences.terminalCWD).toBe("/tmp");
expect(storedCluster.preferences.icon).toBe("data:image/jpeg;base64, iVBORw0KGgoAAAANSUhEUgAAA1wAAAKoCAYAAABjkf5"); expect(storedCluster.preferences.icon).toBe("data:image/jpeg;base64, iVBORw0KGgoAAAANSUhEUgAAA1wAAAKoCAYAAABjkf5");
expect(storedCluster.enabled).toBe(true);
}); });
it("adds cluster to default workspace", () => { it("adds cluster to default workspace", () => {
@ -170,7 +171,8 @@ describe("config with existing clusters", () => {
kubeConfig: "foo", kubeConfig: "foo",
contextName: "foo", contextName: "foo",
preferences: { terminalCWD: "/foo" }, preferences: { terminalCWD: "/foo" },
workspace: "foo" workspace: "foo",
ownerRef: "foo"
}, },
] ]
}) })
@ -208,6 +210,12 @@ describe("config with existing clusters", () => {
expect(storedClusters[1].preferences.terminalCWD).toBe("/foo2"); expect(storedClusters[1].preferences.terminalCWD).toBe("/foo2");
expect(storedClusters[2].id).toBe("cluster3"); expect(storedClusters[2].id).toBe("cluster3");
}); });
it("marks owned cluster disabled by default", () => {
const storedClusters = clusterStore.clustersList;
expect(storedClusters[0].enabled).toBe(true);
expect(storedClusters[2].enabled).toBe(false);
});
}); });
describe("pre 2.0 config with an existing cluster", () => { describe("pre 2.0 config with an existing cluster", () => {

View File

@ -6,6 +6,13 @@ jest.mock("electron", () => {
getVersion: () => "99.99.99", getVersion: () => "99.99.99",
getPath: () => "tmp", getPath: () => "tmp",
getLocale: () => "en" getLocale: () => "en"
},
ipcRenderer: {
invoke: jest.fn(),
on: jest.fn()
},
ipcMain: {
handle: jest.fn()
} }
}; };
}); });
@ -60,7 +67,9 @@ describe("workspace store tests", () => {
name: "foobar", name: "foobar",
})); }));
expect(ws.getById("123").name).toBe("foobar"); const workspace = ws.getById("123");
expect(workspace.name).toBe("foobar");
expect(workspace.enabled).toBe(true);
}); });
it("cannot set a non-existent workspace to be active", () => { it("cannot set a non-existent workspace to be active", () => {

View File

@ -205,6 +205,7 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
if (!(model instanceof Cluster)) { if (!(model instanceof Cluster)) {
cluster = new Cluster(model); cluster = new Cluster(model);
} }
cluster.enabled = true;
this.clusters.set(model.id, cluster); this.clusters.set(model.id, cluster);
return cluster; return cluster;
} }

View File

@ -3,7 +3,7 @@ import { action, computed, observable, toJS, reaction } from "mobx";
import { BaseStore } from "./base-store"; import { BaseStore } from "./base-store";
import { clusterStore } from "./cluster-store"; import { clusterStore } from "./cluster-store";
import { appEventBus } from "./event-bus"; import { appEventBus } from "./event-bus";
import { broadcastMessage } from "../common/ipc"; import { broadcastMessage, handleRequest, requestMain } from "../common/ipc";
import logger from "../main/logger"; import logger from "../main/logger";
import type { ClusterId } from "./cluster-store"; import type { ClusterId } from "./cluster-store";
@ -77,16 +77,34 @@ export class Workspace implements WorkspaceModel, WorkspaceState {
export class WorkspaceStore extends BaseStore<WorkspaceStoreModel> { export class WorkspaceStore extends BaseStore<WorkspaceStoreModel> {
static readonly defaultId: WorkspaceId = "default"; static readonly defaultId: WorkspaceId = "default";
private stateRequestChannel = "workspace:states";
private constructor() { private constructor() {
super({ super({
configName: "lens-workspace-store", configName: "lens-workspace-store",
}); });
}
if (!ipcRenderer) { async load() {
setInterval(() => { await super.load();
this.pushState(); if (ipcRenderer) {
}, 5000); logger.info("[WORKSPACE-STORE] requesting initial state sync");
await requestMain(this.stateRequestChannel, (states: Map<string, WorkspaceState>) => {
states.forEach((state, id) => {
const workspace = this.getById(id);
if (workspace) {
workspace.setState(state);
}
});
});
} else {
handleRequest(this.stateRequestChannel, (): Map<string, WorkspaceState> => {
const states = new Map<string, WorkspaceState>();
this.workspacesList.forEach((workspace) => {
states.set(workspace.id, workspace.getState());
});
return states;
});
} }
} }
@ -157,6 +175,7 @@ export class WorkspaceStore extends BaseStore<WorkspaceStoreModel> {
return; return;
} }
this.workspaces.set(id, workspace); this.workspaces.set(id, workspace);
workspace.enabled = true;
appEventBus.emit({name: "workspace", action: "add"}); appEventBus.emit({name: "workspace", action: "add"});
return workspace; return workspace;
} }

View File

@ -21,7 +21,7 @@ export class Workspaces extends React.Component {
@computed get workspaces(): Workspace[] { @computed get workspaces(): Workspace[] {
const currentWorkspaces: Map<WorkspaceId, Workspace> = new Map(); const currentWorkspaces: Map<WorkspaceId, Workspace> = new Map();
workspaceStore.workspacesList.forEach((w) => { workspaceStore.enabledWorkspacesList.forEach((w) => {
currentWorkspaces.set(w.id, w); currentWorkspaces.set(w.id, w);
}); });
const allWorkspaces = new Map([ const allWorkspaces = new Map([

View File

@ -106,7 +106,7 @@ export class ClustersMenu extends React.Component<Props> {
const { className } = this.props; const { className } = this.props;
const { newContexts } = userStore; const { newContexts } = userStore;
const workspace = workspaceStore.getById(workspaceStore.currentWorkspaceId); const workspace = workspaceStore.getById(workspaceStore.currentWorkspaceId);
const clusters = clusterStore.getByWorkspaceId(workspace.id); const clusters = clusterStore.getByWorkspaceId(workspace.id).filter(cluster => cluster.enabled === true);
const activeClusterId = clusterStore.activeCluster; const activeClusterId = clusterStore.activeCluster;
return ( return (
<div className={cssNames("ClustersMenu flex column", className)}> <div className={cssNames("ClustersMenu flex column", className)}>