mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Make all of Command* injectable, with some others too
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
abe90ad92a
commit
f8ae1149fb
44 files changed
+868
-753
No files matched your search
@@ -26,41 +26,43 @@ import React from "react";
|
||||
import { Dialog } from "../dialog";
|
||||
import { CommandDialog } from "./command-dialog";
|
||||
import type { ClusterId } from "../../../common/cluster-types";
|
||||
import { CommandOverlay } from "./command-overlay";
|
||||
import commandOverlayInjectable, { CommandOverlay } from "./command-overlay.injectable";
|
||||
import { isMac } from "../../../common/vars";
|
||||
import { catalogEntityRegistry } from "../../api/catalog-entity-registry";
|
||||
import { broadcastMessage, ipcRendererOn } from "../../../common/ipc";
|
||||
import { getMatchedClusterId } from "../../navigation";
|
||||
import type { Disposer } from "../../utils";
|
||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||
import windowAddEventListenerInjectable from "../../window/event-listener.injectable";
|
||||
|
||||
export interface CommandContainerProps {
|
||||
clusterId?: ClusterId;
|
||||
}
|
||||
|
||||
function addWindowEventListener<K extends keyof WindowEventMap>(type: K, listener: (this: Window, ev: WindowEventMap[K]) => any, options?: boolean | AddEventListenerOptions): Disposer {
|
||||
window.addEventListener(type, listener, options);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener(type, listener);
|
||||
};
|
||||
interface Dependencies {
|
||||
addWindowEventListener: <K extends keyof WindowEventMap>(type: K, listener: (this: Window, ev: WindowEventMap[K]) => any, options?: boolean | AddEventListenerOptions) => Disposer;
|
||||
commandOverlay: CommandOverlay,
|
||||
}
|
||||
|
||||
@observer
|
||||
export class CommandContainer extends React.Component<CommandContainerProps> {
|
||||
class NonInjectedCommandContainer extends React.Component<CommandContainerProps & Dependencies> {
|
||||
private escHandler(event: KeyboardEvent) {
|
||||
const { commandOverlay } = this.props;
|
||||
|
||||
if (event.key === "Escape") {
|
||||
event.stopPropagation();
|
||||
CommandOverlay.close();
|
||||
commandOverlay.close();
|
||||
}
|
||||
}
|
||||
|
||||
handleCommandPalette = () => {
|
||||
const { commandOverlay } = this.props;
|
||||
const clusterIsActive = getMatchedClusterId() !== undefined;
|
||||
|
||||
if (clusterIsActive) {
|
||||
broadcastMessage(`command-palette:${catalogEntityRegistry.activeEntity.getId()}:open`);
|
||||
} else {
|
||||
CommandOverlay.open(<CommandDialog />);
|
||||
commandOverlay.open(<CommandDialog />);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -75,11 +77,13 @@ export class CommandContainer extends React.Component<CommandContainerProps> {
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
const action = this.props.clusterId
|
||||
? () => CommandOverlay.open(<CommandDialog />)
|
||||
const { clusterId, addWindowEventListener, commandOverlay } = this.props;
|
||||
|
||||
const action = clusterId
|
||||
? () => commandOverlay.open(<CommandDialog />)
|
||||
: this.handleCommandPalette;
|
||||
const ipcChannel = this.props.clusterId
|
||||
? `command-palette:${this.props.clusterId}:open`
|
||||
const ipcChannel = clusterId
|
||||
? `command-palette:${clusterId}:open`
|
||||
: "command-palette:open";
|
||||
|
||||
disposeOnUnmount(this, [
|
||||
@@ -90,17 +94,27 @@ export class CommandContainer extends React.Component<CommandContainerProps> {
|
||||
}
|
||||
|
||||
render() {
|
||||
const { commandOverlay } = this.props;
|
||||
|
||||
return (
|
||||
<Dialog
|
||||
isOpen={CommandOverlay.isOpen}
|
||||
isOpen={commandOverlay.isOpen}
|
||||
animated={true}
|
||||
onClose={CommandOverlay.close}
|
||||
onClose={commandOverlay.close}
|
||||
modal={false}
|
||||
>
|
||||
<div id="command-container">
|
||||
{CommandOverlay.component}
|
||||
{commandOverlay.component}
|
||||
</div>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export const CommandContainer = withInjectables<Dependencies, CommandContainerProps>(NonInjectedCommandContainer, {
|
||||
getProps: (di, props) => ({
|
||||
addWindowEventListener: di.inject(windowAddEventListenerInjectable),
|
||||
commandOverlay: di.inject(commandOverlayInjectable),
|
||||
...props,
|
||||
}),
|
||||
});
|
||||
@@ -24,7 +24,7 @@ import { Select } from "../select";
|
||||
import type { IComputedValue } from "mobx";
|
||||
import { observer } from "mobx-react";
|
||||
import React, { useState } from "react";
|
||||
import { CommandOverlay } from "./command-overlay";
|
||||
import commandOverlayInjectable from "./command-overlay.injectable";
|
||||
import type { CatalogEntity } from "../../../common/catalog";
|
||||
import { navigate } from "../../navigation";
|
||||
import { broadcastMessage } from "../../../common/ipc";
|
||||
@@ -39,9 +39,10 @@ import { catalogEntityRegistry } from "../../api/catalog-entity-registry";
|
||||
interface Dependencies {
|
||||
commands: IComputedValue<Map<string, RegisteredCommand>>;
|
||||
activeEntity?: CatalogEntity;
|
||||
closeCommandOverlay: () => void;
|
||||
}
|
||||
|
||||
const NonInjectedCommandDialog = observer(({ commands, activeEntity }: Dependencies) => {
|
||||
const NonInjectedCommandDialog = observer(({ commands, activeEntity, closeCommandOverlay }: Dependencies) => {
|
||||
const [searchValue, setSearchValue] = useState("");
|
||||
|
||||
const executeAction = (commandId: string) => {
|
||||
@@ -52,7 +53,7 @@ const NonInjectedCommandDialog = observer(({ commands, activeEntity }: Dependenc
|
||||
}
|
||||
|
||||
try {
|
||||
CommandOverlay.close();
|
||||
closeCommandOverlay();
|
||||
command.action({
|
||||
entity: activeEntity,
|
||||
navigate: (url, opts = {}) => {
|
||||
@@ -121,5 +122,6 @@ export const CommandDialog = withInjectables<Dependencies>(NonInjectedCommandDia
|
||||
commands: di.inject(registeredCommandsInjectable),
|
||||
// TODO: replace with injection
|
||||
activeEntity: catalogEntityRegistry.activeEntity,
|
||||
closeCommandOverlay: di.inject(commandOverlayInjectable).close,
|
||||
}),
|
||||
});
|
||||
+19
-11
@@ -19,29 +19,37 @@
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
|
||||
import { observable } from "mobx";
|
||||
import React from "react";
|
||||
|
||||
export class CommandOverlay {
|
||||
static #component = observable.box<React.ReactElement | null>(null, { deep: false });
|
||||
#component = observable.box<React.ReactElement | null>(null, { deep: false });
|
||||
|
||||
static get isOpen(): boolean {
|
||||
return Boolean(CommandOverlay.#component.get());
|
||||
get isOpen(): boolean {
|
||||
return Boolean(this.#component.get());
|
||||
}
|
||||
|
||||
static open(component: React.ReactElement) {
|
||||
open = (component: React.ReactElement) => {
|
||||
if (!React.isValidElement(component)) {
|
||||
throw new TypeError("CommandOverlay.open must be passed a valid ReactElement");
|
||||
}
|
||||
|
||||
CommandOverlay.#component.set(component);
|
||||
}
|
||||
this.#component.set(component);
|
||||
};
|
||||
|
||||
static close() {
|
||||
CommandOverlay.#component.set(null);
|
||||
}
|
||||
close = () => {
|
||||
this.#component.set(null);
|
||||
};
|
||||
|
||||
static get component(): React.ReactElement | null {
|
||||
return CommandOverlay.#component.get();
|
||||
get component(): React.ReactElement | null {
|
||||
return this.#component.get();
|
||||
}
|
||||
}
|
||||
|
||||
const commandOverlayInjectable = getInjectable({
|
||||
instantiate: () => new CommandOverlay(),
|
||||
lifecycle: lifecycleEnum.singleton,
|
||||
});
|
||||
|
||||
export default commandOverlayInjectable;
|
||||
@@ -21,4 +21,4 @@
|
||||
|
||||
export * from "./command-container";
|
||||
export * from "./command-dialog";
|
||||
export * from "./command-overlay";
|
||||
export * from "./command-overlay.injectable";
|
||||
+231
@@ -0,0 +1,231 @@
|
||||
/**
|
||||
* Copyright (c) 2021 OpenLens Authors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import React from "react";
|
||||
import * as routes from "../../../../common/routes";
|
||||
import { EntitySettingRegistry, RegisteredEntitySetting } from "../../../../extensions/registries";
|
||||
import { createTerminalTab } from "../../dock/terminal.store";
|
||||
import { HotbarAddCommand } from "../../hotbar/hotbar-add-command";
|
||||
import { HotbarRemoveCommand } from "../../hotbar/hotbar-remove-command";
|
||||
import { HotbarSwitchCommand } from "../../hotbar/hotbar-switch-command";
|
||||
import { HotbarRenameCommand } from "../../hotbar/hotbar-rename-command";
|
||||
import { ActivateEntityCommand } from "../../activate-entity-command";
|
||||
import type { CommandContext, CommandRegistration } from "./commands";
|
||||
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
|
||||
import commandOverlayInjectable from "../command-overlay.injectable";
|
||||
|
||||
export function isKubernetesClusterActive(context: CommandContext): boolean {
|
||||
return context.entity?.kind === "KubernetesCluster";
|
||||
}
|
||||
|
||||
interface Dependencies {
|
||||
openCommandDialog: (component: React.ReactElement) => void;
|
||||
getEntitySettingItems: (kind: string, apiVersion: string, source?: string) => RegisteredEntitySetting[];
|
||||
}
|
||||
|
||||
function getInternalCommands({ openCommandDialog, getEntitySettingItems }: Dependencies): CommandRegistration[] {
|
||||
return [
|
||||
{
|
||||
id: "app.showPreferences",
|
||||
title: "Preferences: Open",
|
||||
action: ({ navigate }) => navigate(routes.preferencesURL(), {
|
||||
forceRootFrame: true,
|
||||
}),
|
||||
},
|
||||
{
|
||||
id: "cluster.viewHelmCharts",
|
||||
title: "Cluster: View Helm Charts",
|
||||
isActive: isKubernetesClusterActive,
|
||||
action: ({ navigate }) => navigate(routes.helmChartsURL()),
|
||||
},
|
||||
{
|
||||
id: "cluster.viewHelmReleases",
|
||||
title: "Cluster: View Helm Releases",
|
||||
isActive: isKubernetesClusterActive,
|
||||
action: ({ navigate }) => navigate(routes.releaseURL()),
|
||||
},
|
||||
{
|
||||
id: "cluster.viewConfigMaps",
|
||||
title: "Cluster: View ConfigMaps",
|
||||
isActive: isKubernetesClusterActive,
|
||||
action: ({ navigate }) => navigate(routes.configMapsURL()),
|
||||
},
|
||||
{
|
||||
id: "cluster.viewSecrets",
|
||||
title: "Cluster: View Secrets",
|
||||
isActive: isKubernetesClusterActive,
|
||||
action: ({ navigate }) => navigate(routes.secretsURL()),
|
||||
},
|
||||
{
|
||||
id: "cluster.viewResourceQuotas",
|
||||
title: "Cluster: View ResourceQuotas",
|
||||
isActive: isKubernetesClusterActive,
|
||||
action: ({ navigate }) => navigate(routes.resourceQuotaURL()),
|
||||
},
|
||||
{
|
||||
id: "cluster.viewLimitRanges",
|
||||
title: "Cluster: View LimitRanges",
|
||||
isActive: isKubernetesClusterActive,
|
||||
action: ({ navigate }) => navigate(routes.limitRangeURL()),
|
||||
},
|
||||
{
|
||||
id: "cluster.viewHorizontalPodAutoscalers",
|
||||
title: "Cluster: View HorizontalPodAutoscalers (HPA)",
|
||||
isActive: isKubernetesClusterActive,
|
||||
action: ({ navigate }) => navigate(routes.hpaURL()),
|
||||
},
|
||||
{
|
||||
id: "cluster.viewPodDisruptionBudget",
|
||||
title: "Cluster: View PodDisruptionBudgets",
|
||||
isActive: isKubernetesClusterActive,
|
||||
action: ({ navigate }) => navigate(routes.pdbURL()),
|
||||
},
|
||||
{
|
||||
id: "cluster.viewServices",
|
||||
title: "Cluster: View Services",
|
||||
isActive: isKubernetesClusterActive,
|
||||
action: ({ navigate }) => navigate(routes.servicesURL()),
|
||||
},
|
||||
{
|
||||
id: "cluster.viewEndpoints",
|
||||
title: "Cluster: View Endpoints",
|
||||
isActive: isKubernetesClusterActive,
|
||||
action: ({ navigate }) => navigate(routes.endpointURL()),
|
||||
},
|
||||
{
|
||||
id: "cluster.viewIngresses",
|
||||
title: "Cluster: View Ingresses",
|
||||
isActive: isKubernetesClusterActive,
|
||||
action: ({ navigate }) => navigate(routes.ingressURL()),
|
||||
},
|
||||
{
|
||||
id: "cluster.viewNetworkPolicies",
|
||||
title: "Cluster: View NetworkPolicies",
|
||||
isActive: isKubernetesClusterActive,
|
||||
action: ({ navigate }) => navigate(routes.networkPoliciesURL()),
|
||||
},
|
||||
{
|
||||
id: "cluster.viewNodes",
|
||||
title: "Cluster: View Nodes",
|
||||
isActive: isKubernetesClusterActive,
|
||||
action: ({ navigate }) => navigate(routes.nodesURL()),
|
||||
},
|
||||
{
|
||||
id: "cluster.viewPods",
|
||||
title: "Cluster: View Pods",
|
||||
isActive: isKubernetesClusterActive,
|
||||
action: ({ navigate }) => navigate(routes.podsURL()),
|
||||
},
|
||||
{
|
||||
id: "cluster.viewDeployments",
|
||||
title: "Cluster: View Deployments",
|
||||
isActive: isKubernetesClusterActive,
|
||||
action: ({ navigate }) => navigate(routes.deploymentsURL()),
|
||||
},
|
||||
{
|
||||
id: "cluster.viewDaemonSets",
|
||||
title: "Cluster: View DaemonSets",
|
||||
isActive: isKubernetesClusterActive,
|
||||
action: ({ navigate }) => navigate(routes.daemonSetsURL()),
|
||||
},
|
||||
{
|
||||
id: "cluster.viewStatefulSets",
|
||||
title: "Cluster: View StatefulSets",
|
||||
isActive: isKubernetesClusterActive,
|
||||
action: ({ navigate }) => navigate(routes.statefulSetsURL()),
|
||||
},
|
||||
{
|
||||
id: "cluster.viewJobs",
|
||||
title: "Cluster: View Jobs",
|
||||
isActive: isKubernetesClusterActive,
|
||||
action: ({ navigate }) => navigate(routes.jobsURL()),
|
||||
},
|
||||
{
|
||||
id: "cluster.viewCronJobs",
|
||||
title: "Cluster: View CronJobs",
|
||||
isActive: isKubernetesClusterActive,
|
||||
action: ({ navigate }) => navigate(routes.cronJobsURL()),
|
||||
},
|
||||
{
|
||||
id: "cluster.viewCustomResourceDefinitions",
|
||||
title: "Cluster: View Custom Resource Definitions",
|
||||
isActive: isKubernetesClusterActive,
|
||||
action: ({ navigate }) => navigate(routes.crdURL()),
|
||||
},
|
||||
{
|
||||
id: "entity.viewSettings",
|
||||
title: ({ entity }) => `${entity.kind}/${entity.getName()}: View Settings`,
|
||||
action: ({ entity, navigate }) => navigate(`/entity/${entity.getId()}/settings`, {
|
||||
forceRootFrame: true,
|
||||
}),
|
||||
isActive: ({ entity }) => {
|
||||
if (!entity) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return getEntitySettingItems(entity.kind, entity.apiVersion, entity.metadata.source).length > 0;
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "cluster.openTerminal",
|
||||
title: "Cluster: Open terminal",
|
||||
action: () => createTerminalTab(),
|
||||
isActive: isKubernetesClusterActive,
|
||||
},
|
||||
{
|
||||
id: "hotbar.switchHotbar",
|
||||
title: "Hotbar: Switch ...",
|
||||
action: () => openCommandDialog(<HotbarSwitchCommand />),
|
||||
},
|
||||
{
|
||||
id: "hotbar.addHotbar",
|
||||
title: "Hotbar: Add Hotbar ...",
|
||||
action: () => openCommandDialog(<HotbarAddCommand />),
|
||||
},
|
||||
{
|
||||
id: "hotbar.removeHotbar",
|
||||
title: "Hotbar: Remove Hotbar ...",
|
||||
action: () => openCommandDialog(<HotbarRemoveCommand />),
|
||||
},
|
||||
{
|
||||
id: "hotbar.renameHotbar",
|
||||
title: "Hotbar: Rename Hotbar ...",
|
||||
action: () => openCommandDialog(<HotbarRenameCommand />),
|
||||
},
|
||||
{
|
||||
id: "catalog.searchEntities",
|
||||
title: "Catalog: Activate Entity ...",
|
||||
action: () => openCommandDialog(<ActivateEntityCommand />),
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
const internalCommandsInjectable = getInjectable({
|
||||
instantiate: (di) => getInternalCommands({
|
||||
openCommandDialog: di.inject(commandOverlayInjectable).open,
|
||||
getEntitySettingItems: EntitySettingRegistry
|
||||
.getInstance()
|
||||
.getItemsForKind,
|
||||
}),
|
||||
lifecycle: lifecycleEnum.singleton,
|
||||
});
|
||||
|
||||
export default internalCommandsInjectable;
|
||||
@@ -1,215 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2021 OpenLens Authors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import React from "react";
|
||||
import * as routes from "../../../../common/routes";
|
||||
import { EntitySettingRegistry } from "../../../../extensions/registries";
|
||||
import { CommandOverlay } from "../../../components/command-palette";
|
||||
import { createTerminalTab } from "../../../components/dock/terminal.store";
|
||||
import { HotbarAddCommand } from "../../../components/hotbar/hotbar-add-command";
|
||||
import { HotbarRemoveCommand } from "../../../components/hotbar/hotbar-remove-command";
|
||||
import { HotbarSwitchCommand } from "../../../components/hotbar/hotbar-switch-command";
|
||||
import { HotbarRenameCommand } from "../../../components/hotbar/hotbar-rename-command";
|
||||
import { ActivateEntityCommand } from "../../../components/activate-entity-command";
|
||||
import type { CommandContext, CommandRegistration } from "./commands";
|
||||
|
||||
export function isKubernetesClusterActive(context: CommandContext): boolean {
|
||||
return context.entity?.kind === "KubernetesCluster";
|
||||
}
|
||||
|
||||
export const internalCommands: CommandRegistration[] = [
|
||||
{
|
||||
id: "app.showPreferences",
|
||||
title: "Preferences: Open",
|
||||
action: ({ navigate }) => navigate(routes.preferencesURL(), {
|
||||
forceRootFrame: true,
|
||||
}),
|
||||
},
|
||||
{
|
||||
id: "cluster.viewHelmCharts",
|
||||
title: "Cluster: View Helm Charts",
|
||||
isActive: isKubernetesClusterActive,
|
||||
action: ({ navigate }) => navigate(routes.helmChartsURL()),
|
||||
},
|
||||
{
|
||||
id: "cluster.viewHelmReleases",
|
||||
title: "Cluster: View Helm Releases",
|
||||
isActive: isKubernetesClusterActive,
|
||||
action: ({ navigate }) => navigate(routes.releaseURL()),
|
||||
},
|
||||
{
|
||||
id: "cluster.viewConfigMaps",
|
||||
title: "Cluster: View ConfigMaps",
|
||||
isActive: isKubernetesClusterActive,
|
||||
action: ({ navigate }) => navigate(routes.configMapsURL()),
|
||||
},
|
||||
{
|
||||
id: "cluster.viewSecrets",
|
||||
title: "Cluster: View Secrets",
|
||||
isActive: isKubernetesClusterActive,
|
||||
action: ({ navigate }) => navigate(routes.secretsURL()),
|
||||
},
|
||||
{
|
||||
id: "cluster.viewResourceQuotas",
|
||||
title: "Cluster: View ResourceQuotas",
|
||||
isActive: isKubernetesClusterActive,
|
||||
action: ({ navigate }) => navigate(routes.resourceQuotaURL()),
|
||||
},
|
||||
{
|
||||
id: "cluster.viewLimitRanges",
|
||||
title: "Cluster: View LimitRanges",
|
||||
isActive: isKubernetesClusterActive,
|
||||
action: ({ navigate }) => navigate(routes.limitRangeURL()),
|
||||
},
|
||||
{
|
||||
id: "cluster.viewHorizontalPodAutoscalers",
|
||||
title: "Cluster: View HorizontalPodAutoscalers (HPA)",
|
||||
isActive: isKubernetesClusterActive,
|
||||
action: ({ navigate }) => navigate(routes.hpaURL()),
|
||||
},
|
||||
{
|
||||
id: "cluster.viewPodDisruptionBudget",
|
||||
title: "Cluster: View PodDisruptionBudgets",
|
||||
isActive: isKubernetesClusterActive,
|
||||
action: ({ navigate }) => navigate(routes.pdbURL()),
|
||||
},
|
||||
{
|
||||
id: "cluster.viewServices",
|
||||
title: "Cluster: View Services",
|
||||
isActive: isKubernetesClusterActive,
|
||||
action: ({ navigate }) => navigate(routes.servicesURL()),
|
||||
},
|
||||
{
|
||||
id: "cluster.viewEndpoints",
|
||||
title: "Cluster: View Endpoints",
|
||||
isActive: isKubernetesClusterActive,
|
||||
action: ({ navigate }) => navigate(routes.endpointURL()),
|
||||
},
|
||||
{
|
||||
id: "cluster.viewIngresses",
|
||||
title: "Cluster: View Ingresses",
|
||||
isActive: isKubernetesClusterActive,
|
||||
action: ({ navigate }) => navigate(routes.ingressURL()),
|
||||
},
|
||||
{
|
||||
id: "cluster.viewNetworkPolicies",
|
||||
title: "Cluster: View NetworkPolicies",
|
||||
isActive: isKubernetesClusterActive,
|
||||
action: ({ navigate }) => navigate(routes.networkPoliciesURL()),
|
||||
},
|
||||
{
|
||||
id: "cluster.viewNodes",
|
||||
title: "Cluster: View Nodes",
|
||||
isActive: isKubernetesClusterActive,
|
||||
action: ({ navigate }) => navigate(routes.nodesURL()),
|
||||
},
|
||||
{
|
||||
id: "cluster.viewPods",
|
||||
title: "Cluster: View Pods",
|
||||
isActive: isKubernetesClusterActive,
|
||||
action: ({ navigate }) => navigate(routes.podsURL()),
|
||||
},
|
||||
{
|
||||
id: "cluster.viewDeployments",
|
||||
title: "Cluster: View Deployments",
|
||||
isActive: isKubernetesClusterActive,
|
||||
action: ({ navigate }) => navigate(routes.deploymentsURL()),
|
||||
},
|
||||
{
|
||||
id: "cluster.viewDaemonSets",
|
||||
title: "Cluster: View DaemonSets",
|
||||
isActive: isKubernetesClusterActive,
|
||||
action: ({ navigate }) => navigate(routes.daemonSetsURL()),
|
||||
},
|
||||
{
|
||||
id: "cluster.viewStatefulSets",
|
||||
title: "Cluster: View StatefulSets",
|
||||
isActive: isKubernetesClusterActive,
|
||||
action: ({ navigate }) => navigate(routes.statefulSetsURL()),
|
||||
},
|
||||
{
|
||||
id: "cluster.viewJobs",
|
||||
title: "Cluster: View Jobs",
|
||||
isActive: isKubernetesClusterActive,
|
||||
action: ({ navigate }) => navigate(routes.jobsURL()),
|
||||
},
|
||||
{
|
||||
id: "cluster.viewCronJobs",
|
||||
title: "Cluster: View CronJobs",
|
||||
isActive: isKubernetesClusterActive,
|
||||
action: ({ navigate }) => navigate(routes.cronJobsURL()),
|
||||
},
|
||||
{
|
||||
id: "cluster.viewCustomResourceDefinitions",
|
||||
title: "Cluster: View Custom Resource Definitions",
|
||||
isActive: isKubernetesClusterActive,
|
||||
action: ({ navigate }) => navigate(routes.crdURL()),
|
||||
},
|
||||
{
|
||||
id: "entity.viewSettings",
|
||||
title: ({ entity }) => `${entity.kind}/${entity.getName()}: View Settings`,
|
||||
action: ({ entity, navigate }) => navigate(`/entity/${entity.getId()}/settings`, {
|
||||
forceRootFrame: true,
|
||||
}),
|
||||
isActive: ({ entity }) => {
|
||||
if (!entity) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO: replace with injection
|
||||
const entries = EntitySettingRegistry.getInstance()
|
||||
.getItemsForKind(entity.kind, entity.apiVersion, entity.metadata.source);
|
||||
|
||||
return entries.length > 0;
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "cluster.openTerminal",
|
||||
title: "Cluster: Open terminal",
|
||||
action: () => createTerminalTab(),
|
||||
isActive: isKubernetesClusterActive,
|
||||
},
|
||||
{
|
||||
id: "hotbar.switchHotbar",
|
||||
title: "Hotbar: Switch ...",
|
||||
action: () => CommandOverlay.open(<HotbarSwitchCommand />),
|
||||
},
|
||||
{
|
||||
id: "hotbar.addHotbar",
|
||||
title: "Hotbar: Add Hotbar ...",
|
||||
action: () => CommandOverlay.open(<HotbarAddCommand />),
|
||||
},
|
||||
{
|
||||
id: "hotbar.removeHotbar",
|
||||
title: "Hotbar: Remove Hotbar ...",
|
||||
action: () => CommandOverlay.open(<HotbarRemoveCommand />),
|
||||
},
|
||||
{
|
||||
id: "hotbar.renameHotbar",
|
||||
title: "Hotbar: Rename Hotbar ...",
|
||||
action: () => CommandOverlay.open(<HotbarRenameCommand />),
|
||||
},
|
||||
{
|
||||
id: "catalog.searchEntities",
|
||||
title: "Catalog: Activate Entity ...",
|
||||
action: () => CommandOverlay.open(<ActivateEntityCommand />),
|
||||
},
|
||||
];
|
||||
+16
-17
@@ -22,32 +22,30 @@
|
||||
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
|
||||
import { computed, IComputedValue } from "mobx";
|
||||
import type { CustomResourceDefinition } from "../../../../common/k8s-api/endpoints";
|
||||
import customResourceDefinitionsInjectable from "../../../../common/k8s-api/endpoints/custom-resources/custom-resources.injectable";
|
||||
import customResourceDefinitionsInjectable from "../../+custom-resources/custom-resources.injectable";
|
||||
import type { LensRendererExtension } from "../../../../extensions/lens-renderer-extension";
|
||||
import rendererExtensionsInjectable from "../../../../extensions/renderer-extensions.injectable";
|
||||
import { iter } from "../../../utils";
|
||||
import type { RegisteredCommand } from "./commands";
|
||||
import { internalCommands, isKubernetesClusterActive } from "./internal-commands";
|
||||
import type { CommandRegistration, RegisteredCommand } from "./commands";
|
||||
import internalCommandsInjectable, { isKubernetesClusterActive } from "./internal-commands.injectable";
|
||||
|
||||
interface Dependencies {
|
||||
extensions: IComputedValue<LensRendererExtension[]>;
|
||||
customResourceDefinitions: IComputedValue<CustomResourceDefinition[]>;
|
||||
internalCommands: CommandRegistration[];
|
||||
}
|
||||
|
||||
const instantiateRegisteredCommands = ({ extensions, customResourceDefinitions }: Dependencies) => computed(() => {
|
||||
const instantiateRegisteredCommands = ({ extensions, customResourceDefinitions, internalCommands }: Dependencies) => computed(() => {
|
||||
const result = new Map<string, RegisteredCommand>();
|
||||
const commands = iter.chain(
|
||||
internalCommands,
|
||||
iter.chain(
|
||||
iter.flatMap(extensions.get(), extension => extension.commands),
|
||||
iter.map(customResourceDefinitions.get(), command => ({
|
||||
id: `cluster.view.${command.getResourceKind()}`,
|
||||
title: `Cluster: View ${command.getResourceKind()}`,
|
||||
isActive: isKubernetesClusterActive,
|
||||
action: ({ navigate }) => navigate(command.getResourceUrl()),
|
||||
})),
|
||||
),
|
||||
);
|
||||
const commands = [
|
||||
...internalCommands,
|
||||
...extensions.get().flatMap(e => e.commands),
|
||||
...customResourceDefinitions.get().map((command): CommandRegistration => ({
|
||||
id: `cluster.view.${command.getResourceKind()}`,
|
||||
title: `Cluster: View ${command.getResourceKind()}`,
|
||||
isActive: isKubernetesClusterActive,
|
||||
action: ({ navigate }) => navigate(command.getResourceUrl()),
|
||||
})),
|
||||
];
|
||||
|
||||
for (const { scope, isActive = () => true, ...command } of commands) {
|
||||
if (!result.has(command.id)) {
|
||||
@@ -62,6 +60,7 @@ const registeredCommandsInjectable = getInjectable({
|
||||
instantiate: (di) => instantiateRegisteredCommands({
|
||||
extensions: di.inject(rendererExtensionsInjectable),
|
||||
customResourceDefinitions: di.inject(customResourceDefinitionsInjectable),
|
||||
internalCommands: di.inject(internalCommandsInjectable),
|
||||
}),
|
||||
|
||||
lifecycle: lifecycleEnum.singleton,
|
||||
|
||||
Reference in new issue
Block a user