Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ActiveChooN committed May 17, 2021
1 parent 56a9715 commit bde6e5b
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 89 deletions.
44 changes: 5 additions & 39 deletions cvat-ui/src/actions/tasks-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ export enum TasksActionTypes {
UPDATE_TASK_SUCCESS = 'UPDATE_TASK_SUCCESS',
UPDATE_TASK_FAILED = 'UPDATE_TASK_FAILED',
HIDE_EMPTY_TASKS = 'HIDE_EMPTY_TASKS',
MOVE_TASK_TO_PROJECT = 'MOVE_TASK_TO_PROJECT',
MOVE_TASK_TO_PROJECT_SUCCESS = 'MOVE_TASK_TO_PROJECT_SUCCESS',
MOVE_TASK_TO_PROJECT_FAILED = 'MOVE_TASK_TO_PROJECT_FAILED',
SWITCH_MOVE_TASK_MODAL_VISIBLE = 'SWITCH_MOVE_TASK_MODAL_VISIBLE',
}

Expand Down Expand Up @@ -524,43 +521,12 @@ export function hideEmptyTasks(hideEmpty: boolean): AnyAction {
return action;
}

export function switchMoveTaskModalVisible(taskId: number | null = null): AnyAction {
export function switchMoveTaskModalVisible(visible: boolean, taskId: number | null = null): AnyAction {
const action = {
type: TasksActionTypes.SWITCH_MOVE_TASK_MODAL_VISIBLE,
payload: {
taskId,
},
};

return action;
}

function moveTaskToProject(): AnyAction {
const action = {
type: TasksActionTypes.MOVE_TASK_TO_PROJECT,
payload: {},
};

return action;
}

function moveTaskToProjectFailed(error: any, task: any): AnyAction {
const action = {
type: TasksActionTypes.MOVE_TASK_TO_PROJECT_FAILED,
payload: {
error,
task,
},
};

return action;
}

function moveTaskToProjectSuccess(task: any): AnyAction {
const action = {
type: TasksActionTypes.MOVE_TASK_TO_PROJECT_SUCCESS,
payload: {
task,
visible,
},
};

Expand All @@ -579,7 +545,7 @@ export function moveTaskToProjectAsync(
labelMap: LabelMap[],
): ThunkAction<Promise<void>, {}, {}, AnyAction> {
return async (dispatch: ActionCreator<Dispatch>): Promise<void> => {
dispatch(moveTaskToProject());
dispatch(updateTask());
try {
// eslint-disable-next-line no-param-reassign
taskInstance.labels = labelMap.map((mapper) => {
Expand All @@ -591,9 +557,9 @@ export function moveTaskToProjectAsync(
taskInstance.projectId = projectId;
await taskInstance.save();
const [task] = await cvat.tasks.get({ id: taskInstance.id });
dispatch(moveTaskToProjectSuccess(task));
dispatch(updateTaskSuccess(task, task.id));
} catch (error) {
dispatch(moveTaskToProjectFailed(error, taskInstance));
dispatch(updateTaskFailed(error, taskInstance));
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const core = getCore();

type Props = {
value: number | null;
excludeId?: number;
onSelect: (id: number | null) => void;
filter?: (value: Project, index: number, array: Project[]) => unknown
};

type Project = {
Expand All @@ -22,7 +22,7 @@ type Project = {
};

export default function ProjectSearchField(props: Props): JSX.Element {
const { value, excludeId, onSelect } = props;
const { value, filter, onSelect } = props;
const [searchPhrase, setSearchPhrase] = useState('');

const [projects, setProjects] = useState<Project[]>([]);
Expand All @@ -44,7 +44,10 @@ export default function ProjectSearchField(props: Props): JSX.Element {
const handleFocus = (open: boolean): void => {
if (!projects.length && open) {
core.projects.searchNames().then((result: Project[]) => {
const projectsResponse = result.filter((project) => project.id !== excludeId);
let projectsResponse = result;
if (typeof filter === 'function') {
projectsResponse = projectsResponse.filter(filter);
}
if (projectsResponse) {
setProjects(projectsResponse);
}
Expand Down
6 changes: 3 additions & 3 deletions cvat-ui/src/components/move-task-modal/label-mapper-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Tag from 'antd/lib/tag';
import Select from 'antd/lib/select';
import Checkbox from 'antd/lib/checkbox';
import { ArrowRightOutlined } from '@ant-design/icons';
import { Tooltip } from 'antd';
import CVATTooltip from 'components/common/cvat-tooltip';

export interface LabelMapperItemValue {
labelId: number;
Expand All @@ -35,11 +35,11 @@ export default function LabelMapperItem(props: LabelMapperItemProps): JSX.Elemen
<Row className='cvat-move-task-label-mapper-item' align='middle'>
<Col span={6}>
{label.name.length > 12 ? (
<Tooltip overlay={label.name}>
<CVATTooltip overlay={label.name}>
<Tag color={label.color}>
{`${label.name.slice(0, 12)}...`}
</Tag>
</Tooltip>
</CVATTooltip>
) : (
<Tag color={label.color}>
{label.name}
Expand Down
23 changes: 14 additions & 9 deletions cvat-ui/src/components/move-task-modal/move-task-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import Modal from 'antd/lib/modal';
import { Row, Col } from 'antd/lib/grid';
import Divider from 'antd/lib/divider';
import notification from 'antd/lib/notification';
import Tooltip from 'antd/lib/tooltip';
import { QuestionCircleFilled } from '@ant-design/icons';

import ProjectSearch from 'components/create-task-page/project-search-field';
import CVATTooltip from 'components/common/cvat-tooltip';
import { CombinedState } from 'reducers/interfaces';
import { closeMoveTaskModal, moveTaskToProjectAsync } from 'actions/tasks-actions';
import { switchMoveTaskModalVisible, moveTaskToProjectAsync } from 'actions/tasks-actions';
import getCore from 'cvat-core-wrapper';
import LabelMapperItem, { LabelMapperItemValue } from './label-mapper-item';

Expand Down Expand Up @@ -48,7 +48,7 @@ export default function MoveTaskModal(): JSX.Element {
};

const onCancel = (): void => {
dispatch(closeMoveTaskModal());
dispatch(switchMoveTaskModalVisible(false));
initValues();
setProject(null);
setProjectId(null);
Expand Down Expand Up @@ -90,10 +90,11 @@ export default function MoveTaskModal(): JSX.Element {
const { labels } = _project[0];
const labelValues: { [key: string]: LabelMapperItemValue } = {};
Object.entries(values).forEach(([id, label]) => {
const taskLabelName = task.labels.filter(
(_label: any) => (_label.id === label.labelId),
)[0].name;
const [autoNewLabel] = labels.filter((_label: any) => (
_label.name === task.labels.filter((_taskLabel: any) => (
_taskLabel.id === label.labelId
))[0].name
_label.name === taskLabelName
));
labelValues[id] = {
labelId: label.labelId,
Expand Down Expand Up @@ -123,17 +124,21 @@ export default function MoveTaskModal(): JSX.Element {
<span>
{`Move task ${task?.id} to project`}
{/* TODO: replace placeholder */}
<Tooltip title='Some moving proccess description here'>
<CVATTooltip title='Some moving proccess description here'>
<QuestionCircleFilled className='ant-typography-secondary' />
</Tooltip>
</CVATTooltip>
</span>
)}
className='cvat-task-move-modal'
>
<Row align='middle'>
<Col>Project:</Col>
<Col>
<ProjectSearch excludeId={task?.projectId} value={projectId} onSelect={setProjectId} />
<ProjectSearch
value={projectId}
onSelect={setProjectId}
filter={(_project) => _project.id !== task?.projectId}
/>
</Col>
</Row>
<Divider orientation='left'>Label mapping</Divider>
Expand Down
8 changes: 4 additions & 4 deletions cvat-ui/src/containers/actions-menu/actions-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
loadAnnotationsAsync,
exportDatasetAsync,
deleteTaskAsync,
showMoveTaskModal,
switchMoveTaskModalVisible,
} from 'actions/tasks-actions';

interface OwnProps {
Expand Down Expand Up @@ -78,8 +78,8 @@ function mapDispatchToProps(dispatch: any): DispatchToProps {
openRunModelWindow: (taskInstance: any): void => {
dispatch(modelsActions.showRunModelDialog(taskInstance));
},
openMoveTaskToProjectWindow: (taskInstance: any): void => {
dispatch(showMoveTaskModal(taskInstance));
openMoveTaskToProjectWindow: (taskId: number): void => {
dispatch(switchMoveTaskModalVisible(true, taskId));
},
};
}
Expand Down Expand Up @@ -132,7 +132,7 @@ function ActionsMenuContainer(props: OwnProps & StateToProps & DispatchToProps):
} else if (action === Actions.RUN_AUTO_ANNOTATION) {
openRunModelWindow(taskInstance);
} else if (action === Actions.MOVE_TASK_TO_PROJECT) {
openMoveTaskToProjectWindow(taskInstance);
openMoveTaskToProjectWindow(taskInstance.id);
}
}
}
Expand Down
32 changes: 1 addition & 31 deletions cvat-ui/src/reducers/tasks-reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,41 +360,11 @@ export default (state: TasksState = defaultState, action: AnyAction): TasksState
...state,
moveTask: {
...state.moveTask,
modalVisible: !state.moveTask.modalVisible,
modalVisible: action.payload.visible,
taskId: action.payload.taskId,
},
};
}
case TasksActionTypes.MOVE_TASK_TO_PROJECT: {
return {
...state,
updating: true,
};
}
case TasksActionTypes.MOVE_TASK_TO_PROJECT_FAILED: {
return {
...state,
updating: false,
};
}
case TasksActionTypes.MOVE_TASK_TO_PROJECT_SUCCESS: {
return {
...state,
updating: false,
current: state.current.map(
(task): Task => {
if (task.instance.id === action.payload.task.id) {
return {
...task,
instance: action.payload.task,
};
}

return task;
},
),
};
}
case BoundariesActionTypes.RESET_AFTER_ERROR:
case AuthActionTypes.LOGOUT_SUCCESS: {
return { ...defaultState };
Expand Down

0 comments on commit bde6e5b

Please sign in to comment.