mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix catalog entity context menu duplicate entries (#3035)
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
parent
a064d5fbfd
commit
e21178ed4d
@ -79,7 +79,7 @@ export class Catalog extends React.Component<Props> {
|
|||||||
|
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
this.contextMenu = {
|
this.contextMenu = {
|
||||||
menuItems: [],
|
menuItems: observable.array([]),
|
||||||
navigate: (url: string) => navigate(url)
|
navigate: (url: string) => navigate(url)
|
||||||
};
|
};
|
||||||
this.catalogEntityStore = new CatalogEntityStore();
|
this.catalogEntityStore = new CatalogEntityStore();
|
||||||
@ -169,8 +169,14 @@ export class Catalog extends React.Component<Props> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
renderItemMenu = (item: CatalogEntityItem) => {
|
renderItemMenu = (item: CatalogEntityItem) => {
|
||||||
|
const onOpen = () => {
|
||||||
|
this.contextMenu.menuItems = [];
|
||||||
|
|
||||||
|
item.onContextMenuOpen(this.contextMenu);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MenuActions onOpen={() => item.onContextMenuOpen(this.contextMenu)}>
|
<MenuActions onOpen={onOpen}>
|
||||||
{
|
{
|
||||||
this.contextMenu.menuItems.map((menuItem, index) => (
|
this.contextMenu.menuItems.map((menuItem, index) => (
|
||||||
<MenuItem key={index} onClick={() => this.onMenuItemClick(menuItem)}>
|
<MenuItem key={index} onClick={() => this.onMenuItemClick(menuItem)}>
|
||||||
|
|||||||
@ -23,7 +23,7 @@ import React, { DOMAttributes } from "react";
|
|||||||
import { makeObservable, observable } from "mobx";
|
import { makeObservable, observable } from "mobx";
|
||||||
import { observer } from "mobx-react";
|
import { observer } from "mobx-react";
|
||||||
|
|
||||||
import type { CatalogEntity, CatalogEntityContextMenuContext } from "../../../common/catalog";
|
import type { CatalogEntity, CatalogEntityContextMenu, CatalogEntityContextMenuContext } from "../../../common/catalog";
|
||||||
import { catalogCategoryRegistry } from "../../api/catalog-category-registry";
|
import { catalogCategoryRegistry } from "../../api/catalog-category-registry";
|
||||||
import { catalogEntityRegistry } from "../../api/catalog-entity-registry";
|
import { catalogEntityRegistry } from "../../api/catalog-entity-registry";
|
||||||
import { navigate } from "../../navigation";
|
import { navigate } from "../../navigation";
|
||||||
@ -101,24 +101,28 @@ export class HotbarEntityIcon extends React.Component<Props> {
|
|||||||
active: this.isActive(entity),
|
active: this.isActive(entity),
|
||||||
disabled: !entity
|
disabled: !entity
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const isPersisted = this.isPersisted(entity);
|
||||||
const onOpen = async () => {
|
const onOpen = async () => {
|
||||||
|
const menuItems: CatalogEntityContextMenu[] = [];
|
||||||
|
|
||||||
|
if (!isPersisted) {
|
||||||
|
menuItems.unshift({
|
||||||
|
title: "Pin to Hotbar",
|
||||||
|
onClick: () => add(entity, index)
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
menuItems.unshift({
|
||||||
|
title: "Unpin from Hotbar",
|
||||||
|
onClick: () => remove(entity.metadata.uid)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
this.contextMenu.menuItems = menuItems;
|
||||||
|
|
||||||
await entity.onContextMenuOpen(this.contextMenu);
|
await entity.onContextMenuOpen(this.contextMenu);
|
||||||
};
|
};
|
||||||
const isActive = this.isActive(entity);
|
const isActive = this.isActive(entity);
|
||||||
const isPersisted = this.isPersisted(entity);
|
|
||||||
const menuItems = this.contextMenu?.menuItems ?? [];
|
|
||||||
|
|
||||||
if (!isPersisted) {
|
|
||||||
menuItems.unshift({
|
|
||||||
title: "Pin to Hotbar",
|
|
||||||
onClick: () => add(entity, index)
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
menuItems.unshift({
|
|
||||||
title: "Unpin from Hotbar",
|
|
||||||
onClick: () => remove(entity.metadata.uid)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<HotbarIcon
|
<HotbarIcon
|
||||||
@ -128,7 +132,7 @@ export class HotbarEntityIcon extends React.Component<Props> {
|
|||||||
className={className}
|
className={className}
|
||||||
active={isActive}
|
active={isActive}
|
||||||
onMenuOpen={onOpen}
|
onMenuOpen={onOpen}
|
||||||
menuItems={menuItems}
|
menuItems={this.contextMenu.menuItems}
|
||||||
{...elemProps}
|
{...elemProps}
|
||||||
>
|
>
|
||||||
{ this.ledIcon }
|
{ this.ledIcon }
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user