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:
parent
c5a182c310
commit
b604902c72
@ -274,6 +274,14 @@ export class HotbarStore extends BaseStore<HotbarStoreModel> {
|
|||||||
|
|
||||||
hotbarStore.activeHotbarId = hotbarStore.hotbars[index].id;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -44,6 +44,7 @@ import { catalogEntityRegistry } from "../../api/catalog-entity-registry";
|
|||||||
import { HotbarIcon } from "../hotbar/hotbar-icon";
|
import { HotbarIcon } from "../hotbar/hotbar-icon";
|
||||||
import { observable } from "mobx";
|
import { observable } from "mobx";
|
||||||
import type { CatalogEntityContextMenuContext } from "../../../common/catalog";
|
import type { CatalogEntityContextMenuContext } from "../../../common/catalog";
|
||||||
|
import { HotbarStore } from "../../../common/hotbar-store";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
className?: string;
|
className?: string;
|
||||||
@ -202,7 +203,16 @@ export class Sidebar extends React.Component<Props> {
|
|||||||
onClick={() => navigate("/")}
|
onClick={() => navigate("/")}
|
||||||
menuItems={this.contextMenu.menuItems}
|
menuItems={this.contextMenu.menuItems}
|
||||||
onMenuOpen={() => {
|
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);
|
this.clusterEntity.onContextMenuOpen(this.contextMenu);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user