1
0
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

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Jari Kolehmainen 2021-04-09 14:34:51 +03:00
parent 99a464c61d
commit 451aa4ec1f
3 changed files with 5 additions and 2 deletions

View File

@ -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<void>;
confirm?: {
message: string;

View File

@ -124,6 +124,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);
};
@ -136,7 +137,7 @@ export class Catalog extends React.Component {
<MenuItem key="remove-from-hotbar" onClick={() => this.removeFromHotbar(item) }>
<Icon material="clear" small interactive={true} title="Remove from hotbar"/> Remove from Hotbar
</MenuItem>
{ this.contextMenu.menuItems.map((menuItem, index) => {
{ menuItems.map((menuItem, index) => {
return (
<MenuItem key={index} onClick={() => this.onMenuItemClick(menuItem)}>
<Icon material={menuItem.icon} small interactive={true} title={menuItem.title}/> {menuItem.title}

View File

@ -100,6 +100,7 @@ export class HotbarIcon extends React.Component<Props> {
await entity.onContextMenuOpen(this.contextMenu);
this.toggleMenu();
};
const menuItems = this.contextMenu?.menuItems.filter((menuItem) => !menuItem.onlyVisibleForSource || menuItem.onlyVisibleForSource === entity.metadata.source);
return (
<div className={className}>
@ -117,7 +118,7 @@ export class HotbarIcon extends React.Component<Props> {
<MenuItem key="remove-from-hotbar" onClick={() => this.removeFromHotbar(entity) }>
<Icon material="clear" small interactive={true} title="Remove from hotbar"/> Remove from Hotbar
</MenuItem>
{ this.contextMenu && this.contextMenu.menuItems.map((menuItem) => {
{ this.contextMenu && menuItems.map((menuItem) => {
return (
<MenuItem key={menuItem.title} onClick={() => this.onMenuItemClick(menuItem) }>
<Icon material={menuItem.icon} small interactive={true} title={menuItem.title}/> {menuItem.title}