Skip to content

Commit

Permalink
Fixed cannot read property 'annotations' of null
Browse files Browse the repository at this point in the history
  • Loading branch information
bsekachev committed May 7, 2024
1 parent 6a85e61 commit 89ec2db
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 42 deletions.
9 changes: 8 additions & 1 deletion cvat-ui/src/actions/annotation-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -869,12 +869,19 @@ export function resetCanvas(): AnyAction {
}

export function closeJob(): ThunkAction {
return async (dispatch: ActionCreator<Dispatch>): Promise<void> => {
return async (dispatch: ActionCreator<Dispatch>, getState): Promise<void> => {
const state = getState();
const { instance: canvasInstance } = state.annotation.canvas;
const { jobInstance } = receiveAnnotationsParameters();

if (jobInstance) {
await jobInstance.close();
}

if (canvasInstance) {
canvasInstance.destroy();
}

dispatch({
type: AnnotationActionTypes.CLOSE_JOB,
});
Expand Down
26 changes: 12 additions & 14 deletions cvat-ui/src/actions/import-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

import { createAction, ActionUnion, ThunkAction } from 'utils/redux';
import { CombinedState } from 'reducers';
import { getCore, Storage } from 'cvat-core-wrapper';
import {
getCore, Storage, Job, Task, Project,
} from 'cvat-core-wrapper';
import { EventScope } from 'cvat-logger';
import { getProjectsAsync } from './projects-actions';
import { AnnotationActionTypes, fetchAnnotationsAsync } from './annotation-actions';
Expand Down Expand Up @@ -36,10 +38,10 @@ export const importActions = {
importDataset: (instance: any, format: string) => (
createAction(ImportActionTypes.IMPORT_DATASET, { instance, format })
),
importDatasetSuccess: (instance: any, resource: 'dataset' | 'annotation') => (
importDatasetSuccess: (instance: Job | Task | Project, resource: 'dataset' | 'annotation') => (
createAction(ImportActionTypes.IMPORT_DATASET_SUCCESS, { instance, resource })
),
importDatasetFailed: (instance: any, resource: 'dataset' | 'annotation', error: any) => (
importDatasetFailed: (instance: Job | Task | Project, resource: 'dataset' | 'annotation', error: any) => (
createAction(ImportActionTypes.IMPORT_DATASET_FAILED, {
instance,
resource,
Expand Down Expand Up @@ -112,22 +114,18 @@ export const importDatasetAsync = (
await instance.logger.log(EventScope.uploadAnnotations);
await instance.annotations.clear(true);
await instance.actions.clear();
const history = await instance.actions.get();

// first set empty objects list
// to escape some problems in canvas when shape with the same
// clientID has different type (polygon, rectangle) for example
dispatch({
type: AnnotationActionTypes.UPLOAD_JOB_ANNOTATIONS_SUCCESS,
payload: {
states: [],
history,
},
});
dispatch({ type: AnnotationActionTypes.UPLOAD_JOB_ANNOTATIONS_SUCCESS });

setTimeout(() => {
dispatch(fetchAnnotationsAsync());
});
const relevantInstance = getState().annotation.job.instance;
if (relevantInstance && relevantInstance.id === instance.id) {
setTimeout(() => {
dispatch(fetchAnnotationsAsync());
});
}
}
} catch (error) {
dispatch(importActions.importDatasetFailed(instance, resource, error));
Expand Down
8 changes: 2 additions & 6 deletions cvat-ui/src/components/annotation-page/annotation-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// SPDX-License-Identifier: MIT

import React, { useEffect } from 'react';
import { useHistory } from 'react-router';
import Layout from 'antd/lib/layout';
import Result from 'antd/lib/result';
import Spin from 'antd/lib/spin';
Expand Down Expand Up @@ -44,7 +43,6 @@ export default function AnnotationPageComponent(props: Props): JSX.Element {
const prevJob = usePrevious(job);
const prevFetching = usePrevious(fetching);

const history = useHistory();
useEffect(() => {
saveLogs();
const root = window.document.getElementById('root');
Expand All @@ -54,13 +52,11 @@ export default function AnnotationPageComponent(props: Props): JSX.Element {

return () => {
saveLogs();
closeJob();

if (root) {
root.style.minHeight = '';
}

if (!history.location.pathname.includes('/jobs')) {
closeJob();
}
};
}, []);

Expand Down
14 changes: 6 additions & 8 deletions cvat-ui/src/reducers/annotation-reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -779,15 +779,16 @@ export default (state = defaultState, action: AnyAction): AnnotationState => {
};
}
case AnnotationActionTypes.UPLOAD_JOB_ANNOTATIONS_SUCCESS: {
const { states, history } = action.payload;

return {
...state,
annotations: {
...state.annotations,
history,
states,
history: { undo: [], redo: [] },
states: [],
activatedStateID: null,
activatedElementID: null,
activatedAttributeID: null,
highlightedConflict: null,
collapsed: {},
},
};
Expand Down Expand Up @@ -1083,10 +1084,7 @@ export default (state = defaultState, action: AnyAction): AnnotationState => {
}
case AnnotationActionTypes.CLOSE_JOB:
case AuthActionTypes.LOGOUT_SUCCESS: {
if (state.canvas.instance) {
state.canvas.instance.destroy();
}
return { ...defaultState };
return defaultState;
}
default: {
return state;
Expand Down
17 changes: 12 additions & 5 deletions cvat-ui/src/reducers/notifications-reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { AnyAction } from 'redux';

import { ServerError } from 'cvat-core-wrapper';
import { Project, ServerError, Task } from 'cvat-core-wrapper';
import { AuthActionTypes } from 'actions/auth-actions';
import { FormatsActionTypes } from 'actions/formats-actions';
import { ModelsActionTypes } from 'actions/models-actions';
Expand Down Expand Up @@ -567,10 +567,17 @@ export default function (state = defaultState, action: AnyAction): Notifications
}
case ImportActionTypes.IMPORT_DATASET_SUCCESS: {
const { instance, resource } = action.payload;
const message = resource === 'annotation' ?
'Annotations have been loaded to the ' +
`[task ${instance.taskId || instance.id}](/tasks/${instance.taskId || instance.id}) ` :
`Dataset was imported to the [project ${instance.id}](/projects/${instance.id})`;
let message = resource === 'annotation' ?
'Annotations have been loaded to the ' :
'Dataset was imported to the ';
if (instance instanceof Project) {
message += `[Project ${instance.id}](/projects/${instance.id})`;
} else if (instance instanceof Task) {
message += `[Task ${instance.id}](/tasks/${instance.id})`;
} else {
message += `[Job ${instance.id}](/jobs/${instance.id})`;
}

return {
...state,
messages: {
Expand Down
2 changes: 1 addition & 1 deletion cvat-ui/src/reducers/review-reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export default function (state: ReviewState = defaultState, action: any): Review
}
case AnnotationActionTypes.CLOSE_JOB:
case AuthActionTypes.LOGOUT_SUCCESS: {
return { ...defaultState };
return defaultState;
}
default:
return state;
Expand Down
8 changes: 1 addition & 7 deletions cvat-ui/src/reducers/tasks-reducer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (C) 2020-2022 Intel Corporation
// Copyright (C) 2022-2023 CVAT.ai Corporation
// Copyright (C) 2022-2024 CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT

Expand All @@ -8,7 +8,6 @@ import { BoundariesActionTypes } from 'actions/boundaries-actions';
import { TasksActionTypes } from 'actions/tasks-actions';
import { AuthActionTypes } from 'actions/auth-actions';

import { AnnotationActionTypes } from 'actions/annotation-actions';
import { TasksState } from '.';

const defaultState: TasksState = {
Expand Down Expand Up @@ -136,11 +135,6 @@ export default (state: TasksState = defaultState, action: AnyAction): TasksState
},
};
}
case AnnotationActionTypes.CLOSE_JOB: {
return {
...state,
};
}
case BoundariesActionTypes.RESET_AFTER_ERROR:
case AuthActionTypes.LOGOUT_SUCCESS: {
return { ...defaultState };
Expand Down

0 comments on commit 89ec2db

Please sign in to comment.