1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Add hotbar functions to context menu

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2021-10-14 10:06:24 -04:00
parent c5a182c310
commit b604902c72
2 changed files with 19 additions and 1 deletions

View File

@ -274,6 +274,14 @@ export class HotbarStore extends BaseStore<HotbarStoreModel> {
hotbarStore.activeHotbarId = hotbarStore.hotbars[index].id;
}
/**
* Checks if entity already pinned to hotbar
* @returns boolean
*/
isAddedToActive(entity: CatalogEntity) {
return !!this.getActive().items.find(item => item?.entity.uid === entity.metadata.uid);
}
}
/**

View File

@ -44,6 +44,7 @@ import { catalogEntityRegistry } from "../../api/catalog-entity-registry";
import { HotbarIcon } from "../hotbar/hotbar-icon";
import { observable } from "mobx";
import type { CatalogEntityContextMenuContext } from "../../../common/catalog";
import { HotbarStore } from "../../../common/hotbar-store";
interface Props {
className?: string;
@ -202,7 +203,16 @@ export class Sidebar extends React.Component<Props> {
onClick={() => navigate("/")}
menuItems={this.contextMenu.menuItems}
onMenuOpen={() => {
this.contextMenu.menuItems = [];
const hotbarStore = HotbarStore.getInstance();
const isAddedToActive = HotbarStore.getInstance().isAddedToActive(this.clusterEntity);
const title = isAddedToActive
? `Remove from hotbar ${hotbarStore.getActive().name}`
: `Add to hotbar ${hotbarStore.getActive().name}`;
const onClick = isAddedToActive
? () => hotbarStore.removeFromHotbar(metadata.uid)
: () => hotbarStore.addToHotbar(this.clusterEntity);
this.contextMenu.menuItems = [{ title, onClick }];
this.clusterEntity.onContextMenuOpen(this.contextMenu);
}}
/>