Skip to content

Commit

Permalink
Refactor job actions menu (#9025)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiltsov-max authored Jan 31, 2025
1 parent 30e900b commit 0804c45
Showing 1 changed file with 52 additions and 40 deletions.
92 changes: 52 additions & 40 deletions cvat-ui/src/components/job-item/job-actions-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Menu
className='cvat-job-item-menu'
onClick={(action: MenuInfo) => {
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}
>
<Menu.Item key='task' disabled={job.taskId === null}>Go to the task</Menu.Item>
<Menu.Item key='project' disabled={job.projectId === null}>Go to the project</Menu.Item>
<Menu.Item key='bug_tracker' disabled={!job.bugTracker}>Go to the bug tracker</Menu.Item>
<Menu.Item key='import_job'>Import annotations</Menu.Item>
<Menu.Item key='export_job'>Export annotations</Menu.Item>
<Menu.Item key='view_analytics'>View analytics</Menu.Item>
<Menu.Item key={Actions.TASK} disabled={job.taskId === null}>Go to the task</Menu.Item>
<Menu.Item key={Actions.PROJECT} disabled={job.projectId === null}>Go to the project</Menu.Item>
<Menu.Item key={Actions.BUG_TRACKER} disabled={!job.bugTracker}>Go to the bug tracker</Menu.Item>
<Menu.Item key={Actions.IMPORT_JOB}>Import annotations</Menu.Item>
<Menu.Item key={Actions.EXPORT_JOB}>Export annotations</Menu.Item>
<Menu.Item key={Actions.VIEW_ANALYTICS}>View analytics</Menu.Item>
<Menu.Divider />
<Menu.Item
key='delete'
key={Actions.DELETE}
disabled={job.type !== JobType.GROUND_TRUTH}
onClick={() => onDelete()}
>
Delete
</Menu.Item>
Expand Down

0 comments on commit 0804c45

Please sign in to comment.