diff --git a/integration/__tests__/workspace.tests.ts b/integration/__tests__/workspace.tests.ts
index da614b0cfb..b177cefe70 100644
--- a/integration/__tests__/workspace.tests.ts
+++ b/integration/__tests__/workspace.tests.ts
@@ -31,13 +31,29 @@ describe("Lens integration tests", () => {
await app.client.waitUntilTextExists("[data-test-id=current-workspace-name]", name);
};
- it("creates new workspace", async () => {
+ const createWorkspace = async (name: string) => {
await app.client.click("[data-test-id=current-workspace]");
await app.client.keys("add workspace");
await app.client.keys("Enter");
- await app.client.keys("test-workspace");
+ await app.client.keys(name);
await app.client.keys("Enter");
- await app.client.waitUntilTextExists("[data-test-id=current-workspace-name]", "test-workspace");
+ };
+
+ it("creates new workspace", async () => {
+ const name = "test-workspace";
+
+ await createWorkspace(name);
+ await app.client.waitUntilTextExists("[data-test-id=current-workspace-name]", name);
+ });
+
+ it("edits current workspaces", async () => {
+ await createWorkspace("to-be-edited");
+ await app.client.click("[data-test-id=current-workspace]");
+ await app.client.keys("edit current workspace");
+ await app.client.keys("Enter");
+ await app.client.keys("edited-workspace");
+ await app.client.keys("Enter");
+ await app.client.waitUntilTextExists("[data-test-id=current-workspace-name]", "edited-workspace");
});
it("adds cluster in default workspace", async () => {
diff --git a/src/renderer/components/+workspaces/edit-workspace.tsx b/src/renderer/components/+workspaces/edit-workspace.tsx
new file mode 100644
index 0000000000..0e9dce01f4
--- /dev/null
+++ b/src/renderer/components/+workspaces/edit-workspace.tsx
@@ -0,0 +1,81 @@
+import React from "react";
+import { observer } from "mobx-react";
+import { workspaceStore } from "../../../common/workspace-store";
+import { commandRegistry } from "../../../extensions/registries/command-registry";
+import { Input, InputValidator } from "../input";
+import { CommandOverlay } from "../command-palette/command-container";
+
+const validateWorkspaceName: InputValidator = {
+ condition: ({ required }) => required,
+ message: () => `Workspace with this name already exists`,
+ validate: (value) => {
+ const current = workspaceStore.currentWorkspace;
+
+ if (current.name === value.trim()) {
+ return true;
+ }
+
+ return !workspaceStore.enabledWorkspacesList.find((workspace) => workspace.name === value);
+ }
+};
+
+interface EditWorkspaceState {
+ name: string;
+}
+
+@observer
+export class EditWorkspace extends React.Component<{}, EditWorkspaceState> {
+
+ state: EditWorkspaceState = {
+ name: ""
+ };
+
+ componentDidMount() {
+ this.setState({name: workspaceStore.currentWorkspace.name});
+ }
+
+ onSubmit(name: string) {
+ if (name.trim() === "") {
+ return;
+ }
+
+ workspaceStore.currentWorkspace.name = name;
+ CommandOverlay.close();
+ }
+
+ onChange(name: string) {
+ this.setState({name});
+ }
+
+ get name() {
+ return this.state.name;
+ }
+
+ render() {
+ return (
+ <>
+ this.onChange(v)}
+ onSubmit={(v) => this.onSubmit(v)}
+ dirty={true}
+ value={this.name}
+ showValidationLine={true} />
+
+ Please provide a new workspace name (Press "Enter" to confirm or "Escape" to cancel)
+
+ >
+ );
+ }
+}
+
+commandRegistry.add({
+ id: "workspace.editCurrentWorkspace",
+ title: "Workspace: Edit current workspace...",
+ scope: "global",
+ action: () => CommandOverlay.open()
+});
diff --git a/src/renderer/components/+workspaces/workspaces.tsx b/src/renderer/components/+workspaces/workspaces.tsx
index b5a1f2389b..4f3e3a7d4b 100644
--- a/src/renderer/components/+workspaces/workspaces.tsx
+++ b/src/renderer/components/+workspaces/workspaces.tsx
@@ -8,11 +8,13 @@ import { navigate } from "../../navigation";
import { CommandOverlay } from "../command-palette/command-container";
import { AddWorkspace } from "./add-workspace";
import { RemoveWorkspace } from "./remove-workspace";
+import { EditWorkspace } from "./edit-workspace";
@observer
export class ChooseWorkspace extends React.Component {
private static addActionId = "__add__";
private static removeActionId = "__remove__";
+ private static editActionId = "__edit__";
@computed get options() {
const options = workspaceStore.enabledWorkspacesList.map((workspace) => {
@@ -41,6 +43,12 @@ export class ChooseWorkspace extends React.Component {
return;
}
+ if (id === ChooseWorkspace.editActionId) {
+ CommandOverlay.open();
+
+ return;
+ }
+
workspaceStore.setActive(id);
navigate("/");
CommandOverlay.close();
@@ -60,8 +68,6 @@ export class ChooseWorkspace extends React.Component {
}
}
-
-
commandRegistry.add({
id: "workspace.chooseWorkspace",
title: "Workspace: Switch to workspace ...",