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:
parent
07e6df9fdc
commit
3bd484f92a
@ -48,6 +48,7 @@ describe("empty config", () => {
|
||||
expect(storedCluster.id).toBe("foo");
|
||||
expect(storedCluster.preferences.terminalCWD).toBe("/tmp");
|
||||
expect(storedCluster.preferences.icon).toBe("data:image/jpeg;base64, iVBORw0KGgoAAAANSUhEUgAAA1wAAAKoCAYAAABjkf5");
|
||||
expect(storedCluster.enabled).toBe(true);
|
||||
});
|
||||
|
||||
it("adds cluster to default workspace", () => {
|
||||
@ -170,7 +171,8 @@ describe("config with existing clusters", () => {
|
||||
kubeConfig: "foo",
|
||||
contextName: "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[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", () => {
|
||||
|
||||
@ -6,6 +6,13 @@ jest.mock("electron", () => {
|
||||
getVersion: () => "99.99.99",
|
||||
getPath: () => "tmp",
|
||||
getLocale: () => "en"
|
||||
},
|
||||
ipcRenderer: {
|
||||
invoke: jest.fn(),
|
||||
on: jest.fn()
|
||||
},
|
||||
ipcMain: {
|
||||
handle: jest.fn()
|
||||
}
|
||||
};
|
||||
});
|
||||
@ -60,7 +67,9 @@ describe("workspace store tests", () => {
|
||||
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", () => {
|
||||
|
||||
@ -205,6 +205,7 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
|
||||
if (!(model instanceof Cluster)) {
|
||||
cluster = new Cluster(model);
|
||||
}
|
||||
cluster.enabled = true;
|
||||
this.clusters.set(model.id, cluster);
|
||||
return cluster;
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@ import { action, computed, observable, toJS, reaction } from "mobx";
|
||||
import { BaseStore } from "./base-store";
|
||||
import { clusterStore } from "./cluster-store";
|
||||
import { appEventBus } from "./event-bus";
|
||||
import { broadcastMessage } from "../common/ipc";
|
||||
import { broadcastMessage, handleRequest, requestMain } from "../common/ipc";
|
||||
import logger from "../main/logger";
|
||||
import type { ClusterId } from "./cluster-store";
|
||||
|
||||
@ -77,16 +77,34 @@ export class Workspace implements WorkspaceModel, WorkspaceState {
|
||||
|
||||
export class WorkspaceStore extends BaseStore<WorkspaceStoreModel> {
|
||||
static readonly defaultId: WorkspaceId = "default";
|
||||
private stateRequestChannel = "workspace:states";
|
||||
|
||||
private constructor() {
|
||||
super({
|
||||
configName: "lens-workspace-store",
|
||||
});
|
||||
}
|
||||
|
||||
if (!ipcRenderer) {
|
||||
setInterval(() => {
|
||||
this.pushState();
|
||||
}, 5000);
|
||||
async load() {
|
||||
await super.load();
|
||||
if (ipcRenderer) {
|
||||
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;
|
||||
}
|
||||
this.workspaces.set(id, workspace);
|
||||
workspace.enabled = true;
|
||||
appEventBus.emit({name: "workspace", action: "add"});
|
||||
return workspace;
|
||||
}
|
||||
|
||||
@ -21,7 +21,7 @@ export class Workspaces extends React.Component {
|
||||
|
||||
@computed get workspaces(): Workspace[] {
|
||||
const currentWorkspaces: Map<WorkspaceId, Workspace> = new Map();
|
||||
workspaceStore.workspacesList.forEach((w) => {
|
||||
workspaceStore.enabledWorkspacesList.forEach((w) => {
|
||||
currentWorkspaces.set(w.id, w);
|
||||
});
|
||||
const allWorkspaces = new Map([
|
||||
|
||||
@ -106,7 +106,7 @@ export class ClustersMenu extends React.Component<Props> {
|
||||
const { className } = this.props;
|
||||
const { newContexts } = userStore;
|
||||
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;
|
||||
return (
|
||||
<div className={cssNames("ClustersMenu flex column", className)}>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user