From 1ac5588fab94da94af799fc7ed939cca7b92b8e6 Mon Sep 17 00:00:00 2001 From: Jari Kolehmainen Date: Thu, 15 Apr 2021 15:16:56 +0300 Subject: [PATCH] Allow to control catalog entity menu item visibility based on source (#2499) * allow to control catalog entity menu item visibility based on source Signed-off-by: Jari Kolehmainen * fix Signed-off-by: Jari Kolehmainen --- src/common/catalog-entities/kubernetes-cluster.ts | 2 ++ src/common/catalog-entity.ts | 1 + src/renderer/components/+catalog/catalog.tsx | 3 ++- src/renderer/components/hotbar/hotbar-icon.tsx | 3 ++- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/common/catalog-entities/kubernetes-cluster.ts b/src/common/catalog-entities/kubernetes-cluster.ts index 3354b9ba61..d0760dcdf1 100644 --- a/src/common/catalog-entities/kubernetes-cluster.ts +++ b/src/common/catalog-entities/kubernetes-cluster.ts @@ -49,11 +49,13 @@ export class KubernetesCluster implements CatalogEntity { { icon: "settings", title: "Settings", + onlyVisibleForSource: "local", onClick: async () => context.navigate(`/cluster/${this.metadata.uid}/settings`) }, { icon: "delete", title: "Delete", + onlyVisibleForSource: "local", onClick: async () => clusterStore.removeById(this.metadata.uid), confirm: { message: `Remove Kubernetes Cluster "${this.metadata.name} from Lens?` diff --git a/src/common/catalog-entity.ts b/src/common/catalog-entity.ts index ad3f0e591e..19d83d5437 100644 --- a/src/common/catalog-entity.ts +++ b/src/common/catalog-entity.ts @@ -45,6 +45,7 @@ export interface CatalogEntityActionContext { export type CatalogEntityContextMenu = { icon: string; title: string; + onlyVisibleForSource?: string; // show only if empty or if matches with entity source onClick: () => Promise; confirm?: { message: string; diff --git a/src/renderer/components/+catalog/catalog.tsx b/src/renderer/components/+catalog/catalog.tsx index 5cd0e918c1..a73ba86c28 100644 --- a/src/renderer/components/+catalog/catalog.tsx +++ b/src/renderer/components/+catalog/catalog.tsx @@ -127,6 +127,7 @@ export class Catalog extends React.Component { @autobind() renderItemMenu(item: CatalogEntityItem) { + const menuItems = this.contextMenu.menuItems.filter((menuItem) => !menuItem.onlyVisibleForSource || menuItem.onlyVisibleForSource === item.entity.metadata.source); const onOpen = async () => { await item.onContextMenuOpen(this.contextMenu); }; @@ -139,7 +140,7 @@ export class Catalog extends React.Component { this.removeFromHotbar(item) }> Remove from Hotbar - { this.contextMenu.menuItems.map((menuItem, index) => { + { menuItems.map((menuItem, index) => { return ( this.onMenuItemClick(menuItem)}> {menuItem.title} diff --git a/src/renderer/components/hotbar/hotbar-icon.tsx b/src/renderer/components/hotbar/hotbar-icon.tsx index 201bc2df02..29902bc6a0 100644 --- a/src/renderer/components/hotbar/hotbar-icon.tsx +++ b/src/renderer/components/hotbar/hotbar-icon.tsx @@ -100,6 +100,7 @@ export class HotbarIcon extends React.Component { await entity.onContextMenuOpen(this.contextMenu); this.toggleMenu(); }; + const menuItems = this.contextMenu?.menuItems.filter((menuItem) => !menuItem.onlyVisibleForSource || menuItem.onlyVisibleForSource === entity.metadata.source); return (
@@ -117,7 +118,7 @@ export class HotbarIcon extends React.Component { this.removeFromHotbar(entity) }> Remove from Hotbar - { this.contextMenu && this.contextMenu.menuItems.map((menuItem) => { + { this.contextMenu && menuItems.map((menuItem) => { return ( this.onMenuItemClick(menuItem) }> {menuItem.title}