Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(frontend): save changes to drug & target #623

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading