mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Add ability to hide KubeObjectMenu Edit and Remove buttons in extensions (#5107)
This commit is contained in:
1 parent
e532b90b72
commit
dbdde19222
51 files changed
+1245
-765
No files matched your search
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import type { RequireAtLeastOne } from "type-fest";
|
||||
import type { KubeObject } from "../../common/k8s-api/kube-object";
|
||||
import type { BaseIconProps } from "../components/icon";
|
||||
|
||||
export interface KubeObjectContextMenuItem {
|
||||
/**
|
||||
* If the type is `string` then it is shorthand for {@link BaseIconProps.material}
|
||||
*
|
||||
* This is required because this item can be either rendered as a context menu or as a toolbar in
|
||||
* the kube object details page.
|
||||
*/
|
||||
icon: string | BaseIconProps;
|
||||
|
||||
/**
|
||||
* The title text for the menu item or the hover text for the icon.
|
||||
*/
|
||||
title: string;
|
||||
|
||||
/**
|
||||
* The action when clicked
|
||||
*/
|
||||
onClick: (obj: KubeObject) => void;
|
||||
}
|
||||
|
||||
export interface KubeObjectOnContextMenuOpenContext {
|
||||
menuItems: KubeObjectContextMenuItem[];
|
||||
navigate: (location: string) => void;
|
||||
}
|
||||
|
||||
export type KubeObjectOnContextMenuOpen = (ctx: KubeObjectOnContextMenuOpenContext) => void;
|
||||
|
||||
export interface KubeObjectHandlers {
|
||||
onContextMenuOpen: KubeObjectOnContextMenuOpen;
|
||||
}
|
||||
|
||||
export type KubeObjectHandlerRegistration = {
|
||||
apiVersions: string[];
|
||||
kind: string;
|
||||
} & RequireAtLeastOne<KubeObjectHandlers>;
|
||||
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* 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 { computed } from "mobx";
|
||||
import rendererExtensionsInjectable from "../../extensions/renderer-extensions.injectable";
|
||||
import { getOrInsert, getOrInsertMap, readonly } from "../utils";
|
||||
import type { KubeObjectHandlerRegistration, KubeObjectHandlers } from "./handler";
|
||||
import { staticKubeObjectContextMenuHandlers } from "./static-handlers";
|
||||
|
||||
const kubeObjectHandlersInjectable = getInjectable({
|
||||
id: "kube-object-handlers",
|
||||
instantiate: (di) => {
|
||||
const extensions = di.inject(rendererExtensionsInjectable);
|
||||
|
||||
return computed(() => {
|
||||
const res = new Map<string, Map<string, Partial<KubeObjectHandlers>[]>>();
|
||||
const addAllHandlers = (registrations: KubeObjectHandlerRegistration[]) => {
|
||||
for (const { apiVersions, kind, ...handlers } of registrations) {
|
||||
for (const apiVersion of apiVersions) {
|
||||
const byApiVersion = getOrInsertMap(res, apiVersion);
|
||||
const byKind = getOrInsert(byApiVersion, kind, []);
|
||||
|
||||
byKind.push(handlers);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
extensions.get()
|
||||
.map(ext => ext.kubeObjectHandlers)
|
||||
.forEach(addAllHandlers);
|
||||
|
||||
addAllHandlers(staticKubeObjectContextMenuHandlers);
|
||||
|
||||
return readonly(res);
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export default kubeObjectHandlersInjectable;
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import type { KubeObjectHandlerRegistration } from "./handler";
|
||||
import { StatefulSetScaleDialog } from "../components/+workloads-statefulsets/statefulset-scale-dialog";
|
||||
import type { StatefulSet } from "../../common/k8s-api/endpoints";
|
||||
|
||||
export const staticKubeObjectContextMenuHandlers: KubeObjectHandlerRegistration[] = [
|
||||
{
|
||||
kind: "StatefulSet",
|
||||
apiVersions: ["apps/v1"],
|
||||
onContextMenuOpen: (ctx) => {
|
||||
ctx.menuItems.push({
|
||||
icon: "open_with",
|
||||
title: "Scale",
|
||||
onClick: (obj: StatefulSet) => StatefulSetScaleDialog.open(obj),
|
||||
});
|
||||
},
|
||||
},
|
||||
];
|
||||
Reference in new issue
Block a user