From a27fe83f4f54fb9a162deac46022b0002133db1b Mon Sep 17 00:00:00 2001 From: Rithvik Nishad Date: Tue, 26 Mar 2024 19:34:41 +0530 Subject: [PATCH] Fixes high cpu usage in medicines tab, pagination not working, incorrect last modified date and type errors (#7477) * Fixes component re-rendering issue due to change in reference fixes #7465; * fixes dependency on field `last_administered_on` that no longer exists fixes #7466 --- src/Common/hooks/useRangePagination.ts | 2 +- .../Medicine/MedicineAdministrationSheet/index.tsx | 2 +- .../Medicine/MedicineAdministrationSheet/utils.ts | 9 +++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Common/hooks/useRangePagination.ts b/src/Common/hooks/useRangePagination.ts index 7652ae546c1..b7c8b8510a5 100644 --- a/src/Common/hooks/useRangePagination.ts +++ b/src/Common/hooks/useRangePagination.ts @@ -19,7 +19,7 @@ const useRangePagination = ({ bounds, perPage, ...props }: Props) => { useEffect(() => { setCurrentRange(getInitialBounds(bounds, perPage, props.defaultEnd)); - }, [bounds, perPage, props.defaultEnd]); + }, [JSON.stringify(bounds), perPage, props.defaultEnd]); const next = () => { const { end } = currentRange; diff --git a/src/Components/Medicine/MedicineAdministrationSheet/index.tsx b/src/Components/Medicine/MedicineAdministrationSheet/index.tsx index 48c7e2aaff8..fd3d50272a3 100644 --- a/src/Components/Medicine/MedicineAdministrationSheet/index.tsx +++ b/src/Components/Medicine/MedicineAdministrationSheet/index.tsx @@ -83,7 +83,7 @@ const MedicineAdministrationSheet = ({ readonly, is_prn }: Props) => { prescription.last_administered_on) + .filter((prescription) => prescription.last_administration?.created_date) .reduce( (latest, curr) => - curr.last_administered_on && curr.last_administered_on > latest - ? curr.last_administered_on + curr.last_administration?.created_date && + curr.last_administration?.created_date > latest + ? curr.last_administration?.created_date : latest, prescriptions[0]?.created_date ?? new Date() )