Skip to content

fix data not being updated in image classification configuration #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ describe('ConfigureImageClassification', () => {
expect(screen.getByText('Multiple Region Labels')).toBeInTheDocument();
expect(screen.getByText('Region Types Allowed')).toBeInTheDocument();
expect(screen.getByText('Labels')).toBeInTheDocument();
expect(screen.getByText('Regions')).toBeInTheDocument();

// Assert checkboxes are rendered
const multipleRegionsCheckbox = screen.getByTestId('checkbox-multipleRegions');
Expand Down
52 changes: 21 additions & 31 deletions client/src/ConfigureImageClassification/index.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow
import React, { useMemo } from "react"
import Survey from "material-survey/components/Survey"
import { setIn } from "seamless-immutable"
import { setIn, asMutable } from "seamless-immutable"
import { CssBaseline, GlobalStyles } from "@mui/material";
import { useTranslation } from "react-i18next"

Expand All @@ -21,12 +21,12 @@ export default ({ config, onChange }) => {
type: "boolean",
},
{
name: "regionTypesAllowed",
title: t("configuration.region_types_allowed"),
description: t("configuration.region_types_allowed.description"),
type: "checkbox",
choices: ["bounding-box", "polygon", "circle"],
},
name: "regionTypesAllowed",
title: t("configuration.region_types_allowed"),
description: t("configuration.region_types_allowed.description"),
type: "multiple-dropdown",
choices: ["bounding-box", "polygon", "circle"],
},
{
name: "labels",
title: t("configuration.labels"),
Expand All @@ -40,32 +40,22 @@ export default ({ config, onChange }) => {
title: t("configuration.labels.option.id"),
},
],
},
{
name: "regions",
title: t("configuration.regions"),
description: t("configuration.regions.description"),
type: "dropdown",
choices: [
"Polygon",
"Bounding Box",
"Point",
],
}
],
}

const defaultAnswers = useMemo(
() => ({
() => asMutable({
multipleRegions: config.multipleRegions ?? false,
multipleRegionLabels: config.multipleRegionLabels ?? false,
regionTypesAllowed: config.regionTypesAllowed ? config.regionTypesAllowed : [],
labels:
(config.labels || []).map((a) => {
return typeof a === "string" ? { id: a, description: a } : a
}) || [],
regions: config.regions ?? "Polygon"
}),
},
{deep: true}
),
[config.labels, config.multipleRegions]
)
return (
Expand Down Expand Up @@ -97,16 +87,16 @@ export default ({ config, onChange }) => {
variant="flat"
defaultAnswers={defaultAnswers}
onQuestionChange={(questionId, newValue) => {
if(questionId !=="regionTypesAllowed" && questionId !=="multipleRegions" && questionId !=="multipleRegionLabels"){
let arrayId = []
if (Array.isArray(newValue)){
newValue = newValue.filter((json) => {
if (arrayId.includes(json.id)) return false
arrayId.push(json.id)
return true
})
onChange(setIn(config, [questionId], newValue))
}
if(questionId !=="regionTypesAllowed" && questionId !=="multipleRegions" && questionId !=="multipleRegionLabels"){
let arrayId = []
if (Array.isArray(newValue)){
newValue = newValue.filter((json) => {
if (arrayId.includes(json.id)) return false
arrayId.push(json.id)
return true
})
onChange(setIn(config, [questionId], newValue))
}
}else {
onChange(setIn(config, [questionId], newValue))
}
Expand Down
7 changes: 5 additions & 2 deletions client/src/SetupPage/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,17 @@ export const SetupPage = ({setConfiguration, settings, setShowLabel, showAnnotat
settings.taskChoice = newTaskInfo.taskChoice;
settingsConfig.changeSetting('settings',settings);
}

useEffect(() => {
setTab("datatype");
}, []);

useEffect(() => {
const { labels } = configuration
if (labels.length > 0) {
setHasConfig(true)
}
setTab("datatype");
}, []);
}, [currentTab]);

const showLab = ()=> {
const hasLabels = configuration.labels.length > 0;
Expand Down
Loading