From ade8d650a5c8c63bb1640a97d5d4c20cbf17b46a Mon Sep 17 00:00:00 2001 From: Peter Muriuki Date: Fri, 13 May 2022 12:00:41 +0300 Subject: [PATCH] Disable location hierarchy refetches Add alert when refetching tree location hierarchy --- .../src/components/LocationUnitList/index.tsx | 122 ++++++++++-------- 1 file changed, 68 insertions(+), 54 deletions(-) diff --git a/packages/fhir-location-management/src/components/LocationUnitList/index.tsx b/packages/fhir-location-management/src/components/LocationUnitList/index.tsx index e23406059..1460b23ae 100644 --- a/packages/fhir-location-management/src/components/LocationUnitList/index.tsx +++ b/packages/fhir-location-management/src/components/LocationUnitList/index.tsx @@ -23,6 +23,7 @@ import { setSelectedNode, getSelectedNode, } from '../../ducks/location-tree-state'; +import { Alert } from 'antd'; reducerRegistry.register(reducerName, reducer); @@ -77,6 +78,7 @@ export const LocationUnitList: React.FC = (props: Locatio data: treeData, isLoading: treeIsLoading, error: treeError, + isFetching: treeIsFetching, } = useQuery( [locationHierarchyResourceType, hierarchyParams], async () => { @@ -88,6 +90,7 @@ export const LocationUnitList: React.FC = (props: Locatio select: (res) => { return convertApiResToTree(res); }, + staleTime: Infinity, // prevent refetches on things like window refocus } ); @@ -117,62 +120,73 @@ export const LocationUnitList: React.FC = (props: Locatio const tableDispData = parseTableData(tableNodes); return ( -
- - {lang.LOCATION_UNIT} - -

{lang.LOCATION_UNIT_MANAGEMENT}

- - - { - dispatch(setSelectedNode(node)); - }} - /> - - -
-
- {selectedNode ? selectedNode.model.node.name : lang.LOCATION_UNIT} -
-
- { - if (selectedNode) { - const queryParams = { parentId: selectedNode.model.nodeId }; - const searchString = new URLSearchParams(queryParams).toString(); - return `${URL_LOCATION_UNIT_ADD}?${searchString}`; - } - return URL_LOCATION_UNIT_ADD; + <> + {treeIsFetching && ( + + )} +
+ + {lang.LOCATION_UNIT} + +

{lang.LOCATION_UNIT_MANAGEMENT}

+ + + { + dispatch(setSelectedNode(node)); + }} + /> + + +
+
+ {selectedNode ? selectedNode.model.node.name : lang.LOCATION_UNIT} +
+
+ { + if (selectedNode) { + const queryParams = { parentId: selectedNode.model.nodeId }; + const searchString = new URLSearchParams(queryParams).toString(); + return `${URL_LOCATION_UNIT_ADD}?${searchString}`; + } + return URL_LOCATION_UNIT_ADD; + }} + > + + +
+
+
+ { + setDetailId(row.id); }} - > - - + /> - -
-
{ - setDetailId(row.id); - }} + + {detailId ? ( + setDetailId('')} + detailId={detailId} /> - - - {detailId ? ( - setDetailId('')} - detailId={detailId} - /> - ) : null} - - + ) : null} + + + ); };