Skip to content

Commit

Permalink
fix(frontend): fix TS errors in Simulations
Browse files Browse the repository at this point in the history
  • Loading branch information
eatyourgreens committed Nov 20, 2024
1 parent 029bc70 commit 2ce79d3
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 36 deletions.
5 changes: 3 additions & 2 deletions frontend-v2/src/components/DropdownButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ type Props = {
disabled?: boolean;
data_cy?: string;
useIcon?: boolean;
sx?: SxProps
sx?: SxProps;
variant?: "text" | "outlined" | "contained";
};

const DropdownButton: FC<Props> = ({
Expand All @@ -32,7 +33,7 @@ const DropdownButton: FC<Props> = ({
disabled,
useIcon,
sx,
variant = 'contained'
variant = "contained",
}) => {
const [anchorEl, setAnchorEl] = useState<HTMLButtonElement | null>(null);

Expand Down
31 changes: 13 additions & 18 deletions frontend-v2/src/features/simulation/Simulations.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
Alert,
Grid,
Snackbar,
Box
} from "@mui/material";
import { Alert, Grid, Snackbar, Box } from "@mui/material";
import { useSelector } from "react-redux";
import { RootState } from "../../app/store";
import {
Expand Down Expand Up @@ -46,31 +41,31 @@ import { getTableHeight } from "../../shared/calculateTableHeights";

const PlotsWidthSteps = [
{
minHeight: "1100",
minHeight: 1100,
tableHeight: "75vw",
},
{
minHeight: "1000",
minHeight: 1000,
tableHeight: "72vw",
},
{
minHeight: "900",
minHeight: 900,
tableHeight: "70vw",
},
{
minHeight: "800",
minHeight: 800,
tableHeight: "65vw",
},
{
minHeight: "700",
minHeight: 700,
tableHeight: "60vw",
},
{
minHeight: "600",
minHeight: 600,
tableHeight: "55vw",
},
{
minHeight: "500",
minHeight: 500,
tableHeight: "53vw",
},
];
Expand Down Expand Up @@ -150,9 +145,9 @@ const Simulations: FC = () => {
const [sliderValues, setSliderValues] = useState<SliderValues | undefined>(
undefined,
);
console.log('sliderValues', sliderValues);
console.log("sliderValues", sliderValues);
const handleChangeSlider = useCallback((variable: number, value: number) => {
console.log('handleChangeSlider', variable, value);
console.log("handleChangeSlider", variable, value);
setSliderValues((prevSliderValues) => ({
...prevSliderValues,
[variable]: value,
Expand Down Expand Up @@ -212,7 +207,7 @@ const Simulations: FC = () => {
);
const { data: dataReference } = useSimulation(
refSimInputs,
showReference ? model : undefined
showReference ? model : undefined,
);

const {
Expand Down Expand Up @@ -254,7 +249,7 @@ const Simulations: FC = () => {
// reset form and sliders if simulation changes
useEffect(() => {
if (simulation && variables) {
console.log('reset form and sliders if simulation changes');
console.log("reset form and sliders if simulation changes");
setSliderValues((s) => {
const initialValues = getSliderInitialValues(simulation, s, variables);
return initialValues;
Expand Down Expand Up @@ -370,7 +365,7 @@ const Simulations: FC = () => {
};

const orderedSliders = sliders.map((slider, i) => {
const variable = variables.find((v) => v.id === slider.variable);
const variable = variables?.find((v) => v.id === slider.variable);
return {
...slider,
priority: variable ? paramPriority(variable) : 0,
Expand Down
39 changes: 23 additions & 16 deletions frontend-v2/src/features/simulation/SimulationsSidePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,15 @@ import HelpButton from "../../components/HelpButton";
import { ExpandLess, ExpandMore } from "@mui/icons-material";
import { ChangeEvent, useState } from "react";
import { getTableHeight } from "../../shared/calculateTableHeights";
import { Simulation, SimulationPlot, SimulationRead, SimulationSlider, SubjectGroupRead, UnitRead } from "../../app/backendApi";
import { UseFormReset } from "react-hook-form";
import {
Simulation,
SimulationPlot,
SimulationRead,
SimulationSlider,
SubjectGroupRead,
UnitRead,
} from "../../app/backendApi";
import { Control } from "react-hook-form";

type SimulationsSidePanelType = {
portalId: string;
Expand All @@ -30,11 +37,11 @@ type SimulationsSidePanelType = {
}[];
handleAddPlot: (plot: number) => void;
isSharedWithMe: boolean;
layoutOptions: { value: string, label: string }[];
layoutOptions: { value: string; label: string }[];
layout: string;
setLayout: (layout: string) => void;
plots: SimulationPlot[];
control: UseFormReset<Simulation>;
control: Control<Simulation, any>;
units: UnitRead[];
simulation: SimulationRead;
groups?: SubjectGroupRead[];
Expand All @@ -45,15 +52,15 @@ type SimulationsSidePanelType = {
label: string;
}[];
handleAddSlider: (slider: number) => void;
orderedSliders: SimulationSlider[];
orderedSliders: (SimulationSlider & { fieldArrayIndex: number })[];
handleChangeSlider: (variable: number, value: number) => void;
handleRemoveSlider: (index: number) => void;
handleSaveSlider: (slider: SimulationSlider) => void;
handleRemoveSlider: (index: number) => () => void;
handleSaveSlider: (slider: SimulationSlider) => (value: number) => void;
exportSimulation: () => void;
showReference: boolean;
setShowReference: (reference: boolean) => void;
shouldShowLegend: boolean;
setShouldShowLegend: (value: boolean) => void
setShouldShowLegend: (value: boolean) => void;
};

const ButtonSx = {
Expand All @@ -73,31 +80,31 @@ const ButtonSx = {

const SidePanelSteps = [
{
minHeight: "1100",
minHeight: 1100,
tableHeight: "75vh",
},
{
minHeight: "1000",
minHeight: 1000,
tableHeight: "72vh",
},
{
minHeight: "900",
minHeight: 900,
tableHeight: "70vh",
},
{
minHeight: "800",
minHeight: 800,
tableHeight: "65vh",
},
{
minHeight: "700",
minHeight: 700,
tableHeight: "60vh",
},
{
minHeight: "600",
minHeight: 600,
tableHeight: "55vh",
},
{
minHeight: "500",
minHeight: 500,
tableHeight: "53vh",
},
];
Expand Down Expand Up @@ -127,7 +134,7 @@ export const SimulationsSidePanel = ({
showReference,
setShowReference,
shouldShowLegend,
setShouldShowLegend
setShouldShowLegend,
}: SimulationsSidePanelType) => {
const portalRoot = document.getElementById(portalId);
const [collapseLayout, setCollapseLayout] = useState(true);
Expand Down

0 comments on commit 2ce79d3

Please sign in to comment.