Skip to content

Commit

Permalink
fix: handle reset of species question
Browse files Browse the repository at this point in the history
  • Loading branch information
9sneha-n committed Apr 25, 2024
1 parent 7f5db25 commit 7daf96d
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/webapp/components/survey/GridSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ interface GridSectionProps {

export const GridSection: React.FC<GridSectionProps> = React.memo(
({ speciesSection, antibioticStage, updateQuestion, viewOnly }) => {
const [gridOptions, setGridOptions] = useState<string[]>();
const { getAntibioticOptions } = useASTGuidelinesOptions();
const [gridOptions, setGridOptions] = useState<string[]>();
const [antibioticSets, setAntibioticSets] = useState<AntibioticSection[]>();

useEffect(() => {
Expand Down Expand Up @@ -77,10 +77,37 @@ export const GridSection: React.FC<GridSectionProps> = React.memo(
if (question.type === "select" && isSpeciesQuestion(question)) {
const options = getAntibioticOptions(question);
setGridOptions(options);
antibioticSets?.map(antibioticSet => {
if (antibioticSet.addNewAntibioticQuestion?.value) {
updateQuestion({
...antibioticSet.addNewAntibioticQuestion,
value: false,
});
}
if (antibioticSet.antibioticQuestion?.value) {
updateQuestion({
...antibioticSet.antibioticQuestion,
value: undefined,
});
}

if (antibioticSet.astResultsQuestion?.value) {
updateQuestion({
...antibioticSet.astResultsQuestion,
value: undefined,
});
}
if (antibioticSet.valueQuestion?.value) {
updateQuestion({
...antibioticSet.valueQuestion,
value: undefined,
});
}
});
}
updateQuestion(question);
},
[getAntibioticOptions, updateQuestion]
[antibioticSets, getAntibioticOptions, updateQuestion, setGridOptions]
);

return (
Expand Down

0 comments on commit 7daf96d

Please sign in to comment.