From 4e6999079f5e573e6977798fcdaeedfc4edaf0b3 Mon Sep 17 00:00:00 2001 From: Amjith Titus Date: Thu, 6 Mar 2025 13:43:40 +0530 Subject: [PATCH] Group beds, fetch children on expand only --- public/locale/en.json | 1 + src/pages/Facility/locations/LocationList.tsx | 69 +++++++++++++++---- 2 files changed, 58 insertions(+), 12 deletions(-) diff --git a/public/locale/en.json b/public/locale/en.json index ceae5190f95..55eea157588 100644 --- a/public/locale/en.json +++ b/public/locale/en.json @@ -486,6 +486,7 @@ "bed_type__300": "Oxygen Supported Bed", "bed_type__400": "Isolation Bed", "bed_type__500": "Others", + "beds": "Beds", "before": "before", "begin_clinical_encounter": "Begin a new clinical encounter for {{patientName}}. Select the appropriate encounter type, status, and priority to ensure proper documentation and care delivery.", "beta": "beta", diff --git a/src/pages/Facility/locations/LocationList.tsx b/src/pages/Facility/locations/LocationList.tsx index 39a002f1e34..c3d51ead13e 100644 --- a/src/pages/Facility/locations/LocationList.tsx +++ b/src/pages/Facility/locations/LocationList.tsx @@ -233,6 +233,7 @@ function LocationTreeNode({ }, pageSize: 100, }), + enabled: isExpanded, // Only fetch when the node is expanded }); return ( @@ -375,7 +376,7 @@ function LocationCard({ location, onClick }: ChildLocationCardProps) {

- {location.description || t("no_description")} + {location.description}

@@ -439,7 +440,7 @@ function SelectedLocationChildren({ selectedLocationId, "full", currentPage, - searchQuery, // Add search query to cache key + searchQuery, ], queryFn: query(locationApi.list, { pathParams: { facility_id: facilityId }, @@ -447,7 +448,7 @@ function SelectedLocationChildren({ parent: selectedLocationId, limit: ITEMS_PER_PAGE, offset: (currentPage - 1) * ITEMS_PER_PAGE, - name: searchQuery, // Add search parameter to API call + name: searchQuery, }, }), enabled: !!selectedLocationId, @@ -475,18 +476,62 @@ function SelectedLocationChildren({ ); } + // Group locations by type (bed vs non-bed) + const { bedLocations, nonBedLocations } = children.results.reduce( + (acc, location) => { + if (location.form === "bd") { + acc.bedLocations.push(location); + } else { + acc.nonBedLocations.push(location); + } + return acc; + }, + { + bedLocations: [] as LocationListType[], + nonBedLocations: [] as LocationListType[], + }, + ); + return ( <> -
- {children.results.map((child) => ( - onSelect(child)} - facilityId={facilityId} - /> - ))} +
+ {/* Non-bed locations */} + {nonBedLocations.length > 0 && ( +
+

+ {t("locations")} +

+
+ {nonBedLocations.map((location) => ( + onSelect(location)} + facilityId={facilityId} + /> + ))} +
+
+ )} + + {/* Bed locations */} + {bedLocations.length > 0 && ( +
+

{t("beds")}

+
+ {bedLocations.map((location) => ( + onSelect(location)} + facilityId={facilityId} + /> + ))} +
+
+ )}
+