Fixed failure after updating a label on cvat.org (#2199)

* Fixed failure after updating a label on cvat.org (the bug is related with low bandwidth)

* Removed extra line of code

* Updated NPM version

* Fix test

* Better fix for the test
main
Boris Sekachev 5 years ago committed by GitHub
parent 4d3a93a803
commit acfb1a492d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -251,7 +251,7 @@
const data = JSON.stringify({ const data = JSON.stringify({
old_password: oldPassword, old_password: oldPassword,
new_password1: newPassword1, new_password1: newPassword1,
new_password2:newPassword2, new_password2: newPassword2,
}); });
await Axios.post(`${config.backendAPI}/auth/password/change`, data, { await Axios.post(`${config.backendAPI}/auth/password/change`, data, {
proxy: config.proxy, proxy: config.proxy,
@ -280,13 +280,13 @@
} }
} }
async function resetPassword(newPassword1, newPassword2, uid, token) { async function resetPassword(newPassword1, newPassword2, uid, _token) {
try { try {
const data = JSON.stringify({ const data = JSON.stringify({
new_password1: newPassword1, new_password1: newPassword1,
new_password2: newPassword2, new_password2: newPassword2,
uid, uid,
token, token: _token,
}); });
await Axios.post(`${config.backendAPI}/auth/password/reset/confirm`, data, { await Axios.post(`${config.backendAPI}/auth/password/reset/confirm`, data, {
proxy: config.proxy, proxy: config.proxy,
@ -456,7 +456,7 @@
throw generateError(errorData); throw generateError(errorData);
} }
onUpdate('The data is being uploaded to the server..'); onUpdate('The data are being uploaded to the server..');
try { try {
await Axios.post(`${backendAPI}/tasks/${response.data.id}/data`, taskData, { await Axios.post(`${backendAPI}/tasks/${response.data.id}/data`, taskData, {
proxy: config.proxy, proxy: config.proxy,

@ -1,6 +1,6 @@
{ {
"name": "cvat-ui", "name": "cvat-ui",
"version": "1.9.6", "version": "1.9.7",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

@ -1,6 +1,6 @@
{ {
"name": "cvat-ui", "name": "cvat-ui",
"version": "1.9.6", "version": "1.9.7",
"description": "CVAT single-page application", "description": "CVAT single-page application",
"main": "src/index.tsx", "main": "src/index.tsx",
"scripts": { "scripts": {

@ -458,9 +458,7 @@ function updateTask(): AnyAction {
function updateTaskSuccess(task: any): AnyAction { function updateTaskSuccess(task: any): AnyAction {
const action = { const action = {
type: TasksActionTypes.UPDATE_TASK_SUCCESS, type: TasksActionTypes.UPDATE_TASK_SUCCESS,
payload: { payload: { task },
task,
},
}; };
return action; return action;
@ -469,23 +467,28 @@ function updateTaskSuccess(task: any): AnyAction {
function updateTaskFailed(error: any, task: any): AnyAction { function updateTaskFailed(error: any, task: any): AnyAction {
const action = { const action = {
type: TasksActionTypes.UPDATE_TASK_FAILED, type: TasksActionTypes.UPDATE_TASK_FAILED,
payload: { payload: { error, task },
error,
task,
},
}; };
return action; return action;
} }
export function updateTaskAsync(taskInstance: any): export function updateTaskAsync(taskInstance: any):
ThunkAction<Promise<void>, {}, {}, AnyAction> { ThunkAction<Promise<void>, CombinedState, {}, AnyAction> {
return async (dispatch: ActionCreator<Dispatch>): Promise<void> => { return async (
dispatch: ActionCreator<Dispatch>,
getState: () => CombinedState,
): Promise<void> => {
try { try {
dispatch(updateTask()); dispatch(updateTask());
const currentUser = getState().auth.user;
await taskInstance.save(); await taskInstance.save();
const [task] = await cvat.tasks.get({ id: taskInstance.id }); const nextUser = getState().auth.user;
dispatch(updateTaskSuccess(task)); const userFetching = getState().auth.fetching;
if (!userFetching && nextUser && currentUser.username === nextUser.username) {
const [task] = await cvat.tasks.get({ id: taskInstance.id });
dispatch(updateTaskSuccess(task));
}
} catch (error) { } catch (error) {
// try abort all changes // try abort all changes
let task = null; let task = null;

@ -13,10 +13,7 @@ interface Props {
} }
export default function ConstructorUpdater(props: Props): JSX.Element { export default function ConstructorUpdater(props: Props): JSX.Element {
const { const { label, onUpdate } = props;
label,
onUpdate,
} = props;
return ( return (
<div className='cvat-label-constructor-updater'> <div className='cvat-label-constructor-updater'>

@ -49,14 +49,9 @@ class LabelForm extends React.PureComponent<Props, {}> {
} }
private handleSubmit = (e: React.FormEvent): void => { private handleSubmit = (e: React.FormEvent): void => {
e.preventDefault(); const { form, label, onSubmit } = this.props;
const {
form,
label,
onSubmit,
} = this.props;
e.preventDefault();
form.validateFields((error, formValues): void => { form.validateFields((error, formValues): void => {
if (!error) { if (!error) {
onSubmit({ onSubmit({
@ -344,11 +339,7 @@ class LabelForm extends React.PureComponent<Props, {}> {
} }
private renderAttribute = (key: number, index: number): JSX.Element => { private renderAttribute = (key: number, index: number): JSX.Element => {
const { const { label, form } = this.props;
label,
form,
} = this.props;
const attr = (label && index < label.attributes.length const attr = (label && index < label.attributes.length
? label.attributes[index] ? label.attributes[index]
: null); : null);
@ -387,11 +378,7 @@ class LabelForm extends React.PureComponent<Props, {}> {
}; };
private renderLabelNameInput(): JSX.Element { private renderLabelNameInput(): JSX.Element {
const { const { label, form, labelNames } = this.props;
label,
form,
labelNames,
} = this.props;
const value = label ? label.name : ''; const value = label ? label.name : '';
const locked = label ? label.id >= 0 : false; const locked = label ? label.id >= 0 : false;
@ -532,10 +519,7 @@ class LabelForm extends React.PureComponent<Props, {}> {
} }
public render(): JSX.Element { public render(): JSX.Element {
const { const { label, form } = this.props;
label,
form,
} = this.props;
form.getFieldDecorator('keys', { form.getFieldDecorator('keys', {
initialValue: label initialValue: label

@ -102,24 +102,15 @@ export default class LabelsEditor
} }
} }
this.setState({ this.setState({ unsavedLabels, savedLabels });
unsavedLabels,
savedLabels,
});
this.handleSubmit(savedLabels, unsavedLabels); this.handleSubmit(savedLabels, unsavedLabels);
}; };
private handleCreate = (label: Label | null): void => { private handleCreate = (label: Label | null): void => {
if (label === null) { if (label === null) {
this.setState({ this.setState({ constructorMode: ConstructorMode.SHOW });
constructorMode: ConstructorMode.SHOW,
});
} else { } else {
const { const { unsavedLabels, savedLabels } = this.state;
unsavedLabels,
savedLabels,
} = this.state;
const newUnsavedLabels = [ const newUnsavedLabels = [
...unsavedLabels, ...unsavedLabels,
{ {
@ -128,19 +119,13 @@ export default class LabelsEditor
}, },
]; ];
this.setState({ this.setState({ unsavedLabels: newUnsavedLabels });
unsavedLabels: newUnsavedLabels,
});
this.handleSubmit(savedLabels, newUnsavedLabels); this.handleSubmit(savedLabels, newUnsavedLabels);
} }
}; };
private handleUpdate = (label: Label | null): void => { private handleUpdate = (label: Label | null): void => {
const { const { savedLabels, unsavedLabels } = this.state;
savedLabels,
unsavedLabels,
} = this.state;
if (label) { if (label) {
const filteredSavedLabels = savedLabels const filteredSavedLabels = savedLabels
@ -163,9 +148,7 @@ export default class LabelsEditor
this.handleSubmit(filteredSavedLabels, filteredUnsavedLabels); this.handleSubmit(filteredSavedLabels, filteredUnsavedLabels);
} else { } else {
this.setState({ this.setState({ constructorMode: ConstructorMode.SHOW });
constructorMode: ConstructorMode.SHOW,
});
} }
}; };
@ -178,19 +161,13 @@ export default class LabelsEditor
}); });
} }
const { const { unsavedLabels, savedLabels } = this.state;
unsavedLabels,
savedLabels,
} = this.state;
const filteredUnsavedLabels = unsavedLabels.filter( const filteredUnsavedLabels = unsavedLabels.filter(
(_label: Label): boolean => _label.id !== label.id, (_label: Label): boolean => _label.id !== label.id,
); );
this.setState({ this.setState({ unsavedLabels: filteredUnsavedLabels });
unsavedLabels: filteredUnsavedLabels,
});
this.handleSubmit(savedLabels, filteredUnsavedLabels); this.handleSubmit(savedLabels, filteredUnsavedLabels);
}; };
@ -214,10 +191,8 @@ export default class LabelsEditor
} }
const { onSubmit } = this.props; const { onSubmit } = this.props;
const output = []; const output = savedLabels.concat(unsavedLabels)
for (const label of savedLabels.concat(unsavedLabels)) { .map((label: Label): any => transformLabel(label));
output.push(transformLabel(label));
}
onSubmit(output); onSubmit(output);
} }

@ -48,10 +48,7 @@ class RawViewer extends React.PureComponent<Props> {
}; };
private handleSubmit = (e: React.FormEvent): void => { private handleSubmit = (e: React.FormEvent): void => {
const { const { form, onSubmit } = this.props;
form,
onSubmit,
} = this.props;
e.preventDefault(); e.preventDefault();
form.validateFields((error, values): void => { form.validateFields((error, values): void => {

@ -19,6 +19,7 @@ import TopBarComponent from './top-bar';
interface TaskPageComponentProps { interface TaskPageComponentProps {
task: Task | null | undefined; task: Task | null | undefined;
fetching: boolean; fetching: boolean;
updating: boolean;
deleteActivity: boolean | null; deleteActivity: boolean | null;
installedGit: boolean; installedGit: boolean;
getTask: () => void; getTask: () => void;
@ -28,10 +29,7 @@ type Props = TaskPageComponentProps & RouteComponentProps<{id: string}>;
class TaskPageComponent extends React.PureComponent<Props> { class TaskPageComponent extends React.PureComponent<Props> {
public componentDidUpdate(): void { public componentDidUpdate(): void {
const { const { deleteActivity, history } = this.props;
deleteActivity,
history,
} = this.props;
if (deleteActivity) { if (deleteActivity) {
history.replace('/tasks'); history.replace('/tasks');
@ -42,11 +40,12 @@ class TaskPageComponent extends React.PureComponent<Props> {
const { const {
task, task,
fetching, fetching,
updating,
getTask, getTask,
} = this.props; } = this.props;
if (task === null) { if (task === null || updating) {
if (!fetching) { if (task === null && !fetching) {
getTask(); getTask();
} }

@ -38,7 +38,9 @@ function mapStateToProps(state: CombinedState, own: OwnProps): StateToProps {
function mapDispatchToProps(dispatch: any, own: OwnProps): DispatchToProps { function mapDispatchToProps(dispatch: any, own: OwnProps): DispatchToProps {
return { return {
onTaskUpdate: (taskInstance: any): void => dispatch(updateTaskAsync(taskInstance)), onTaskUpdate(taskInstance: any): void {
dispatch(updateTaskAsync(taskInstance));
},
cancelAutoAnnotation(): void { cancelAutoAnnotation(): void {
dispatch(cancelInferenceAsync(own.task.instance.id)); dispatch(cancelInferenceAsync(own.task.instance.id));
}, },

@ -19,6 +19,7 @@ type Props = RouteComponentProps<{id: string}>;
interface StateToProps { interface StateToProps {
task: Task | null | undefined; task: Task | null | undefined;
fetching: boolean; fetching: boolean;
updating: boolean;
deleteActivity: boolean | null; deleteActivity: boolean | null;
installedGit: boolean; installedGit: boolean;
} }
@ -30,7 +31,7 @@ interface DispatchToProps {
function mapStateToProps(state: CombinedState, own: Props): StateToProps { function mapStateToProps(state: CombinedState, own: Props): StateToProps {
const { list } = state.plugins; const { list } = state.plugins;
const { tasks } = state; const { tasks } = state;
const { gettingQuery } = tasks; const { gettingQuery, fetching, updating } = tasks;
const { deletes } = tasks.activities; const { deletes } = tasks.activities;
const id = +own.match.params.id; const id = +own.match.params.id;
@ -49,7 +50,8 @@ function mapStateToProps(state: CombinedState, own: Props): StateToProps {
return { return {
task, task,
deleteActivity, deleteActivity,
fetching: state.tasks.fetching, fetching,
updating,
installedGit: list.GIT_INTEGRATION, installedGit: list.GIT_INTEGRATION,
}; };
} }

@ -41,6 +41,7 @@ export interface Task {
export interface TasksState { export interface TasksState {
initialized: boolean; initialized: boolean;
fetching: boolean; fetching: boolean;
updating: boolean;
hideEmpty: boolean; hideEmpty: boolean;
gettingQuery: TasksQuery; gettingQuery: TasksQuery;
count: number; count: number;

@ -12,6 +12,7 @@ import { TasksState, Task } from './interfaces';
const defaultState: TasksState = { const defaultState: TasksState = {
initialized: false, initialized: false,
fetching: false, fetching: false,
updating: false,
hideEmpty: false, hideEmpty: false,
count: 0, count: 0,
current: [], current: [],
@ -290,11 +291,13 @@ export default (state: TasksState = defaultState, action: AnyAction): TasksState
case TasksActionTypes.UPDATE_TASK: { case TasksActionTypes.UPDATE_TASK: {
return { return {
...state, ...state,
updating: true,
}; };
} }
case TasksActionTypes.UPDATE_TASK_SUCCESS: { case TasksActionTypes.UPDATE_TASK_SUCCESS: {
return { return {
...state, ...state,
updating: false,
current: state.current.map((task): Task => { current: state.current.map((task): Task => {
if (task.instance.id === action.payload.task.id) { if (task.instance.id === action.payload.task.id) {
return { return {
@ -310,6 +313,7 @@ export default (state: TasksState = defaultState, action: AnyAction): TasksState
case TasksActionTypes.UPDATE_TASK_FAILED: { case TasksActionTypes.UPDATE_TASK_FAILED: {
return { return {
...state, ...state,
updating: false,
current: state.current.map((task): Task => { current: state.current.map((task): Task => {
if (task.instance.id === action.payload.task.id) { if (task.instance.id === action.payload.task.id) {
return { return {

Loading…
Cancel
Save