Skip to content

Commit 055f00a

Browse files
authored
Merge pull request #230 from ITISFoundation/223-outputdistributions-does-not-get-updated-upon-changing-selectedfunction
fix: outputs now update when changing function
2 parents 367c63d + 12f6e3a commit 055f00a

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

node/src/components/setup/AddOutputModal.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ export const AddOutputModal = (props: AddOutputModalProps) => {
6666
</MenuItem>
6767
))}
6868
</Select>
69-
<Button onClick={() => onChange(selected)} sx={{ backgroundColor: theme.palette.primary.main, marginTop: "16px" }}>
69+
<Button
70+
onClick={() => onChange(selected)}
71+
sx={{ backgroundColor: theme.palette.primary.main, marginTop: "16px" }}
72+
>
7073
<Typography variant="body1" color={theme.palette.text.primary}>
7174
Add
7275
</Typography>

node/src/components/setup/OutputVariableDist.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,25 @@ export const OutputVariableDist = () => {
4242
[outputDistribution, selectedFunction, setOutputDistribution]
4343
);
4444

45+
useEffect(() => {
46+
if (
47+
outputDistribution &&
48+
selectedFunction &&
49+
outputDistribution[selectedFunction.uid]
50+
) {
51+
setConfiguredOutputs(outputDistribution[selectedFunction.uid]);
52+
} else {
53+
if (outputVars && outputVars.length > 0) {
54+
handlesetConfiguredOutputs(
55+
Object.fromEntries(outputVars.map((v) => [v, "minimize"]))
56+
);
57+
} else {
58+
handlesetConfiguredOutputs({});
59+
}
60+
}
61+
// eslint-disable-next-line react-hooks/exhaustive-deps
62+
}, [outputDistribution, outputVars, selectedFunction]);
63+
4564
if (outputVars && outputVars.length === 0) {
4665
return <></>;
4766
}

node/src/components/utils/CustomAnimatedToggle.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from "react";
1+
import React, { useEffect } from "react";
22
import { Box, Button, useTheme } from "@mui/material";
33

44
interface CustomAnimatedToggleProps {
@@ -19,6 +19,10 @@ export const CustomAnimatedToggle = (props: CustomAnimatedToggleProps) => {
1919
onChange(index);
2020
};
2121

22+
useEffect(() => {
23+
setSelected(value);
24+
}, [value]);
25+
2226
return (
2327
<Box
2428
sx={{

0 commit comments

Comments
 (0)