// Copyright (C) 2020 Intel Corporation // // SPDX-License-Identifier: MIT import React from 'react'; import ReactDOM from 'react-dom'; import Menu from 'antd/lib/menu'; // eslint-disable-next-line import/no-extraneous-dependencies import { MenuInfo } from 'rc-menu/lib/interface'; import ObjectItemContainer from 'containers/annotation-page/standard-workspace/objects-side-bar/object-item'; import { Workspace } from 'reducers/interfaces'; import consts from 'consts'; interface Props { readonly: boolean; workspace: Workspace; contextMenuClientID: number | null; objectStates: any[]; visible: boolean; left: number; top: number; onStartIssue(position: number[]): void; openIssue(position: number[], message: string): void; latestComments: string[]; } interface ReviewContextMenuProps { top: number; left: number; latestComments: string[]; onClick: (param: MenuInfo) => void; } enum ReviewContextMenuKeys { OPEN_ISSUE = 'open_issue', QUICK_ISSUE_POSITION = 'quick_issue_position', QUICK_ISSUE_ATTRIBUTE = 'quick_issue_attribute', QUICK_ISSUE_FROM_LATEST = 'quick_issue_from_latest', } function ReviewContextMenu({ top, left, latestComments, onClick, }: ReviewContextMenuProps): JSX.Element { return ( Open an issue ... Quick issue: incorrect position Quick issue: incorrect attribute {latestComments.length ? ( {latestComments.map( (comment: string, id: number): JSX.Element => ( {comment} ), )} ) : null} ); } export default function CanvasContextMenu(props: Props): JSX.Element | null { const { contextMenuClientID, objectStates, visible, left, top, readonly, workspace, latestComments, onStartIssue, openIssue, } = props; if (!visible || contextMenuClientID === null) { return null; } if (workspace === Workspace.REVIEW_WORKSPACE) { return ReactDOM.createPortal( { const [state] = objectStates.filter( (_state: any): boolean => _state.clientID === contextMenuClientID, ); if (param.key === ReviewContextMenuKeys.OPEN_ISSUE) { if (state) { onStartIssue(state.points); } } else if (param.key === ReviewContextMenuKeys.QUICK_ISSUE_POSITION) { if (state) { openIssue(state.points, consts.QUICK_ISSUE_INCORRECT_POSITION_TEXT); } } else if (param.key === ReviewContextMenuKeys.QUICK_ISSUE_ATTRIBUTE) { if (state) { openIssue(state.points, consts.QUICK_ISSUE_INCORRECT_ATTRIBUTE_TEXT); } } else if ( param.keyPath.length === 2 && param.keyPath[1] === ReviewContextMenuKeys.QUICK_ISSUE_FROM_LATEST ) { if (state) { openIssue(state.points, latestComments[+param.keyPath[0]]); } } }} />, window.document.body, ); } return ReactDOM.createPortal(
, window.document.body, ); }