mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
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 <jari.kolehmainen@gmail.com> * fix Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
parent
95ebb52f5d
commit
1ac5588fab
@ -49,11 +49,13 @@ export class KubernetesCluster implements CatalogEntity {
|
|||||||
{
|
{
|
||||||
icon: "settings",
|
icon: "settings",
|
||||||
title: "Settings",
|
title: "Settings",
|
||||||
|
onlyVisibleForSource: "local",
|
||||||
onClick: async () => context.navigate(`/cluster/${this.metadata.uid}/settings`)
|
onClick: async () => context.navigate(`/cluster/${this.metadata.uid}/settings`)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: "delete",
|
icon: "delete",
|
||||||
title: "Delete",
|
title: "Delete",
|
||||||
|
onlyVisibleForSource: "local",
|
||||||
onClick: async () => clusterStore.removeById(this.metadata.uid),
|
onClick: async () => clusterStore.removeById(this.metadata.uid),
|
||||||
confirm: {
|
confirm: {
|
||||||
message: `Remove Kubernetes Cluster "${this.metadata.name} from Lens?`
|
message: `Remove Kubernetes Cluster "${this.metadata.name} from Lens?`
|
||||||
|
|||||||
@ -45,6 +45,7 @@ export interface CatalogEntityActionContext {
|
|||||||
export type CatalogEntityContextMenu = {
|
export type CatalogEntityContextMenu = {
|
||||||
icon: string;
|
icon: string;
|
||||||
title: string;
|
title: string;
|
||||||
|
onlyVisibleForSource?: string; // show only if empty or if matches with entity source
|
||||||
onClick: () => Promise<void>;
|
onClick: () => Promise<void>;
|
||||||
confirm?: {
|
confirm?: {
|
||||||
message: string;
|
message: string;
|
||||||
|
|||||||
@ -127,6 +127,7 @@ export class Catalog extends React.Component {
|
|||||||
|
|
||||||
@autobind()
|
@autobind()
|
||||||
renderItemMenu(item: CatalogEntityItem) {
|
renderItemMenu(item: CatalogEntityItem) {
|
||||||
|
const menuItems = this.contextMenu.menuItems.filter((menuItem) => !menuItem.onlyVisibleForSource || menuItem.onlyVisibleForSource === item.entity.metadata.source);
|
||||||
const onOpen = async () => {
|
const onOpen = async () => {
|
||||||
await item.onContextMenuOpen(this.contextMenu);
|
await item.onContextMenuOpen(this.contextMenu);
|
||||||
};
|
};
|
||||||
@ -139,7 +140,7 @@ export class Catalog extends React.Component {
|
|||||||
<MenuItem key="remove-from-hotbar" onClick={() => this.removeFromHotbar(item) }>
|
<MenuItem key="remove-from-hotbar" onClick={() => this.removeFromHotbar(item) }>
|
||||||
<Icon material="clear" small interactive={true} title="Remove from hotbar"/> Remove from Hotbar
|
<Icon material="clear" small interactive={true} title="Remove from hotbar"/> Remove from Hotbar
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
{ this.contextMenu.menuItems.map((menuItem, index) => {
|
{ menuItems.map((menuItem, index) => {
|
||||||
return (
|
return (
|
||||||
<MenuItem key={index} onClick={() => this.onMenuItemClick(menuItem)}>
|
<MenuItem key={index} onClick={() => this.onMenuItemClick(menuItem)}>
|
||||||
<Icon material={menuItem.icon} small interactive={true} title={menuItem.title}/> {menuItem.title}
|
<Icon material={menuItem.icon} small interactive={true} title={menuItem.title}/> {menuItem.title}
|
||||||
|
|||||||
@ -100,6 +100,7 @@ export class HotbarIcon extends React.Component<Props> {
|
|||||||
await entity.onContextMenuOpen(this.contextMenu);
|
await entity.onContextMenuOpen(this.contextMenu);
|
||||||
this.toggleMenu();
|
this.toggleMenu();
|
||||||
};
|
};
|
||||||
|
const menuItems = this.contextMenu?.menuItems.filter((menuItem) => !menuItem.onlyVisibleForSource || menuItem.onlyVisibleForSource === entity.metadata.source);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={className}>
|
<div className={className}>
|
||||||
@ -117,7 +118,7 @@ export class HotbarIcon extends React.Component<Props> {
|
|||||||
<MenuItem key="remove-from-hotbar" onClick={() => this.removeFromHotbar(entity) }>
|
<MenuItem key="remove-from-hotbar" onClick={() => this.removeFromHotbar(entity) }>
|
||||||
<Icon material="clear" small interactive={true} title="Remove from hotbar"/> Remove from Hotbar
|
<Icon material="clear" small interactive={true} title="Remove from hotbar"/> Remove from Hotbar
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
{ this.contextMenu && this.contextMenu.menuItems.map((menuItem) => {
|
{ this.contextMenu && menuItems.map((menuItem) => {
|
||||||
return (
|
return (
|
||||||
<MenuItem key={menuItem.title} onClick={() => this.onMenuItemClick(menuItem) }>
|
<MenuItem key={menuItem.title} onClick={() => this.onMenuItemClick(menuItem) }>
|
||||||
<Icon material={menuItem.icon} small interactive={true} title={menuItem.title}/> {menuItem.title}
|
<Icon material={menuItem.icon} small interactive={true} title={menuItem.title}/> {menuItem.title}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user