mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
feat: Add deleting subNamespaces to contextMenu
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
aa950026a3
commit
89cf491bc0
@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { action } from "mobx";
|
||||
import type { Namespace } from "../../../common/k8s-api/endpoints";
|
||||
import type { KubeObjectOnContextMenuOpenContext } from "../../kube-object/handler";
|
||||
import { staticKubeObjectHandlerInjectionToken } from "../../kube-object/handler";
|
||||
import requestDeleteNamespaceInjectable from "./request-delete-namespace.injectable";
|
||||
|
||||
const namespaceRemoveContextMenuOverridingListenerInjectable = getInjectable({
|
||||
id: "namespace-remove-context-menu-overriding-listener",
|
||||
instantiate: (di) => {
|
||||
const requestDeleteNamespace = di.inject(requestDeleteNamespaceInjectable);
|
||||
|
||||
return ({
|
||||
apiVersions: ["v1"],
|
||||
kind: "Namespace",
|
||||
onContextMenuOpen: action((ctx: KubeObjectOnContextMenuOpenContext) => {
|
||||
ctx.menuItems.replace([
|
||||
{
|
||||
id: "new-delete-kube-object",
|
||||
icon: "delete",
|
||||
title: "Delete",
|
||||
onClick: (obj) => requestDeleteNamespace(obj as Namespace),
|
||||
},
|
||||
...ctx.menuItems.filter((menuItem) => menuItem.id !== "delete-kube-object"),
|
||||
]);
|
||||
}),
|
||||
});
|
||||
},
|
||||
injectionToken: staticKubeObjectHandlerInjectionToken,
|
||||
});
|
||||
|
||||
export default namespaceRemoveContextMenuOverridingListenerInjectable;
|
||||
@ -106,6 +106,7 @@ class NonInjectedKubeObjectMenu<Kube extends KubeObject> extends React.Component
|
||||
|
||||
if (isRemovable) {
|
||||
this.menuItems.push({
|
||||
id: "delete-kube-object",
|
||||
title: "Delete",
|
||||
icon: "delete",
|
||||
onClick: withConfirmation({
|
||||
@ -126,6 +127,7 @@ class NonInjectedKubeObjectMenu<Kube extends KubeObject> extends React.Component
|
||||
|
||||
if (isEditable) {
|
||||
this.menuItems.push({
|
||||
id: "edit-kube-object",
|
||||
title: "Edit",
|
||||
icon: "edit",
|
||||
onClick: async () => {
|
||||
|
||||
@ -4,11 +4,13 @@
|
||||
*/
|
||||
|
||||
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||
import type { IObservableArray } from "mobx";
|
||||
import type { RequireAtLeastOne } from "type-fest";
|
||||
import type { KubeObject } from "../../common/k8s-api/kube-object";
|
||||
import type { BaseIconProps } from "../components/icon";
|
||||
|
||||
export interface KubeObjectContextMenuItem {
|
||||
id?: string;
|
||||
/**
|
||||
* If the type is `string` then it is shorthand for {@link BaseIconProps.material}
|
||||
*
|
||||
@ -29,7 +31,7 @@ export interface KubeObjectContextMenuItem {
|
||||
}
|
||||
|
||||
export interface KubeObjectOnContextMenuOpenContext {
|
||||
menuItems: KubeObjectContextMenuItem[];
|
||||
readonly menuItems: IObservableArray<KubeObjectContextMenuItem>;
|
||||
navigate: (location: string) => void;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user