diff --git a/src/extensions/registries/command-registry.ts b/src/extensions/registries/command-registry.ts index 359702c29f..258f856b9c 100644 --- a/src/extensions/registries/command-registry.ts +++ b/src/extensions/registries/command-registry.ts @@ -12,6 +12,7 @@ export type CommandContext = { export interface CommandRegistration { id: string; title: string; + scope: "cluster" | "global"; action: (context: CommandContext) => void; isActive?: (context: CommandContext) => boolean; } diff --git a/src/renderer/components/+preferences/preferences.route.ts b/src/renderer/components/+preferences/preferences.route.ts index 6937ecb0dd..2915b68a28 100644 --- a/src/renderer/components/+preferences/preferences.route.ts +++ b/src/renderer/components/+preferences/preferences.route.ts @@ -12,5 +12,6 @@ export const preferencesURL = buildURL(preferencesRoute.path); commandRegistry.add({ id: "app.showPreferences", title: "Preferences: Open", - action: () => navigate(preferencesURL.toString()) + scope: "global", + action: () => navigate(preferencesURL()) }); diff --git a/src/renderer/components/+workspaces/add-workspace.tsx b/src/renderer/components/+workspaces/add-workspace.tsx new file mode 100644 index 0000000000..a7b24804e4 --- /dev/null +++ b/src/renderer/components/+workspaces/add-workspace.tsx @@ -0,0 +1,56 @@ +import React from "react"; +import { observer } from "mobx-react"; +import { Workspace, workspaceStore } from "../../../common/workspace-store"; +import { v4 as uuid } from "uuid"; +import { commandRegistry } from "../../../extensions/registries/command-registry"; +import { Input, InputValidator } from "../input"; +import { navigate } from "../../navigation"; +import { closeCommandDialog, openCommandDialog } from "../command-palette/command-container"; + +const uniqueWorkspaceName: InputValidator = { + condition: ({ required }) => required, + message: () => `Workspace with this name already exists`, + validate: value => !workspaceStore.enabledWorkspacesList.find((workspace) => workspace.name === value), +}; + +@observer +export class AddWorkspace extends React.Component { + handleKeyDown(name: string) { + if (name.trim() === "") { + return; + } + const workspace = workspaceStore.addWorkspace(new Workspace({ + id: uuid(), + name + })); + + workspaceStore.setActive(workspace.id); + navigate("/"); + closeCommandDialog(); + } + + render() { + return ( + <> + this.handleKeyDown(v)} + dirty={true} + showValidationLine={true} /> + + Please provide a new workspace name (Press "Enter" to confirm or "Escape" to cancel) + + + ); + } +} + +commandRegistry.add({ + id: "workspace.addWorkspace", + title: "Workspace: Add workspace ...", + scope: "global", + action: () => openCommandDialog() +}); diff --git a/src/renderer/components/+workspaces/index.ts b/src/renderer/components/+workspaces/index.ts index db23faa3be..5b84fc9b00 100644 --- a/src/renderer/components/+workspaces/index.ts +++ b/src/renderer/components/+workspaces/index.ts @@ -1,2 +1 @@ -export * from "./workspaces.route"; export * from "./workspaces"; diff --git a/src/renderer/components/+workspaces/remove-workspace.tsx b/src/renderer/components/+workspaces/remove-workspace.tsx new file mode 100644 index 0000000000..17119b4a82 --- /dev/null +++ b/src/renderer/components/+workspaces/remove-workspace.tsx @@ -0,0 +1,71 @@ +import React from "react"; +import { observer } from "mobx-react"; +import { computed} from "mobx"; +import { WorkspaceStore, workspaceStore } from "../../../common/workspace-store"; +import { ConfirmDialog } from "../confirm-dialog"; +import { commandRegistry } from "../../../extensions/registries/command-registry"; +import { Select } from "../select"; +import { closeCommandDialog, openCommandDialog } from "../command-palette/command-container"; + +@observer +export class RemoveWorkspace extends React.Component { + @computed get options() { + return workspaceStore.enabledWorkspacesList.filter((workspace) => workspace.id !== WorkspaceStore.defaultId).map((workspace) => { + return { value: workspace.id, label: workspace.name }; + }); + } + + onChange(id: string) { + const workspace = workspaceStore.enabledWorkspacesList.find((workspace) => workspace.id === id); + + if (!workspace ) { + return; + } + + closeCommandDialog(); + ConfirmDialog.open({ + okButtonProps: { + label: `Remove Workspace`, + primary: false, + accent: true, + }, + ok: () => { + workspaceStore.removeWorkspace(workspace); + + if (workspace.id === workspaceStore.currentWorkspaceId) { + workspaceStore.setActive(workspaceStore.enabledWorkspacesList[0].id); + } + }, + message: ( +
+

+ Are you sure you want remove workspace {workspace.name}? +

+

+ All clusters within workspace will be cleared as well +

+
+ ), + }); + } + + render() { + return ( + editingWorkspace.name = v} - onKeyPress={(e) => this.onInputKeypress(e, workspaceId)} - validators={[isRequired, existenceValidator]} - autoFocus - /> - editingWorkspace.description = v} - onKeyPress={(e) => this.onInputKeypress(e, workspaceId)} - /> - this.saveWorkspace(workspaceId)} - /> - this.clearEditing(workspaceId)} - /> - - )} - - ); - })} - -