1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
4 import React from "react";
5 import { Popover, List, ListItem, ListItemIcon, ListItemText, Divider } from "@material-ui/core";
6 import { DefaultTransformOrigin } from "../popover/helpers";
7 import { IconType } from "../icon/icon";
8 import { RootState } from "store/store";
9 import { ContextMenuResource } from "store/context-menu/context-menu-actions";
11 export interface ContextMenuItem {
12 name?: string | React.ComponentType;
14 component?: React.ComponentType<any>;
16 filters?: ((state: RootState, resource: ContextMenuResource) => boolean)[]
19 export type ContextMenuItemGroup = ContextMenuItem[];
21 export interface ContextMenuProps {
22 anchorEl?: HTMLElement;
23 items: ContextMenuItemGroup[];
25 onItemClick: (action: ContextMenuItem) => void;
29 export class ContextMenu extends React.PureComponent<ContextMenuProps> {
31 const { anchorEl, items, open, onClose, onItemClick } = this.props;
36 transformOrigin={DefaultTransformOrigin}
37 anchorOrigin={DefaultTransformOrigin}
38 onContextMenu={this.handleContextMenu}>
39 <List data-cy='context-menu' dense>
40 {items.map((group, groupIndex) =>
41 <React.Fragment key={groupIndex}>
42 {group.map((item, actionIndex) =>
46 onClick={() => onItemClick(item)} />
50 onClick={() => onItemClick(item)}>
61 items[groupIndex + 1] &&
62 items[groupIndex + 1].length > 0 &&
70 handleContextMenu = (event: React.MouseEvent<HTMLElement>) => {
71 event.preventDefault();