Skip to content

Commit

Permalink
fix(frontend): save changes to drug & target (#623)
Browse files Browse the repository at this point in the history
Restore some deleted code that saves changes to the drug and target form.
  • Loading branch information
eatyourgreens authored Dec 13, 2024
1 parent d3f6a67 commit 3c44d1e
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions frontend-v2/src/features/drug/Drug.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
useProjectRetrieveQuery,
useUnitListQuery,
} from "../../app/backendApi";
import { useFieldArray, useForm } from "react-hook-form";
import { useFieldArray, useForm, useFormState } from "react-hook-form";
import FloatField from "../../components/FloatField";
import UnitField from "../../components/UnitField";
import { FC, useEffect, useMemo, useState } from "react";
Expand All @@ -39,6 +39,7 @@ import Delete from "@mui/icons-material/Delete";
import { decrementDirtyCount, incrementDirtyCount } from "../main/mainSlice";
import AddCircleOutlineOutlinedIcon from "@mui/icons-material/AddCircleOutlineOutlined";
import { getTableHeight } from "../../shared/calculateTableHeights";
import useDirty from "../../hooks/useDirty";

export const DOUBLE_TABLE_SECOND_BREAKPOINTS = [
{
Expand Down Expand Up @@ -103,6 +104,8 @@ const Drug: FC = () => {
efficacy_experiments: [],
},
});
const { isDirty } = useFormState({ control });
useDirty(isDirty);

const {
fields: efficacy_experiments,
Expand Down Expand Up @@ -157,9 +160,15 @@ const Drug: FC = () => {
[compound, handleSubmit, updateCompound],
);

useEffect(() => {
if (isDirty) {
submit();
}
}, [isDirty, submit]);

useEffect(() => {
submit();
}, [efficacy_experiments?.length]);
}, [efficacy_experiments?.length, submit]);

const addNewEfficacyExperiment = () => {
append([
Expand Down Expand Up @@ -359,7 +368,7 @@ const Drug: FC = () => {
{isEditIndex === index ? (
<TextField
size="small"
sx={{ flex: "1", minWidth: '10rem' }}
sx={{ flex: "1", minWidth: "10rem" }}
label="Name"
name={`efficacy_experiments.${index}.name`}
control={control}
Expand All @@ -379,7 +388,7 @@ const Drug: FC = () => {
{isEditIndex === index ? (
<FloatField
size="small"
sx={{ flex: "1", minWidth: '5rem' }}
sx={{ flex: "1", minWidth: "5rem" }}
label="C50"
name={`efficacy_experiments.${index}.c50`}
control={control}
Expand Down Expand Up @@ -407,17 +416,18 @@ const Drug: FC = () => {
) : (
<Typography>
{units.find(
(u) => u.id === getValues(`efficacy_experiments.${index}.c50_unit`),
)?.symbol ||
"-"}
(u) =>
u.id ===
getValues(`efficacy_experiments.${index}.c50_unit`),
)?.symbol || "-"}
</Typography>
)}
</TableCell>
<TableCell size="small">
{isEditIndex === index ? (
<FloatField
size="small"
sx={{ minWidth: '5rem' }}
sx={{ minWidth: "5rem" }}
label="Hill-coefficient"
name={`efficacy_experiments.${index}.hill_coefficient`}
control={control}
Expand Down

0 comments on commit 3c44d1e

Please sign in to comment.