1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Custom remove namespaces methods

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2023-03-02 15:01:20 +03:00
parent 7fd7fd66f7
commit e9fbde7213
2 changed files with 20 additions and 2 deletions

View File

@ -7,6 +7,7 @@ import { withInjectables } from "@ogre-tools/injectable-react";
import React from "react"; import React from "react";
import type { Namespace } from "../../../common/k8s-api/endpoints"; import type { Namespace } from "../../../common/k8s-api/endpoints";
import type { KubeObject } from "../../../common/k8s-api/kube-object"; import type { KubeObject } from "../../../common/k8s-api/kube-object";
import withConfirmationInjectable, { WithConfirmation } from "../confirm-dialog/with-confirm.injectable";
import createEditResourceTabInjectable from "../dock/edit-resource/edit-resource-tab.injectable"; import createEditResourceTabInjectable from "../dock/edit-resource/edit-resource-tab.injectable";
import { Icon } from "../icon"; import { Icon } from "../icon";
import { MenuItem } from "../menu"; import { MenuItem } from "../menu";
@ -24,10 +25,11 @@ interface Dependencies {
readonly removeSubnamespace: (name: string) => Promise<void>; readonly removeSubnamespace: (name: string) => Promise<void>;
readonly namespaceStore: NamespaceStore; readonly namespaceStore: NamespaceStore;
readonly createEditResourceTab: (kubeObject: KubeObject) => void; readonly createEditResourceTab: (kubeObject: KubeObject) => void;
readonly withConfirmation: WithConfirmation;
} }
function NonInjectedNamespaceMenu(props: NamespaceMenuProps & Dependencies) { function NonInjectedNamespaceMenu(props: NamespaceMenuProps & Dependencies) {
const { namespace, removeSubnamespace, namespaceStore, createEditResourceTab } = props; const { namespace, removeSubnamespace, namespaceStore, createEditResourceTab, withConfirmation } = props;
const remove = async () => { const remove = async () => {
if (namespace.isSubnamespace()) { if (namespace.isSubnamespace()) {
@ -39,13 +41,25 @@ function NonInjectedNamespaceMenu(props: NamespaceMenuProps & Dependencies) {
namespaceStore.clearSelected(); namespaceStore.clearSelected();
}; };
const renderRemoveMessage = (object: KubeObject) => {
return (
<p>
Remove <b>{object.getName()}</b>?
</p>
);
}
return ( return (
<MenuActions {...props}> <MenuActions {...props}>
<MenuItem onClick={() => createEditResourceTab(namespace)}> <MenuItem onClick={() => createEditResourceTab(namespace)}>
<Icon material="edit" interactive={false} tooltip="Edit" /> <Icon material="edit" interactive={false} tooltip="Edit" />
<span className="title">Edit</span> <span className="title">Edit</span>
</MenuItem> </MenuItem>
<MenuItem onClick={remove}> <MenuItem onClick={withConfirmation({
message: renderRemoveMessage(namespace),
labelOk: "Remove",
ok: remove,
})}>
<Icon material="delete" interactive={false} tooltip="Delete" /> <Icon material="delete" interactive={false} tooltip="Delete" />
<span className="title">Delete</span> <span className="title">Delete</span>
</MenuItem> </MenuItem>
@ -59,5 +73,6 @@ export const NamespaceMenu = withInjectables<Dependencies, NamespaceMenuProps>(N
removeSubnamespace: di.inject(removeSubnamespaceInjectable), removeSubnamespace: di.inject(removeSubnamespaceInjectable),
namespaceStore: di.inject(namespaceStoreInjectable), namespaceStore: di.inject(namespaceStoreInjectable),
createEditResourceTab: di.inject(createEditResourceTabInjectable), createEditResourceTab: di.inject(createEditResourceTabInjectable),
withConfirmation: di.inject(withConfirmationInjectable),
}), }),
}); });

View File

@ -77,6 +77,9 @@ const NonInjectedNamespacesRoute = ({ namespaceStore, openAddNamespaceDialog }:
addRemoveButtons={{ addRemoveButtons={{
addTooltip: "Add Namespace", addTooltip: "Add Namespace",
onAdd: openAddNamespaceDialog, onAdd: openAddNamespaceDialog,
onRemove: () => {
namespaceStore.selectedItems.forEach(namespace => namespaceStore.remove(namespace));
},
}} }}
renderItemMenu={namespace => ( renderItemMenu={namespace => (
<NamespaceMenu <NamespaceMenu