diff --git a/src/extensions/renderer-api/components.ts b/src/extensions/renderer-api/components.ts index a9a519498b..6e2caaf5a6 100644 --- a/src/extensions/renderer-api/components.ts +++ b/src/extensions/renderer-api/components.ts @@ -13,6 +13,9 @@ export * from "../../renderer/components/select"; export * from "../../renderer/components/slider"; export * from "../../renderer/components/input/input"; +// command-overlay +export { CommandOverlay } from "../../renderer/components/command-palette"; + // other components export * from "../../renderer/components/icon"; export * from "../../renderer/components/tooltip"; diff --git a/src/renderer/components/+apps/apps.command.ts b/src/renderer/components/+apps/apps.command.ts new file mode 100644 index 0000000000..ff6c9d615d --- /dev/null +++ b/src/renderer/components/+apps/apps.command.ts @@ -0,0 +1,18 @@ +import { navigate } from "../../navigation"; +import { commandRegistry } from "../../../extensions/registries/command-registry"; +import { helmChartsURL } from "../+apps-helm-charts"; +import { releaseURL } from "../+apps-releases"; + +commandRegistry.add({ + id: "cluster.viewHelmCharts", + title: "Cluster: View Helm Charts", + scope: "cluster", + action: () => navigate(helmChartsURL()) +}); + +commandRegistry.add({ + id: "cluster.viewHelmReleases", + title: "Cluster: View Helm Releases", + scope: "cluster", + action: () => navigate(releaseURL()) +}); diff --git a/src/renderer/components/+apps/index.ts b/src/renderer/components/+apps/index.ts index 70c0169777..30fbf65316 100644 --- a/src/renderer/components/+apps/index.ts +++ b/src/renderer/components/+apps/index.ts @@ -1,2 +1,3 @@ export * from "./apps"; -export * from "./apps.route"; \ No newline at end of file +export * from "./apps.route"; +export * from "./apps.command"; diff --git a/src/renderer/components/+cluster-settings/cluster-settings.command.ts b/src/renderer/components/+cluster-settings/cluster-settings.command.ts new file mode 100644 index 0000000000..a3b3c8792e --- /dev/null +++ b/src/renderer/components/+cluster-settings/cluster-settings.command.ts @@ -0,0 +1,16 @@ +import { navigate } from "../../navigation"; +import { commandRegistry } from "../../../extensions/registries/command-registry"; +import { clusterSettingsURL } from "./cluster-settings.route"; +import { clusterStore } from "../../../common/cluster-store"; + +commandRegistry.add({ + id: "cluster.viewCurrentClusterSettings", + title: "Cluster: View Settings", + scope: "global", + action: () => navigate(clusterSettingsURL({ + params: { + clusterId: clusterStore.active.id + } + })), + isActive: (context) => !!context.cluster +}); diff --git a/src/renderer/components/+cluster-settings/index.ts b/src/renderer/components/+cluster-settings/index.ts index edab795e29..b83e440d53 100644 --- a/src/renderer/components/+cluster-settings/index.ts +++ b/src/renderer/components/+cluster-settings/index.ts @@ -1,2 +1,3 @@ export * from "./cluster-settings.route"; export * from "./cluster-settings"; +export * from "./cluster-settings.command"; diff --git a/src/renderer/components/+config/config.command.ts b/src/renderer/components/+config/config.command.ts new file mode 100644 index 0000000000..b709e6e9cd --- /dev/null +++ b/src/renderer/components/+config/config.command.ts @@ -0,0 +1,50 @@ +import { navigate } from "../../navigation"; +import { commandRegistry } from "../../../extensions/registries/command-registry"; +import { configMapsURL } from "../+config-maps"; +import { secretsURL } from "../+config-secrets"; +import { resourceQuotaURL } from "../+config-resource-quotas"; +import { limitRangeURL } from "../+config-limit-ranges"; +import { hpaURL } from "../+config-autoscalers"; +import { pdbURL } from "../+config-pod-disruption-budgets"; + +commandRegistry.add({ + id: "cluster.viewConfigMaps", + title: "Cluster: View ConfigMaps", + scope: "cluster", + action: () => navigate(configMapsURL()) +}); + +commandRegistry.add({ + id: "cluster.viewSecrets", + title: "Cluster: View Secrets", + scope: "cluster", + action: () => navigate(secretsURL()) +}); + +commandRegistry.add({ + id: "cluster.viewResourceQuotas", + title: "Cluster: View ResourceQuotas", + scope: "cluster", + action: () => navigate(resourceQuotaURL()) +}); + +commandRegistry.add({ + id: "cluster.viewLimitRanges", + title: "Cluster: View LimitRanges", + scope: "cluster", + action: () => navigate(limitRangeURL()) +}); + +commandRegistry.add({ + id: "cluster.viewHorizontalPodAutoscalers", + title: "Cluster: View HorizontalPodAutoscalers (HPA)", + scope: "cluster", + action: () => navigate(hpaURL()) +}); + +commandRegistry.add({ + id: "cluster.viewPodDisruptionBudget", + title: "Cluster: View PodDisruptionBudgets", + scope: "cluster", + action: () => navigate(pdbURL()) +}); diff --git a/src/renderer/components/+config/index.ts b/src/renderer/components/+config/index.ts index dba36b66d6..bfc04ecbe6 100644 --- a/src/renderer/components/+config/index.ts +++ b/src/renderer/components/+config/index.ts @@ -1,2 +1,3 @@ export * from "./config.route"; export * from "./config"; +export * from "./config.command"; diff --git a/src/renderer/components/+network/index.ts b/src/renderer/components/+network/index.ts index 9a58dc59a6..e37b11c3b7 100644 --- a/src/renderer/components/+network/index.ts +++ b/src/renderer/components/+network/index.ts @@ -1,2 +1,3 @@ export * from "./network.route"; export * from "./network"; +export * from "./network.command"; diff --git a/src/renderer/components/+network/network.command.ts b/src/renderer/components/+network/network.command.ts new file mode 100644 index 0000000000..6dfa907136 --- /dev/null +++ b/src/renderer/components/+network/network.command.ts @@ -0,0 +1,34 @@ +import { navigate } from "../../navigation"; +import { commandRegistry } from "../../../extensions/registries/command-registry"; +import { servicesURL } from "../+network-services"; +import { endpointURL } from "../+network-endpoints"; +import { ingressURL } from "../+network-ingresses"; +import { networkPoliciesURL } from "../+network-policies"; + +commandRegistry.add({ + id: "cluster.viewServices", + title: "Cluster: View Services", + scope: "cluster", + action: () => navigate(servicesURL()) +}); + +commandRegistry.add({ + id: "cluster.viewEndpoints", + title: "Cluster: View Endpoints", + scope: "cluster", + action: () => navigate(endpointURL()) +}); + +commandRegistry.add({ + id: "cluster.viewIngresses", + title: "Cluster: View Ingresses", + scope: "cluster", + action: () => navigate(ingressURL()) +}); + +commandRegistry.add({ + id: "cluster.viewNetworkPolicies", + title: "Cluster: View NetworkPolicies", + scope: "cluster", + action: () => navigate(networkPoliciesURL()) +}); diff --git a/src/renderer/components/+nodes/index.ts b/src/renderer/components/+nodes/index.ts index 515a3d85f6..8af90267d4 100644 --- a/src/renderer/components/+nodes/index.ts +++ b/src/renderer/components/+nodes/index.ts @@ -1,3 +1,4 @@ export * from "./nodes"; export * from "./nodes.route"; export * from "./node-details"; +export * from "./node.command"; diff --git a/src/renderer/components/+nodes/node.command.ts b/src/renderer/components/+nodes/node.command.ts new file mode 100644 index 0000000000..9257cea668 --- /dev/null +++ b/src/renderer/components/+nodes/node.command.ts @@ -0,0 +1,10 @@ +import { navigate } from "../../navigation"; +import { commandRegistry } from "../../../extensions/registries/command-registry"; +import { nodesURL } from "./nodes.route"; + +commandRegistry.add({ + id: "cluster.viewNodes", + title: "Cluster: View Nodes", + scope: "cluster", + action: () => navigate(nodesURL()) +}); diff --git a/src/renderer/components/+workloads/index.ts b/src/renderer/components/+workloads/index.ts index a6e1904b84..7e40e91f98 100644 --- a/src/renderer/components/+workloads/index.ts +++ b/src/renderer/components/+workloads/index.ts @@ -1,3 +1,4 @@ export * from "./workloads.route"; export * from "./workloads"; export * from "./workloads.stores"; +export * from "./workloads.command"; diff --git a/src/renderer/components/+workloads/workloads.command.ts b/src/renderer/components/+workloads/workloads.command.ts new file mode 100644 index 0000000000..02b5e42657 --- /dev/null +++ b/src/renderer/components/+workloads/workloads.command.ts @@ -0,0 +1,45 @@ +import { navigate } from "../../navigation"; +import { commandRegistry } from "../../../extensions/registries/command-registry"; +import { cronJobsURL, daemonSetsURL, deploymentsURL, jobsURL, podsURL, statefulSetsURL } from "./workloads.route"; + +commandRegistry.add({ + id: "cluster.viewPods", + title: "Cluster: View Pods", + scope: "cluster", + action: () => navigate(podsURL()) +}); + +commandRegistry.add({ + id: "cluster.viewDeployments", + title: "Cluster: View Deployments", + scope: "cluster", + action: () => navigate(deploymentsURL()) +}); + +commandRegistry.add({ + id: "cluster.viewDaemonSets", + title: "Cluster: View DaemonSets", + scope: "cluster", + action: () => navigate(daemonSetsURL()) +}); + +commandRegistry.add({ + id: "cluster.viewStatefulSets", + title: "Cluster: View StatefulSets", + scope: "cluster", + action: () => navigate(statefulSetsURL()) +}); + +commandRegistry.add({ + id: "cluster.viewJobs", + title: "Cluster: View Jobs", + scope: "cluster", + action: () => navigate(jobsURL()) +}); + +commandRegistry.add({ + id: "cluster.viewCronJobs", + title: "Cluster: View CronJobs", + scope: "cluster", + action: () => navigate(cronJobsURL()) +}); diff --git a/src/renderer/components/+workloads/workloads.route.ts b/src/renderer/components/+workloads/workloads.route.ts index 38814d3fc6..9ca43522aa 100644 --- a/src/renderer/components/+workloads/workloads.route.ts +++ b/src/renderer/components/+workloads/workloads.route.ts @@ -1,9 +1,7 @@ import type { RouteProps } from "react-router"; import { buildURL, IURLParams } from "../../../common/utils/buildUrl"; -import { isAllowedResource, KubeResource } from "../../../common/rbac"; +import { KubeResource } from "../../../common/rbac"; import { Workloads } from "./workloads"; -import { navigate } from "../../navigation"; -import { commandRegistry } from "../../../extensions/registries/command-registry"; export const workloadsRoute: RouteProps = { get path() { @@ -83,30 +81,4 @@ export const workloadURL: Partial navigate(podsURL()) -}); -commandRegistry.add({ - id: "cluster.viewDeployments", - title: "Cluster: View Deployments", - scope: "cluster", - action: () => navigate(deploymentsURL()) -}); - -commandRegistry.add({ - id: "cluster.viewDaemonSets", - title: "Cluster: View DaemonSets", - scope: "cluster", - action: () => navigate(daemonSetsURL()) -}); - -commandRegistry.add({ - id: "cluster.viewStatefulSets", - title: "Cluster: View StatefulSets", - scope: "cluster", - action: () => navigate(statefulSetsURL()) -}); diff --git a/src/renderer/components/+workspaces/add-workspace.tsx b/src/renderer/components/+workspaces/add-workspace.tsx index a7b24804e4..3491a05e7e 100644 --- a/src/renderer/components/+workspaces/add-workspace.tsx +++ b/src/renderer/components/+workspaces/add-workspace.tsx @@ -5,7 +5,7 @@ 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"; +import { CommandOverlay } from "../command-palette/command-container"; const uniqueWorkspaceName: InputValidator = { condition: ({ required }) => required, @@ -15,7 +15,7 @@ const uniqueWorkspaceName: InputValidator = { @observer export class AddWorkspace extends React.Component { - handleKeyDown(name: string) { + onSubmit(name: string) { if (name.trim() === "") { return; } @@ -26,7 +26,7 @@ export class AddWorkspace extends React.Component { workspaceStore.setActive(workspace.id); navigate("/"); - closeCommandDialog(); + CommandOverlay.close(); } render() { @@ -37,7 +37,7 @@ export class AddWorkspace extends React.Component { autoFocus={true} theme="round-black" validators={[uniqueWorkspaceName]} - onSubmit={(v) => this.handleKeyDown(v)} + onSubmit={(v) => this.onSubmit(v)} dirty={true} showValidationLine={true} /> @@ -52,5 +52,5 @@ commandRegistry.add({ id: "workspace.addWorkspace", title: "Workspace: Add workspace ...", scope: "global", - action: () => openCommandDialog() + action: () => CommandOverlay.open() }); diff --git a/src/renderer/components/+workspaces/remove-workspace.tsx b/src/renderer/components/+workspaces/remove-workspace.tsx index ac25dc55b9..7e7fc4c6d4 100644 --- a/src/renderer/components/+workspaces/remove-workspace.tsx +++ b/src/renderer/components/+workspaces/remove-workspace.tsx @@ -5,7 +5,7 @@ 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"; +import { CommandOverlay } from "../command-palette/command-container"; @observer export class RemoveWorkspace extends React.Component { @@ -22,7 +22,7 @@ export class RemoveWorkspace extends React.Component { return; } - closeCommandDialog(); + CommandOverlay.close(); ConfirmDialog.open({ okButtonProps: { label: `Remove Workspace`, @@ -67,5 +67,5 @@ commandRegistry.add({ id: "workspace.removeWorkspace", title: "Workspace: Remove workspace ...", scope: "global", - action: () => openCommandDialog() + action: () => CommandOverlay.open() }); diff --git a/src/renderer/components/+workspaces/workspaces.tsx b/src/renderer/components/+workspaces/workspaces.tsx index 0a64132e13..b5a1f2389b 100644 --- a/src/renderer/components/+workspaces/workspaces.tsx +++ b/src/renderer/components/+workspaces/workspaces.tsx @@ -5,7 +5,7 @@ import { workspaceStore } from "../../../common/workspace-store"; import { commandRegistry } from "../../../extensions/registries/command-registry"; import { Select } from "../select"; import { navigate } from "../../navigation"; -import { closeCommandDialog, openCommandDialog } from "../command-palette/command-container"; +import { CommandOverlay } from "../command-palette/command-container"; import { AddWorkspace } from "./add-workspace"; import { RemoveWorkspace } from "./remove-workspace"; @@ -30,20 +30,20 @@ export class ChooseWorkspace extends React.Component { onChange(id: string) { if (id === ChooseWorkspace.addActionId) { - openCommandDialog(); + CommandOverlay.open(); return; } if (id === ChooseWorkspace.removeActionId) { - openCommandDialog(); + CommandOverlay.open(); return; } workspaceStore.setActive(id); navigate("/"); - closeCommandDialog(); + CommandOverlay.close(); } render() { @@ -66,5 +66,5 @@ commandRegistry.add({ id: "workspace.chooseWorkspace", title: "Workspace: Switch to workspace ...", scope: "global", - action: () => openCommandDialog() + action: () => CommandOverlay.open() }); diff --git a/src/renderer/components/cluster-manager/bottom-bar.tsx b/src/renderer/components/cluster-manager/bottom-bar.tsx index 3429f7600f..28d1f83106 100644 --- a/src/renderer/components/cluster-manager/bottom-bar.tsx +++ b/src/renderer/components/cluster-manager/bottom-bar.tsx @@ -5,7 +5,7 @@ import { observer } from "mobx-react"; import { Icon } from "../icon"; import { workspaceStore } from "../../../common/workspace-store"; import { statusBarRegistry } from "../../../extensions/registries"; -import { openCommandDialog } from "../command-palette/command-container"; +import { CommandOverlay } from "../command-palette/command-container"; import { ChooseWorkspace } from "../+workspaces"; @observer @@ -17,7 +17,7 @@ export class BottomBar extends React.Component { return (
-
openCommandDialog()}> +
CommandOverlay.open()}> {currentWorkspace.name}
diff --git a/src/renderer/components/cluster-manager/clusters-menu.tsx b/src/renderer/components/cluster-manager/clusters-menu.tsx index 2118988426..d963438136 100644 --- a/src/renderer/components/cluster-manager/clusters-menu.tsx +++ b/src/renderer/components/cluster-manager/clusters-menu.tsx @@ -23,7 +23,7 @@ import { clusterViewURL } from "./cluster-view.route"; import { getExtensionPageUrl, globalPageMenuRegistry, globalPageRegistry } from "../../../extensions/registries"; import { clusterDisconnectHandler } from "../../../common/cluster-ipc"; import { commandRegistry } from "../../../extensions/registries/command-registry"; -import { closeCommandDialog, openCommandDialog } from "../command-palette/command-container"; +import { CommandOverlay } from "../command-palette/command-container"; import { computed } from "mobx"; import { Select } from "../select"; @@ -196,7 +196,7 @@ export class ChooseCluster extends React.Component { onChange(clusterId: string) { navigate(clusterViewURL({ params: { clusterId } })); - closeCommandDialog(); + CommandOverlay.close(); } render() { @@ -218,5 +218,5 @@ commandRegistry.add({ id: "workspace.chooseCluster", title: "Workspace: Switch to cluster ...", scope: "global", - action: () => openCommandDialog() + action: () => CommandOverlay.open() }); diff --git a/src/renderer/components/command-palette/command-container.tsx b/src/renderer/components/command-palette/command-container.tsx index 701170d79b..9c34ef8c93 100644 --- a/src/renderer/components/command-palette/command-container.tsx +++ b/src/renderer/components/command-palette/command-container.tsx @@ -18,12 +18,14 @@ export type CommandDialogEvent = { const commandDialogBus = new EventEmitter<[CommandDialogEvent]>(); -export function openCommandDialog(component: React.ReactElement) { - commandDialogBus.emit({ component }); -} +export class CommandOverlay { + static open(component: React.ReactElement) { + commandDialogBus.emit({ component }); + } -export function closeCommandDialog() { - commandDialogBus.emit({ component: null }); + static close() { + commandDialogBus.emit({ component: null }); + } } @observer @@ -74,7 +76,7 @@ export class CommandContainer extends React.Component<{cluster?: Cluster}> { }); } else { subscribeToBroadcast("command-palette:open", () => { - openCommandDialog(); + CommandOverlay.open(); }); } window.addEventListener("keyup", (e) => this.escHandler(e), true); diff --git a/src/renderer/components/command-palette/command-dialog.tsx b/src/renderer/components/command-palette/command-dialog.tsx index b377442d56..ac9c3cb358 100644 --- a/src/renderer/components/command-palette/command-dialog.tsx +++ b/src/renderer/components/command-palette/command-dialog.tsx @@ -6,7 +6,7 @@ import React from "react"; import { commandRegistry } from "../../../extensions/registries/command-registry"; import { clusterStore } from "../../../common/cluster-store"; import { workspaceStore } from "../../../common/workspace-store"; -import { closeCommandDialog } from "./command-container"; +import { CommandOverlay } from "./command-container"; import { broadcastMessage } from "../../../common/ipc"; @observer @@ -50,7 +50,7 @@ export class CommandDialog extends React.Component { const action = toJS(command.action); try { - closeCommandDialog(); + CommandOverlay.close(); if (command.scope === "global") { action({ diff --git a/src/renderer/components/command-palette/index.ts b/src/renderer/components/command-palette/index.ts new file mode 100644 index 0000000000..c01da0f7b6 --- /dev/null +++ b/src/renderer/components/command-palette/index.ts @@ -0,0 +1,2 @@ +export * from "./command-container"; +export * from "./command-dialog";