diff --git a/cvat-ui/src/components/job-item/job-actions-menu.tsx b/cvat-ui/src/components/job-item/job-actions-menu.tsx index 7ca0892d7c7a..6ed839c6fb42 100644 --- a/cvat-ui/src/components/job-item/job-actions-menu.tsx +++ b/cvat-ui/src/components/job-item/job-actions-menu.tsx @@ -17,60 +17,72 @@ interface Props { job: Job; } +export enum Actions { + TASK = 'task', + PROJECT = 'project', + BUG_TRACKER = 'bug_tracker', + IMPORT_JOB = 'import_job', + EXPORT_JOB = 'export_job', + VIEW_ANALYTICS = 'view_analytics', + DELETE = 'delete', +} + function JobActionsMenu(props: Props): JSX.Element { const { job } = props; const dispatch = useDispatch(); const history = useHistory(); - const onDelete = useCallback(() => { - Modal.confirm({ - title: `The job ${job.id} will be deleted`, - content: 'All related data (annotations) will be lost. Continue?', - className: 'cvat-modal-confirm-delete-job', - onOk: () => { - dispatch(deleteJobAsync(job)); - }, - okButtonProps: { - type: 'primary', - danger: true, - }, - okText: 'Delete', - }); - }, [job]); + const onClickMenu = useCallback( + (action: MenuInfo) => { + if (action.key === Actions.TASK) { + history.push(`/tasks/${job.taskId}`); + } else if (action.key === Actions.PROJECT) { + history.push(`/projects/${job.projectId}`); + } else if (action.key === Actions.BUG_TRACKER) { + if (job.bugTracker) { + window.open(job.bugTracker, '_blank', 'noopener noreferrer'); + } + } else if (action.key === Actions.IMPORT_JOB) { + dispatch(importActions.openImportDatasetModal(job)); + } else if (action.key === Actions.EXPORT_JOB) { + dispatch(exportActions.openExportDatasetModal(job)); + } else if (action.key === Actions.VIEW_ANALYTICS) { + history.push(`/tasks/${job.taskId}/jobs/${job.id}/analytics`); + } else if (action.key === Actions.DELETE) { + Modal.confirm({ + title: `The job ${job.id} will be deleted`, + content: 'All related data (annotations) will be lost. Continue?', + className: 'cvat-modal-confirm-delete-job', + onOk: () => { + dispatch(deleteJobAsync(job)); + }, + okButtonProps: { + type: 'primary', + danger: true, + }, + okText: 'Delete', + }); + } + }, + [job], + ); return ( { - if (action.key === 'task') { - history.push(`/tasks/${job.taskId}`); - } else if (action.key === 'project') { - history.push(`/projects/${job.projectId}`); - } else if (action.key === 'bug_tracker') { - if (job.bugTracker) { - window.open(job.bugTracker, '_blank', 'noopener noreferrer'); - } - } else if (action.key === 'import_job') { - dispatch(importActions.openImportDatasetModal(job)); - } else if (action.key === 'export_job') { - dispatch(exportActions.openExportDatasetModal(job)); - } else if (action.key === 'view_analytics') { - history.push(`/tasks/${job.taskId}/jobs/${job.id}/analytics`); - } - }} + onClick={onClickMenu} > - Go to the task - Go to the project - Go to the bug tracker - Import annotations - Export annotations - View analytics + Go to the task + Go to the project + Go to the bug tracker + Import annotations + Export annotations + View analytics onDelete()} > Delete