mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
implement workspace edit
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
parent
3e51d8d32a
commit
1307ea50fd
@ -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 () => {
|
||||
|
||||
81
src/renderer/components/+workspaces/edit-workspace.tsx
Normal file
81
src/renderer/components/+workspaces/edit-workspace.tsx
Normal file
@ -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 (
|
||||
<>
|
||||
<Input
|
||||
placeholder="Workspace name"
|
||||
autoFocus={true}
|
||||
theme="round-black"
|
||||
data-test-id="command-palette-workspace-add-name"
|
||||
validators={[validateWorkspaceName]}
|
||||
onChange={(v) => this.onChange(v)}
|
||||
onSubmit={(v) => this.onSubmit(v)}
|
||||
dirty={true}
|
||||
value={this.name}
|
||||
showValidationLine={true} />
|
||||
<small className="hint">
|
||||
Please provide a new workspace name (Press "Enter" to confirm or "Escape" to cancel)
|
||||
</small>
|
||||
</>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
commandRegistry.add({
|
||||
id: "workspace.editCurrentWorkspace",
|
||||
title: "Workspace: Edit current workspace...",
|
||||
scope: "global",
|
||||
action: () => CommandOverlay.open(<EditWorkspace />)
|
||||
});
|
||||
@ -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(<EditWorkspace />);
|
||||
|
||||
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 ...",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user