Skip to content

Commit 6a2c79f

Browse files
committed
fix(frontend): accurate export options by the annotation tool
1 parent 3c10590 commit 6a2c79f

File tree

3 files changed

+35
-72
lines changed

3 files changed

+35
-72
lines changed

apps/frontend/src/components/ExportPortal/index.tsx

+35-39
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,19 @@ export const exportDescriptionMapping = {
2020
[ExportType.MASK]: '面向图像分割(多边形)任务',
2121
};
2222

23-
const availableOptions = {
24-
[MediaType.IMAGE]: [
25-
{
26-
label: ExportType.JSON,
27-
value: ExportType.JSON,
28-
},
29-
{
30-
label: ExportType.COCO,
31-
value: ExportType.COCO,
32-
},
33-
{
34-
label: ExportType.MASK,
35-
value: ExportType.MASK,
36-
},
37-
],
38-
[MediaType.VIDEO]: [
39-
{
40-
label: ExportType.JSON,
41-
value: ExportType.JSON,
42-
},
43-
],
44-
[MediaType.AUDIO]: [
45-
{
46-
label: ExportType.JSON,
47-
value: ExportType.JSON,
48-
},
49-
],
23+
const optionMapping = {
24+
[ExportType.JSON]: {
25+
label: ExportType.JSON,
26+
value: ExportType.JSON,
27+
},
28+
[ExportType.COCO]: {
29+
label: ExportType.COCO,
30+
value: ExportType.COCO,
31+
},
32+
[ExportType.MASK]: {
33+
label: ExportType.MASK,
34+
value: ExportType.MASK,
35+
},
5036
};
5137

5238
export default function ExportPortal({ taskId, sampleIds, mediaType, tools, children }: ExportPortalProps) {
@@ -99,24 +85,34 @@ export default function ExportPortal({ taskId, sampleIds, mediaType, tools, chil
9985
});
10086
}, [children, handleOpenModal]);
10187

102-
// cuboid 不需要导出coco和mask
103-
const containsCuboidTool = useMemo(() => {
104-
return tools?.find((item) => item.tool === 'cuboidTool');
105-
}, [tools]);
106-
10788
const options = useMemo(() => {
89+
const result = [optionMapping[ExportType.JSON]];
90+
10891
if (!mediaType) {
109-
return [];
92+
return result;
11093
}
11194

112-
if (containsCuboidTool && mediaType === MediaType.IMAGE) {
113-
return availableOptions[MediaType.IMAGE].filter(
114-
(option) => option.value !== ExportType.COCO && option.value !== ExportType.MASK,
115-
);
95+
const onlyPolygonTool = tools?.length === 1 && tools[0].tool === 'polygonTool';
96+
const onlyRectTool = tools?.length === 1 && tools[0].tool === 'rectTool';
97+
const polygonOrRectTool =
98+
tools?.length === 2 &&
99+
tools.find((item) => item.tool === 'polygonTool') &&
100+
tools.find((item) => item.tool === 'rectTool');
101+
102+
// coco: rect, polygon
103+
// mask: polygon
104+
if (mediaType === MediaType.IMAGE) {
105+
if (polygonOrRectTool || onlyPolygonTool || onlyRectTool) {
106+
result.push(optionMapping[ExportType.COCO]);
107+
}
108+
109+
if (onlyPolygonTool) {
110+
result.push(optionMapping[ExportType.MASK]);
111+
}
116112
}
117113

118-
return availableOptions[mediaType || MediaType.IMAGE];
119-
}, [containsCuboidTool, mediaType]);
114+
return result;
115+
}, [mediaType, tools]);
120116

121117
return (
122118
<>

apps/frontend/src/setupProxy.js

-28
This file was deleted.

apps/frontend/src/setupTests.ts

-5
This file was deleted.

0 commit comments

Comments
 (0)