Skip to content

React UI: Added button to cancel started automatic annotation #1198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
430 changes: 172 additions & 258 deletions cvat-ui/src/actions/models-actions.ts

Large diffs are not rendered by default.

52 changes: 26 additions & 26 deletions cvat-ui/src/components/tasks-page/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -87,37 +87,11 @@
padding-top: 20px;
background: $background-color-1;

/* description */
> div:nth-child(2) {
word-break: break-all;
max-height: 100%;
overflow: hidden;
}

/* open, actions */
div:nth-child(4) {
> div {
margin-right: 20px;
}

/* actions */
> div:nth-child(2) {
margin-right: 5px;
margin-top: 10px;

> div {
display: flex;
align-items: center;
}
}
}

&:hover {
border: 1px solid $border-color-hover;
}
}


.cvat-task-item-preview-wrapper {
display: flex;
justify-content: center;
Expand All @@ -131,6 +105,12 @@
}
}

.cvat-task-item-description {
word-break: break-all;
max-height: 100%;
overflow: hidden;
}

.cvat-task-progress {
width: 100%;
}
Expand Down Expand Up @@ -159,6 +139,26 @@
margin-right: 5px;
}

.close-auto-annotation-icon {
color: $danger-icon-color;
opacity: 0.7;

&:hover {
opacity: 1;
}
}

.cvat-item-open-task-actions {
margin-right: 5px;
margin-top: 10px;
display: flex;
align-items: center;
}

.cvat-item-open-task-button {
margin-right: 20px;
}

#cvat-create-task-button {
padding: 0 30px;
}
30 changes: 26 additions & 4 deletions cvat-ui/src/components/tasks-page/task-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
Icon,
Progress,
Dropdown,
Tooltip,
Modal,
} from 'antd';

import moment from 'moment';
Expand All @@ -28,6 +30,7 @@ export interface TaskItemProps {
deleted: boolean;
hidden: boolean;
activeInference: ActiveInference | null;
cancelAutoAnnotation(): void;
}

class TaskItemComponent extends React.PureComponent<TaskItemProps & RouteComponentProps> {
Expand All @@ -54,7 +57,7 @@ class TaskItemComponent extends React.PureComponent<TaskItemProps & RouteCompone
const name = `${taskInstance.name.substring(0, 70)}${taskInstance.name.length > 70 ? '...' : ''}`;

return (
<Col span={10}>
<Col span={10} className='cvat-task-item-description'>
<Text strong type='secondary'>{`#${id}: `}</Text>
<Text strong className='cvat-text-color'>{name}</Text>
<br />
Expand All @@ -76,6 +79,7 @@ class TaskItemComponent extends React.PureComponent<TaskItemProps & RouteCompone
const {
taskInstance,
activeInference,
cancelAutoAnnotation,
} = this.props;
// Count number of jobs and performed jobs
const numOfJobs = taskInstance.jobs.length;
Expand Down Expand Up @@ -132,8 +136,8 @@ class TaskItemComponent extends React.PureComponent<TaskItemProps & RouteCompone
<Text strong>Automatic annotation</Text>
</Col>
</Row>
<Row>
<Col>
<Row type='flex' justify='space-between'>
<Col span={22}>
<Progress
percent={Math.floor(activeInference.progress)}
strokeColor={{
Expand All @@ -145,6 +149,23 @@ class TaskItemComponent extends React.PureComponent<TaskItemProps & RouteCompone
size='small'
/>
</Col>
<Col span={1} className='close-auto-annotation-icon'>
<Tooltip title='Cancel automatic annotation'>
<Icon
type='close'
onClick={() => {
Modal.confirm({
title: 'You are going to cancel automatic annotation?',
content: 'Reached progress will be lost. Continue?',
okType: 'danger',
onOk() {
cancelAutoAnnotation();
},
});
}}
/>
</Tooltip>
</Col>
</Row>
</>
)}
Expand All @@ -164,6 +185,7 @@ class TaskItemComponent extends React.PureComponent<TaskItemProps & RouteCompone
<Row type='flex' justify='end'>
<Col>
<Button
className='cvat-item-open-task-button'
type='primary'
size='large'
ghost
Expand All @@ -174,7 +196,7 @@ class TaskItemComponent extends React.PureComponent<TaskItemProps & RouteCompone
</Col>
</Row>
<Row type='flex' justify='end'>
<Col>
<Col className='cvat-item-open-task-actions'>
<Text className='cvat-text-color'>Actions</Text>
<Dropdown overlay={<ActionsMenuContainer taskInstance={taskInstance} />}>
<Icon className='cvat-menu-icon' component={MenuIcon} />
Expand Down
4 changes: 2 additions & 2 deletions cvat-ui/src/containers/actions-menu/actions-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
CombinedState,
} from 'reducers/interfaces';

import { showRunModelDialog } from 'actions/models-actions';
import { modelsActions } from 'actions/models-actions';
import {
dumpAnnotationsAsync,
loadAnnotationsAsync,
Expand Down Expand Up @@ -99,7 +99,7 @@ function mapDispatchToProps(dispatch: any): DispatchToProps {
dispatch(deleteTaskAsync(taskInstance));
},
openRunModelWindow: (taskInstance: any): void => {
dispatch(showRunModelDialog(taskInstance));
dispatch(modelsActions.showRunModelDialog(taskInstance));
},
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
} from 'reducers/interfaces';
import {
getModelsAsync,
inferModelAsync,
closeRunModelDialog,
startInferenceAsync,
modelsActions,
} from 'actions/models-actions';


Expand Down Expand Up @@ -64,13 +64,13 @@ function mapDispatchToProps(dispatch: any): DispatchToProps {
},
cleanOut: boolean,
): void {
dispatch(inferModelAsync(taskInstance, model, mapping, cleanOut));
dispatch(startInferenceAsync(taskInstance, model, mapping, cleanOut));
},
getModels(): void {
dispatch(getModelsAsync());
},
closeDialog(): void {
dispatch(closeRunModelDialog());
dispatch(modelsActions.closeRunModelDialog());
},
});
}
Expand Down
25 changes: 10 additions & 15 deletions cvat-ui/src/containers/tasks-page/task-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ import {

import TaskItemComponent from 'components/tasks-page/task-item';

import {
getTasksAsync,
} from 'actions/tasks-actions';
import { getTasksAsync } from 'actions/tasks-actions';
import { cancelInferenceAsync } from 'actions/models-actions';

interface StateToProps {
deleted: boolean;
Expand All @@ -26,7 +25,8 @@ interface StateToProps {
}

interface DispatchToProps {
getTasks: (query: TasksQuery) => void;
getTasks(query: TasksQuery): void;
cancelAutoAnnotation(): void;
}

interface OwnProps {
Expand All @@ -48,23 +48,18 @@ function mapStateToProps(state: CombinedState, own: OwnProps): StateToProps {
};
}

function mapDispatchToProps(dispatch: any): DispatchToProps {
function mapDispatchToProps(dispatch: any, own: OwnProps): DispatchToProps {
return {
getTasks: (query: TasksQuery): void => {
getTasks(query: TasksQuery): void {
dispatch(getTasksAsync(query));
},
cancelAutoAnnotation(): void {
dispatch(cancelInferenceAsync(own.taskID));
},
};
}

type TasksItemContainerProps = StateToProps & DispatchToProps & OwnProps;

function TaskItemContainer(props: TasksItemContainerProps): JSX.Element {
return (
<TaskItemComponent {...props} />
);
}

export default connect(
mapStateToProps,
mapDispatchToProps,
)(TaskItemContainer);
)(TaskItemComponent);
8 changes: 8 additions & 0 deletions cvat-ui/src/reducers/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,17 @@ export enum RQStatus {
failed = 'failed',
}

export enum ModelType {
OPENVINO = 'openvino',
RCNN = 'rcnn',
MASK_RCNN = 'mask_rcnn',
}

export interface ActiveInference {
status: RQStatus;
progress: number;
error: string;
modelType: ModelType;
}

export interface ModelsState {
Expand Down Expand Up @@ -199,6 +206,7 @@ export interface NotificationsState {
starting: null | ErrorState;
deleting: null | ErrorState;
fetching: null | ErrorState;
canceling: null | ErrorState;
metaFetching: null | ErrorState;
inferenceStatusFetching: null | ErrorState;
};
Expand Down
25 changes: 16 additions & 9 deletions cvat-ui/src/reducers/models-reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
//
// SPDX-License-Identifier: MIT

import { AnyAction } from 'redux';

import { ModelsActionTypes } from 'actions/models-actions';
import { AuthActionTypes } from 'actions/auth-actions';
import { ModelsActionTypes, ModelsActions } from 'actions/models-actions';
import { AuthActionTypes, AuthActions } from 'actions/auth-actions';
import { ModelsState } from './interfaces';

const defaultState: ModelsState = {
Expand All @@ -18,7 +16,7 @@ const defaultState: ModelsState = {
inferences: {},
};

export default function (state = defaultState, action: AnyAction): ModelsState {
export default function (state = defaultState, action: ModelsActions | AuthActions): ModelsState {
switch (action.type) {
case ModelsActionTypes.GET_MODELS: {
return {
Expand Down Expand Up @@ -90,7 +88,7 @@ export default function (state = defaultState, action: AnyAction): ModelsState {
};
}
case ModelsActionTypes.GET_INFERENCE_STATUS_SUCCESS: {
const inferences = { ...state.inferences };
const { inferences } = state;
if (action.payload.activeInference.status === 'finished') {
delete inferences[action.payload.taskID];
} else {
Expand All @@ -99,16 +97,25 @@ export default function (state = defaultState, action: AnyAction): ModelsState {

return {
...state,
inferences,
inferences: { ...inferences },
};
}
case ModelsActionTypes.GET_INFERENCE_STATUS_FAILED: {
const inferences = { ...state.inferences };
const { inferences } = state;
delete inferences[action.payload.taskID];

return {
...state,
inferences: { ...inferences },
};
}
case ModelsActionTypes.CANCEL_INFERENCE_SUCCESS: {
const { inferences } = state;
delete inferences[action.payload.taskID];

return {
...state,
inferences,
inferences: { ...inferences },
};
}
case AuthActionTypes.LOGOUT_SUCCESS: {
Expand Down
20 changes: 19 additions & 1 deletion cvat-ui/src/reducers/notifications-reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const defaultState: NotificationsState = {
starting: null,
deleting: null,
fetching: null,
canceling: null,
metaFetching: null,
inferenceStatusFetching: null,
},
Expand Down Expand Up @@ -432,7 +433,7 @@ export default function (state = defaultState, action: AnyAction): Notifications
},
};
}
case ModelsActionTypes.INFER_MODEL_FAILED: {
case ModelsActionTypes.START_INFERENCE_FAILED: {
const { taskID } = action.payload;
return {
...state,
Expand All @@ -449,6 +450,23 @@ export default function (state = defaultState, action: AnyAction): Notifications
},
};
}
case ModelsActionTypes.CANCEL_INFERENCE_FAILED: {
const { taskID } = action.payload;
return {
...state,
errors: {
...state.errors,
models: {
...state.errors.models,
canceling: {
message: 'Could not cancel model inference for the '
+ `<a href="/tasks/${taskID}" target="_blank">task ${taskID}</a>`,
reason: action.payload.error.toString(),
},
},
},
};
}
case AnnotationActionTypes.GET_JOB_FAILED: {
return {
...state,
Expand Down