Skip to content

Commit

Permalink
touchup: add "view" context menu items
Browse files Browse the repository at this point in the history
to prepare for allowing indicators to be hidden - this way, indicator
functionality is still enabled via the context menu.
  • Loading branch information
keyserj committed Dec 3, 2024
1 parent 5c440a0 commit 97c74e6
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/web/common/components/ContextMenu/ContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import { DeleteEdgeMenuItem } from "@/web/common/components/ContextMenu/DeleteEd
import { DeleteNodeMenuItem } from "@/web/common/components/ContextMenu/DeleteNodeMenuItem";
import { HideMenuItem } from "@/web/common/components/ContextMenu/HideMenuItem";
import { OnlyShowNodeAndNeighborsMenuItem } from "@/web/common/components/ContextMenu/OnlyShowNodeAndNeighborsMenuItem";
import { ViewContextMenuItem } from "@/web/common/components/ContextMenu/ViewContextMenuItem";
import { ViewDetailsMenuItem } from "@/web/common/components/ContextMenu/ViewDetailsMenuItem";
import { ViewTableMenuItem } from "@/web/common/components/ContextMenu/ViewTableMenuItem";
import { closeContextMenu } from "@/web/common/store/contextMenuActions";
import { useAnchorPosition, useContextMenuContext } from "@/web/common/store/contextMenuStore";

Expand All @@ -26,6 +29,11 @@ export const ContextMenu = () => {

// create these based on what's set in the context
const menuItems = [
// view actions (so that this functionality is still available if indicators are hidden)
contextPart && <ViewDetailsMenuItem graphPart={contextPart} key={1} />,
contextNode?.type === "problem" && <ViewTableMenuItem node={contextNode} key={2} />,
contextPart && <ViewContextMenuItem graphPart={contextPart} key={3} />,

// CRUD actions
contextPart === undefined && <AddNodeMenuItem parentMenuOpen={isOpen} key={9} />,
contextNode && <ChangeNodeTypeMenuItem node={contextNode} parentMenuOpen={isOpen} key={7} />,
Expand Down
12 changes: 12 additions & 0 deletions src/web/common/components/ContextMenu/ViewContextMenuItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ContextMenuItem } from "@/web/common/components/ContextMenu/CloseOnClickMenuItem";
import { GraphPart, isNode } from "@/web/topic/utils/graph";
import { contextMethods } from "@/web/topic/utils/partContext";

export const ViewContextMenuItem = ({ graphPart }: { graphPart: GraphPart }) => {
const partType = isNode(graphPart) ? graphPart.type : graphPart.label;
const viewContext = contextMethods[partType]?.viewContext;

if (!viewContext) return <></>;

return <ContextMenuItem onClick={() => viewContext(graphPart.id)}>View context</ContextMenuItem>;
};
17 changes: 17 additions & 0 deletions src/web/common/components/ContextMenu/ViewDetailsMenuItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ContextMenuItem } from "@/web/common/components/ContextMenu/CloseOnClickMenuItem";
import { emitter } from "@/web/common/event";
import { GraphPart } from "@/web/topic/utils/graph";
import { setSelected } from "@/web/view/currentViewStore/store";

export const ViewDetailsMenuItem = ({ graphPart }: { graphPart: GraphPart }) => {
return (
<ContextMenuItem
onClick={() => {
setSelected(graphPart.id);
emitter.emit("viewTopicDetails");
}}
>
View details
</ContextMenuItem>
);
};
11 changes: 11 additions & 0 deletions src/web/common/components/ContextMenu/ViewTableMenuItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ContextMenuItem } from "@/web/common/components/ContextMenu/CloseOnClickMenuItem";
import { Node } from "@/web/topic/utils/graph";
import { viewCriteriaTable } from "@/web/view/currentViewStore/filter";

export const ViewTableMenuItem = ({ node }: { node: Node }) => {
return (
<ContextMenuItem onClick={() => viewCriteriaTable(node.id)}>
View criteria table
</ContextMenuItem>
);
};

0 comments on commit 97c74e6

Please sign in to comment.