Skip to content

Commit

Permalink
fix:OH2-386 | Laboratory - edit page: fix "results" select
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverD3 committed Oct 30, 2024
1 parent f15d23c commit 56e0afa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
17 changes: 8 additions & 9 deletions src/components/accessories/laboratory/examForm/ExamForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -288,15 +288,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 @@ -416,7 +415,7 @@ const ExamForm: FC<ExamProps> = ({
<ExamRowTable
title={t("lab.resultstitle")}
headerData={rowTableHeaders}
onBlur={onBlurCallbackForTableRow()}
onBlur={onBlurCallbackForTableRow}
rows={examRows}
disabled={isLoading}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ const ExamRowTable: FC<IEditableTableProps> = ({
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),
[]
);

Expand Down Expand Up @@ -76,7 +76,7 @@ const ExamRowTable: FC<IEditableTableProps> = ({
<TableCell align="right" component="td" scope="row">
<Checkbox
onChange={(e, value) => {
handleOnBlur(row.label);
handleOnBlur(row.label, value);
}}
defaultChecked={
!isEmpty(
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit 56e0afa

Please sign in to comment.