Skip to content

Commit

Permalink
front: Update fetchSubregions to return empty array.
Browse files Browse the repository at this point in the history
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 <ohmspectator@gmail.com>
  • Loading branch information
OhmSpectator committed Dec 31, 2023
1 parent 549fce9 commit 815fd72
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 5 deletions.
3 changes: 1 addition & 2 deletions frontend/src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 0 additions & 3 deletions frontend/src/components/RegionMap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 815fd72

Please sign in to comment.