Skip to content
This repository was archived by the owner on May 30, 2023. It is now read-only.

Commit e586004

Browse files
committed
Merge branch 'feat/annotation_upload_data' into feat/annotation
2 parents 6e226bc + 08ccdbb commit e586004

13 files changed

Lines changed: 304 additions & 406 deletions

File tree

src/components/Annotation/Formart/labelme/index.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,6 @@ export const importAnnotation = (
136136
label: { label: shape.label },
137137
},
138138
};
139-
console.log(
140-
" drawObjectById[drawObject.data.id]",
141-
drawObjectById[drawObject.data.id]
142-
);
143139
} else if (shape.shape_type === "ellipse") {
144140
const drawObject = createEllipse({ x: 0, y: 0 });
145141
const points = shape.points as EllipseFormatter;

src/components/CloneProjectModal/index.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
selectorDialogCloneProjectToAnnotation,
2222
selectorIsCloningProjectToAnnotation,
2323
} from "reduxes/annotationProject/selector";
24+
import { useEffect } from "react";
2425

2526
const CloneProjectModal = function () {
2627
const dispatch = useDispatch();
@@ -30,15 +31,23 @@ const CloneProjectModal = function () {
3031
const {
3132
register,
3233
handleSubmit,
34+
setValue,
3335
formState: { errors },
3436
} = useForm<CloneProjectToAnnotationFields>({
3537
mode: "onChange",
36-
defaultValues: {
37-
fromProjectName: dialogCloneProjectToAnnotation.projectName,
38-
annotationProjectName: "",
39-
annotationProjectDescription: "",
40-
},
4138
});
39+
useEffect(() => {
40+
setValue(
41+
"fromProjectName",
42+
dialogCloneProjectToAnnotation.projectName
43+
? dialogCloneProjectToAnnotation.projectName
44+
: ""
45+
);
46+
if (!dialogCloneProjectToAnnotation.isShow) {
47+
setValue("annotationProjectName", "");
48+
setValue("annotationProjectDescription", "");
49+
}
50+
}, [dialogCloneProjectToAnnotation]);
4251

4352
const isLoading = useSelector(selectorIsCloningProjectToAnnotation);
4453
const onSubmit = (fields: CloneProjectToAnnotationFields) => {

src/reduxes/annotationProject/action.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { SetIsOpenDeleteConfirmPayload } from "reduxes/project/type";
1+
import {
2+
SetIsOpenDeleteConfirmPayload,
3+
UpdateProjectStatisticPayload,
4+
} from "reduxes/project/type";
25
import {
36
CLONE_PROJECT_TO_ANNOTATION,
47
DELETE_ANNOTATION_PROJECT,
@@ -10,6 +13,7 @@ import {
1013
SET_CURRENT_ANNOTATION_PROJECT,
1114
SET_IS_OPEN_DELETE_ANNOTATION_PROJECT_CONFIRM,
1215
SHOW_DIALOG_CLONE_PROJECT_TO_ANNOTATION,
16+
UPDATE_STATISTIC_PROJECT,
1317
} from "./constants";
1418
import {
1519
CloneProjectToAnnotationProps,
@@ -83,3 +87,9 @@ export const setAnnotationFiles = (
8387
type: SET_ANNOTATION_FILES,
8488
payload,
8589
});
90+
export const updateCurrentAnnotationProjectStatistic = (
91+
payload: UpdateProjectStatisticPayload
92+
) => ({
93+
type: UPDATE_STATISTIC_PROJECT,
94+
payload,
95+
});

src/reduxes/annotationProject/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ export const DELETE_ANNOTATION_PROJECT = asyncAction(
2323
export const SET_IS_OPEN_DELETE_ANNOTATION_PROJECT_CONFIRM =
2424
"SET_IS_OPEN_DELETE_ANNOTATION_PROJECT_CONFIRM";
2525
export const SET_ANNOTATION_FILES = "SET_ANNOTATION_FILES";
26+
export const UPDATE_STATISTIC_PROJECT = "UPDATE_STATISTIC_PROJECT";

src/reduxes/annotationProject/reducer.ts

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
DeleteProjectSucceedPayload,
33
SetIsOpenDeleteConfirmPayload,
4+
UpdateProjectStatisticPayload,
45
} from "reduxes/project/type";
56
import { objectIndexOf } from "utils/general";
67
import {
@@ -14,11 +15,11 @@ import {
1415
SET_CURRENT_ANNOTATION_PROJECT,
1516
SET_IS_OPEN_DELETE_ANNOTATION_PROJECT_CONFIRM,
1617
SHOW_DIALOG_CLONE_PROJECT_TO_ANNOTATION,
18+
UPDATE_STATISTIC_PROJECT,
1719
} from "./constants";
1820
import {
1921
AnnotationFilesApi,
2022
AnnotationProjectReducer,
21-
FetchAnnotationFilesProps,
2223
SetAnnotationFilesProps,
2324
SetCurrentAnnotationProjectProps,
2425
SetDialogCloneProjectToAnnotationProps,
@@ -209,6 +210,88 @@ const annotationProjectReducer = (
209210
deleteConfirmDialogInfo: null,
210211
};
211212
}
213+
case UPDATE_STATISTIC_PROJECT: {
214+
const { projectId, updateInfo } =
215+
payload as UpdateProjectStatisticPayload;
216+
if (
217+
state.currentProjectInfo &&
218+
state.currentProjectInfo.project_id === projectId
219+
) {
220+
const { groups } = state.currentProjectInfo;
221+
const { fileInfo, typeMethod } = updateInfo;
222+
const { isExist, isDelete, size, sizeOld } = fileInfo;
223+
let newSize = 0;
224+
let newCount = 0;
225+
if (groups) {
226+
newSize = groups[typeMethod]?.size || 0;
227+
newCount = groups[typeMethod]?.count || 0;
228+
if (isDelete) {
229+
newSize -= size;
230+
newCount -= 1;
231+
} else if (isExist) {
232+
newSize += fileInfo.size - (sizeOld || 0);
233+
} else {
234+
newSize += size;
235+
newCount += 1;
236+
}
237+
238+
return {
239+
...state,
240+
currentProjectInfo: {
241+
...state.currentProjectInfo,
242+
groups: {
243+
...groups,
244+
[typeMethod]: {
245+
...groups[typeMethod],
246+
size: newSize,
247+
count: newCount,
248+
},
249+
},
250+
},
251+
};
252+
}
253+
254+
newSize = 0;
255+
newCount = 0;
256+
if (isExist) {
257+
newSize += fileInfo.size - (sizeOld || 0);
258+
} else {
259+
newSize += size;
260+
newCount += 1;
261+
}
262+
263+
const matchProjectIndex = objectIndexOf(
264+
state.listProjects,
265+
projectId,
266+
"project_id"
267+
);
268+
269+
const newListProjects = [...state.listProjects];
270+
if (matchProjectIndex > -1) {
271+
let targetGroups = newListProjects[matchProjectIndex].groups;
272+
if (!targetGroups) {
273+
targetGroups = {};
274+
}
275+
targetGroups[typeMethod] = {
276+
size: newSize,
277+
count: newCount,
278+
data_number: [0, 0, 0],
279+
};
280+
}
281+
const currentProjectInfo = {
282+
...state.currentProjectInfo,
283+
};
284+
currentProjectInfo.groups[typeMethod] = {
285+
size: newSize,
286+
count: newCount,
287+
};
288+
return {
289+
...state,
290+
currentProjectInfo,
291+
};
292+
}
293+
return state;
294+
}
212295
}
213296
return state;
214297
};

src/reduxes/annotationProject/type.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ImageSourceType } from "reduxes/album/type";
22
import {
33
GENERATE_PROJECT_STATUS_TYPE,
4+
GroupProjectInfo,
45
SetIsOpenDeleteConfirmPayload,
56
} from "reduxes/project/type";
67

@@ -80,6 +81,7 @@ export interface GroupAnnotationProjectInfo {
8081
size: number;
8182
}
8283
export interface ApiListAnnotationProjectsItem {
84+
groups: GroupProjectInfo;
8385
project_id: string;
8486
project_name: string;
8587
gen_status: GENERATE_PROJECT_STATUS_TYPE;

src/reduxes/annotationmanager/reducer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const inititalState: AnnotationManagerReducer = {
2626
idDrawObjectByImageName: {},
2727
images: {},
2828
currentPreviewImageName: null,
29-
labelClassPropertiesByLabelClass: initialLabelClassPropertiesByLabelClass,
29+
labelClassPropertiesByLabelClass: {}, // initialLabelClassPropertiesByLabelClass,
3030
dialogClassManageModal: {
3131
isOpen: false,
3232
},

src/routes/AnnotationPage/ImagePreview/index.tsx

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -120,31 +120,31 @@ const ImagePreview = function () {
120120
// });
121121
}, []);
122122

123-
const onDrop = (acceptedFiles: File[]) => {
124-
if (acceptedFiles && acceptedFiles.length > 0) {
125-
for (const file of acceptedFiles) {
126-
loadImage(file).then(({ image, fileName }) => {
127-
const property: AnnotationImagesProperty = {
128-
image: file,
129-
width: image.width,
130-
height: image.height,
131-
};
132-
dispatch(
133-
addImagesToAnnotation({ annotationImagesProperties: [property] })
134-
);
135-
if (!currentPreviewImageName) {
136-
dispatch(changePreviewImage({ imageName: acceptedFiles[0].name }));
137-
}
138-
});
139-
}
140-
}
141-
};
142-
const dropZone = useDropzone({
143-
onDrop,
144-
accept: IMAGE_EXTENSIONS.join(","),
145-
noDragEventsBubbling: true,
146-
});
147-
const { getRootProps, isDragActive, getInputProps } = dropZone;
123+
// const onDrop = (acceptedFiles: File[]) => {
124+
// if (acceptedFiles && acceptedFiles.length > 0) {
125+
// for (const file of acceptedFiles) {
126+
// loadImage(file).then(({ image, fileName }) => {
127+
// const property: AnnotationImagesProperty = {
128+
// image: file,
129+
// width: image.width,
130+
// height: image.height,
131+
// };
132+
// dispatch(
133+
// addImagesToAnnotation({ annotationImagesProperties: [property] })
134+
// );
135+
// if (!currentPreviewImageName) {
136+
// dispatch(changePreviewImage({ imageName: acceptedFiles[0].name }));
137+
// }
138+
// });
139+
// }
140+
// }
141+
// };
142+
// const dropZone = useDropzone({
143+
// onDrop,
144+
// accept: IMAGE_EXTENSIONS.join(","),
145+
// noDragEventsBubbling: true,
146+
// });
147+
// const { getRootProps, isDragActive, getInputProps } = dropZone;
148148
// const fileThumbByImageName = useMemo(() => {
149149
// const thumbs: Record<string, string> = {};
150150
// Object.entries(annotationManagerImages).map(
@@ -179,7 +179,7 @@ const ImagePreview = function () {
179179
}
180180
return (
181181
<>
182-
<Box
182+
{/* <Box
183183
sx={{
184184
background: `url("/assets/images/upload-image.png") no-repeat center`,
185185
border: "1px solid",
@@ -194,7 +194,7 @@ const ImagePreview = function () {
194194
{...getRootProps()}
195195
>
196196
<input {...getInputProps()} />
197-
</Box>
197+
</Box> */}
198198
<List
199199
sx={{
200200
maxWidth: "90%",

0 commit comments

Comments
 (0)