Skip to content

Commit 82a38ef

Browse files
committed
fix data not being updated in image classification configuration
1 parent ff965d8 commit 82a38ef

File tree

3 files changed

+26
-34
lines changed

3 files changed

+26
-34
lines changed

client/src/ConfigureImageClassification/ConfigureImageClassification.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ describe('ConfigureImageClassification', () => {
8181
expect(screen.getByText('Multiple Region Labels')).toBeInTheDocument();
8282
expect(screen.getByText('Region Types Allowed')).toBeInTheDocument();
8383
expect(screen.getByText('Labels')).toBeInTheDocument();
84-
expect(screen.getByText('Regions')).toBeInTheDocument();
8584

8685
// Assert checkboxes are rendered
8786
const multipleRegionsCheckbox = screen.getByTestId('checkbox-multipleRegions');

client/src/ConfigureImageClassification/index.jsx

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @flow
22
import React, { useMemo } from "react"
33
import Survey from "material-survey/components/Survey"
4-
import { setIn } from "seamless-immutable"
4+
import { setIn, asMutable } from "seamless-immutable"
55
import { CssBaseline, GlobalStyles } from "@mui/material";
66
import { useTranslation } from "react-i18next"
77

@@ -21,12 +21,12 @@ export default ({ config, onChange }) => {
2121
type: "boolean",
2222
},
2323
{
24-
name: "regionTypesAllowed",
25-
title: t("configuration.region_types_allowed"),
26-
description: t("configuration.region_types_allowed.description"),
27-
type: "checkbox",
28-
choices: ["bounding-box", "polygon", "circle"],
29-
},
24+
name: "regionTypesAllowed",
25+
title: t("configuration.region_types_allowed"),
26+
description: t("configuration.region_types_allowed.description"),
27+
type: "multiple-dropdown",
28+
choices: ["bounding-box", "polygon", "circle"],
29+
},
3030
{
3131
name: "labels",
3232
title: t("configuration.labels"),
@@ -40,32 +40,22 @@ export default ({ config, onChange }) => {
4040
title: t("configuration.labels.option.id"),
4141
},
4242
],
43-
},
44-
{
45-
name: "regions",
46-
title: t("configuration.regions"),
47-
description: t("configuration.regions.description"),
48-
type: "dropdown",
49-
choices: [
50-
"Polygon",
51-
"Bounding Box",
52-
"Point",
53-
],
5443
}
5544
],
5645
}
5746

5847
const defaultAnswers = useMemo(
59-
() => ({
48+
() => asMutable({
6049
multipleRegions: config.multipleRegions ?? false,
6150
multipleRegionLabels: config.multipleRegionLabels ?? false,
6251
regionTypesAllowed: config.regionTypesAllowed ? config.regionTypesAllowed : [],
6352
labels:
6453
(config.labels || []).map((a) => {
6554
return typeof a === "string" ? { id: a, description: a } : a
6655
}) || [],
67-
regions: config.regions ?? "Polygon"
68-
}),
56+
},
57+
{deep: true}
58+
),
6959
[config.labels, config.multipleRegions]
7060
)
7161
return (
@@ -97,16 +87,16 @@ export default ({ config, onChange }) => {
9787
variant="flat"
9888
defaultAnswers={defaultAnswers}
9989
onQuestionChange={(questionId, newValue) => {
100-
if(questionId !=="regionTypesAllowed" && questionId !=="multipleRegions" && questionId !=="multipleRegionLabels"){
101-
let arrayId = []
102-
if (Array.isArray(newValue)){
103-
newValue = newValue.filter((json) => {
104-
if (arrayId.includes(json.id)) return false
105-
arrayId.push(json.id)
106-
return true
107-
})
108-
onChange(setIn(config, [questionId], newValue))
109-
}
90+
if(questionId !=="regionTypesAllowed" && questionId !=="multipleRegions" && questionId !=="multipleRegionLabels"){
91+
let arrayId = []
92+
if (Array.isArray(newValue)){
93+
newValue = newValue.filter((json) => {
94+
if (arrayId.includes(json.id)) return false
95+
arrayId.push(json.id)
96+
return true
97+
})
98+
onChange(setIn(config, [questionId], newValue))
99+
}
110100
}else {
111101
onChange(setIn(config, [questionId], newValue))
112102
}

client/src/SetupPage/index.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,17 @@ export const SetupPage = ({setConfiguration, settings, setShowLabel, showAnnotat
9595
settings.taskChoice = newTaskInfo.taskChoice;
9696
settingsConfig.changeSetting('settings',settings);
9797
}
98+
99+
useEffect(() => {
100+
setTab("datatype");
101+
}, []);
98102

99103
useEffect(() => {
100104
const { labels } = configuration
101105
if (labels.length > 0) {
102106
setHasConfig(true)
103107
}
104-
setTab("datatype");
105-
}, []);
108+
}, [currentTab]);
106109

107110
const showLab = ()=> {
108111
const hasLabels = configuration.labels.length > 0;

0 commit comments

Comments
 (0)