From f35da50a0fa743da27f7ac65445623c9de85c972 Mon Sep 17 00:00:00 2001 From: Nikolay Martyanov Date: Sun, 31 Dec 2023 12:20:26 +0100 Subject: [PATCH] front: Update fetchSubregions to return empty array. Modified fetchSubregions function to return an empty array instead of null when no subregions are available, aligning with the expected return type and ensuring consistency in handling empty results across the application. Issue: #189 Signed-off-by: Nikolay Martyanov --- frontend/src/api/index.js | 3 +-- frontend/src/components/RegionMap.jsx | 3 --- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/frontend/src/api/index.js b/frontend/src/api/index.js index 30427dd..91c282f 100644 --- a/frontend/src/api/index.js +++ b/frontend/src/api/index.js @@ -34,8 +34,7 @@ export const fetchSubregions = async (regionId, hierarchyId) => { try { const response = await api.get(`/api/regions/${regionId}/subregions`, { params: { hierarchyId } }); if (response.status === 204) { - // TODO return empty array instead of null, Issue #189 - return null; + return []; } return response.data; } catch (error) { diff --git a/frontend/src/components/RegionMap.jsx b/frontend/src/components/RegionMap.jsx index b1f0e5e..4382b69 100644 --- a/frontend/src/components/RegionMap.jsx +++ b/frontend/src/components/RegionMap.jsx @@ -64,9 +64,6 @@ function MapComponent() { // If region has subregions, fetch the subregions if (selectedRegion.hasSubregions) { const subregions = await fetchSubregions(selectedRegion.id, selectedHierarchy.hierarchyId); - if (subregions === null) { - return []; - } return subregions; } // If region does not have subregions, fetch the siblings