From 56e0afab267a02a42edac0042a46e8b3afb6cb79 Mon Sep 17 00:00:00 2001 From: SilverD3 Date: Wed, 30 Oct 2024 18:19:55 +0100 Subject: [PATCH] fix:OH2-386 | Laboratory - edit page: fix "results" select --- .../laboratory/examForm/ExamForm.tsx | 17 ++++++++--------- .../patientExams/examRowTable/ExamRowTable.tsx | 8 ++++---- .../patientExams/examRowTable/types.ts | 2 +- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/components/accessories/laboratory/examForm/ExamForm.tsx b/src/components/accessories/laboratory/examForm/ExamForm.tsx index d00570ba2..95d4f7ba6 100644 --- a/src/components/accessories/laboratory/examForm/ExamForm.tsx +++ b/src/components/accessories/laboratory/examForm/ExamForm.tsx @@ -288,15 +288,14 @@ const ExamForm: FC = ({ ); 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); @@ -416,7 +415,7 @@ const ExamForm: FC = ({ diff --git a/src/components/accessories/patientExams/examRowTable/ExamRowTable.tsx b/src/components/accessories/patientExams/examRowTable/ExamRowTable.tsx index ada2220e2..44f36e8b2 100644 --- a/src/components/accessories/patientExams/examRowTable/ExamRowTable.tsx +++ b/src/components/accessories/patientExams/examRowTable/ExamRowTable.tsx @@ -29,13 +29,13 @@ const ExamRowTable: FC = ({ state.laboratories.getLabWithRowsByCode.data?.laboratoryRowList ); - const handleOnBlur = (value: string) => { - debounceUpdate(value); + const handleOnBlur = (value: string, checked: boolean) => { + debounceUpdate(value, checked); }; // eslint-disable-next-line react-hooks/exhaustive-deps const debounceUpdate = useCallback( - debounce((value: string) => onBlur(value), 100), + debounce((value: string, checked: boolean) => onBlur(value, checked), 100), [] ); @@ -76,7 +76,7 @@ const ExamRowTable: FC = ({ { - handleOnBlur(row.label); + handleOnBlur(row.label, value); }} defaultChecked={ !isEmpty( diff --git a/src/components/accessories/patientExams/examRowTable/types.ts b/src/components/accessories/patientExams/examRowTable/types.ts index c86d85f1e..20ee00c83 100644 --- a/src/components/accessories/patientExams/examRowTable/types.ts +++ b/src/components/accessories/patientExams/examRowTable/types.ts @@ -1,6 +1,6 @@ export interface IEditableTableProps { rows: Array<{ label: string; value: string }>; - onBlur: (value: string) => void; + onBlur: (value: string, checked: boolean) => void; fieldValues?: string[]; headerData: Array<{ label: string;