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

OH2-386 | Laboratory - edit page: fix "results" select #685

Merged
merged 5 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
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: 8 additions & 18 deletions src/components/accessories/laboratory/examForm/ExamForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,6 @@ const ExamForm: FC<ExamProps> = ({
setActivityTransitionState("IDLE");
}, [dispatch]);

const rowTableHeaders: Array<{
label: string;
align: "left" | "right" | "center" | "justify";
}> = [
{ label: t("lab.resultrow"), align: "left" },
{ label: t("lab.value"), align: "right" },
];

const validationSchema = object({
labDate: string()
.required(t("common.required"))
Expand Down Expand Up @@ -284,15 +276,14 @@ const ExamForm: FC<ExamProps> = ({
);

const onBlurCallbackForTableRow = useCallback(
() => (value: string) => {
setRowsData((rowObjs: string[]) => {
if (!rowObjs.includes(value)) {
rowObjs.push(value);
} else rowObjs = rowObjs.filter((e) => e !== value);
return rowObjs;
});
(value: string, checked: boolean) => {
if (checked && !rowsData.includes(value)) {
setRowsData((prevState) => [...prevState, value]);
} else {
setRowsData((prevState) => prevState.filter((row) => row !== value));
}
},
[]
[rowsData]
);

const [openResetConfirmation, setOpenResetConfirmation] = useState(false);
Expand Down Expand Up @@ -411,8 +402,7 @@ const ExamForm: FC<ExamProps> = ({
{currentExamProcedure === "2" && (
<ExamRowTable
title={t("lab.resultstitle")}
headerData={rowTableHeaders}
onBlur={onBlurCallbackForTableRow()}
onChange={onBlurCallbackForTableRow}
rows={examRows}
disabled={isLoading}
/>
Expand Down
11 changes: 1 addition & 10 deletions src/components/accessories/patientExams/ExamForm/ExamForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,6 @@ const ExamForm: FC<ExamProps> = ({
const [currentExamProcedure, setCurrentExamProcedure] = useState("");
const labToEditRows = labWithRowsToEdit.laboratoryRowList ?? [];

const rowTableHeaders: Array<{
label: string;
align: "left" | "right" | "center" | "justify";
}> = [
{ label: t("lab.resultrow"), align: "left" },
{ label: t("lab.value"), align: "right" },
];

const validationSchema = object({
labDate: string()
.required(t("common.required"))
Expand Down Expand Up @@ -287,8 +279,7 @@ const ExamForm: FC<ExamProps> = ({
{currentExamProcedure === "2" && (
<ExamRowTable
title={t("lab.resultstitle")}
headerData={rowTableHeaders}
onBlur={onBlurCallbackForTableRow()}
onChange={onBlurCallbackForTableRow()}
rows={examRows}
disabled={isLoading}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,17 @@ import Table from "@mui/material/Table";
import TableBody from "@mui/material/TableBody";
import TableCell from "@mui/material/TableCell";
import TableContainer from "@mui/material/TableContainer";
import TableHead from "@mui/material/TableHead";
import TableRow from "@mui/material/TableRow";
import { useAppSelector } from "libraries/hooks/redux";
import { debounce, isEmpty } from "lodash";
import React, { FC, useCallback } from "react";
import React, { ChangeEvent, FC, useCallback } from "react";
import { IState } from "../../../../types";
import "./styles.scss";
import { IEditableTableProps } from "./types";

const ExamRowTable: FC<IEditableTableProps> = ({
rows,
onBlur,
headerData,
onChange,
title,
disabled = false,
}) => {
Expand All @@ -29,16 +27,22 @@ const ExamRowTable: FC<IEditableTableProps> = ({
state.laboratories.getLabWithRowsByCode.data?.laboratoryRowList
);

const handleOnBlur = (value: string) => {
debounceUpdate(value);
};

// eslint-disable-next-line react-hooks/exhaustive-deps
const debounceUpdate = useCallback(
debounce((value: string) => onBlur(value), 100),
debounce(
(value: string, checked: boolean) => onChange(value, checked),
100
),
[]
);

const handleChange = useCallback(
(value: string) => (_: ChangeEvent, checked: boolean) => {
debounceUpdate(value, checked);
},
[debounceUpdate]
);

return (
<Accordion disabled={disabled}>
<AccordionSummary
Expand All @@ -56,17 +60,6 @@ const ExamRowTable: FC<IEditableTableProps> = ({
size="small"
aria-label="results table"
>
<TableHead>
<TableRow key={"header"}>
{headerData.map((row, index) => {
return (
<TableCell key={index} align={row.align}>
{row.label}
</TableCell>
);
})}
</TableRow>
</TableHead>
<TableBody>
{rows?.map((row, index) => (
<TableRow key={index}>
Expand All @@ -75,9 +68,7 @@ const ExamRowTable: FC<IEditableTableProps> = ({
</TableCell>
<TableCell align="right" component="td" scope="row">
<Checkbox
onChange={(e, value) => {
handleOnBlur(row.label);
}}
onChange={handleChange(row.label)}
defaultChecked={
!isEmpty(
labToEditRows?.filter((e) => e === row.label) ?? []
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
export interface IEditableTableProps {
rows: Array<{ label: string; value: string }>;
onBlur: (value: string) => void;
onChange: (value: string, checked: boolean) => void;
fieldValues?: string[];
headerData: Array<{
label: string;
align: "left" | "right" | "center" | "justify";
}>;
title: string;
disabled?: boolean;
}