Skip to content

Commit 42ea8f7

Browse files
committed
fix(frontend): fix TS errors in Simulations
1 parent 029bc70 commit 42ea8f7

File tree

3 files changed

+36
-36
lines changed

3 files changed

+36
-36
lines changed

frontend-v2/src/components/DropdownButton.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ type Props = {
2121
disabled?: boolean;
2222
data_cy?: string;
2323
useIcon?: boolean;
24-
sx?: SxProps
24+
sx?: SxProps;
25+
variant?: "text" | "outlined" | "contained";
2526
};
2627

2728
const DropdownButton: FC<Props> = ({
@@ -32,7 +33,7 @@ const DropdownButton: FC<Props> = ({
3233
disabled,
3334
useIcon,
3435
sx,
35-
variant = 'contained'
36+
variant = "contained",
3637
}) => {
3738
const [anchorEl, setAnchorEl] = useState<HTMLButtonElement | null>(null);
3839

frontend-v2/src/features/simulation/Simulations.tsx

+10-18
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import {
2-
Alert,
3-
Grid,
4-
Snackbar,
5-
Box
6-
} from "@mui/material";
1+
import { Alert, Grid, Snackbar, Box } from "@mui/material";
72
import { useSelector } from "react-redux";
83
import { RootState } from "../../app/store";
94
import {
@@ -46,31 +41,31 @@ import { getTableHeight } from "../../shared/calculateTableHeights";
4641

4742
const PlotsWidthSteps = [
4843
{
49-
minHeight: "1100",
44+
minHeight: 1100,
5045
tableHeight: "75vw",
5146
},
5247
{
53-
minHeight: "1000",
48+
minHeight: 1000,
5449
tableHeight: "72vw",
5550
},
5651
{
57-
minHeight: "900",
52+
minHeight: 900,
5853
tableHeight: "70vw",
5954
},
6055
{
61-
minHeight: "800",
56+
minHeight: 800,
6257
tableHeight: "65vw",
6358
},
6459
{
65-
minHeight: "700",
60+
minHeight: 700,
6661
tableHeight: "60vw",
6762
},
6863
{
69-
minHeight: "600",
64+
minHeight: 600,
7065
tableHeight: "55vw",
7166
},
7267
{
73-
minHeight: "500",
68+
minHeight: 500,
7469
tableHeight: "53vw",
7570
},
7671
];
@@ -150,9 +145,7 @@ const Simulations: FC = () => {
150145
const [sliderValues, setSliderValues] = useState<SliderValues | undefined>(
151146
undefined,
152147
);
153-
console.log('sliderValues', sliderValues);
154148
const handleChangeSlider = useCallback((variable: number, value: number) => {
155-
console.log('handleChangeSlider', variable, value);
156149
setSliderValues((prevSliderValues) => ({
157150
...prevSliderValues,
158151
[variable]: value,
@@ -212,7 +205,7 @@ const Simulations: FC = () => {
212205
);
213206
const { data: dataReference } = useSimulation(
214207
refSimInputs,
215-
showReference ? model : undefined
208+
showReference ? model : undefined,
216209
);
217210

218211
const {
@@ -254,7 +247,6 @@ const Simulations: FC = () => {
254247
// reset form and sliders if simulation changes
255248
useEffect(() => {
256249
if (simulation && variables) {
257-
console.log('reset form and sliders if simulation changes');
258250
setSliderValues((s) => {
259251
const initialValues = getSliderInitialValues(simulation, s, variables);
260252
return initialValues;
@@ -370,7 +362,7 @@ const Simulations: FC = () => {
370362
};
371363

372364
const orderedSliders = sliders.map((slider, i) => {
373-
const variable = variables.find((v) => v.id === slider.variable);
365+
const variable = variables?.find((v) => v.id === slider.variable);
374366
return {
375367
...slider,
376368
priority: variable ? paramPriority(variable) : 0,

frontend-v2/src/features/simulation/SimulationsSidePanel.tsx

+23-16
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,15 @@ import HelpButton from "../../components/HelpButton";
1919
import { ExpandLess, ExpandMore } from "@mui/icons-material";
2020
import { ChangeEvent, useState } from "react";
2121
import { getTableHeight } from "../../shared/calculateTableHeights";
22-
import { Simulation, SimulationPlot, SimulationRead, SimulationSlider, SubjectGroupRead, UnitRead } from "../../app/backendApi";
23-
import { UseFormReset } from "react-hook-form";
22+
import {
23+
Simulation,
24+
SimulationPlot,
25+
SimulationRead,
26+
SimulationSlider,
27+
SubjectGroupRead,
28+
UnitRead,
29+
} from "../../app/backendApi";
30+
import { Control } from "react-hook-form";
2431

2532
type SimulationsSidePanelType = {
2633
portalId: string;
@@ -30,11 +37,11 @@ type SimulationsSidePanelType = {
3037
}[];
3138
handleAddPlot: (plot: number) => void;
3239
isSharedWithMe: boolean;
33-
layoutOptions: { value: string, label: string }[];
40+
layoutOptions: { value: string; label: string }[];
3441
layout: string;
3542
setLayout: (layout: string) => void;
3643
plots: SimulationPlot[];
37-
control: UseFormReset<Simulation>;
44+
control: Control<Simulation, any>;
3845
units: UnitRead[];
3946
simulation: SimulationRead;
4047
groups?: SubjectGroupRead[];
@@ -45,15 +52,15 @@ type SimulationsSidePanelType = {
4552
label: string;
4653
}[];
4754
handleAddSlider: (slider: number) => void;
48-
orderedSliders: SimulationSlider[];
55+
orderedSliders: (SimulationSlider & { fieldArrayIndex: number })[];
4956
handleChangeSlider: (variable: number, value: number) => void;
50-
handleRemoveSlider: (index: number) => void;
51-
handleSaveSlider: (slider: SimulationSlider) => void;
57+
handleRemoveSlider: (index: number) => () => void;
58+
handleSaveSlider: (slider: SimulationSlider) => (value: number) => void;
5259
exportSimulation: () => void;
5360
showReference: boolean;
5461
setShowReference: (reference: boolean) => void;
5562
shouldShowLegend: boolean;
56-
setShouldShowLegend: (value: boolean) => void
63+
setShouldShowLegend: (value: boolean) => void;
5764
};
5865

5966
const ButtonSx = {
@@ -73,31 +80,31 @@ const ButtonSx = {
7380

7481
const SidePanelSteps = [
7582
{
76-
minHeight: "1100",
83+
minHeight: 1100,
7784
tableHeight: "75vh",
7885
},
7986
{
80-
minHeight: "1000",
87+
minHeight: 1000,
8188
tableHeight: "72vh",
8289
},
8390
{
84-
minHeight: "900",
91+
minHeight: 900,
8592
tableHeight: "70vh",
8693
},
8794
{
88-
minHeight: "800",
95+
minHeight: 800,
8996
tableHeight: "65vh",
9097
},
9198
{
92-
minHeight: "700",
99+
minHeight: 700,
93100
tableHeight: "60vh",
94101
},
95102
{
96-
minHeight: "600",
103+
minHeight: 600,
97104
tableHeight: "55vh",
98105
},
99106
{
100-
minHeight: "500",
107+
minHeight: 500,
101108
tableHeight: "53vh",
102109
},
103110
];
@@ -127,7 +134,7 @@ export const SimulationsSidePanel = ({
127134
showReference,
128135
setShowReference,
129136
shouldShowLegend,
130-
setShouldShowLegend
137+
setShouldShowLegend,
131138
}: SimulationsSidePanelType) => {
132139
const portalRoot = document.getElementById(portalId);
133140
const [collapseLayout, setCollapseLayout] = useState(true);

0 commit comments

Comments
 (0)