Skip to content

Commit b0cb0eb

Browse files
authored
Merge pull request #1089 from IFRCGo/fix/country-empty-bbox
Add check for empty bbox of country
2 parents c544e98 + 8a4f26d commit b0cb0eb

File tree

5 files changed

+36
-21
lines changed

5 files changed

+36
-21
lines changed

.changeset/stupid-pandas-juggle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"go-web-app": patch
3+
---
4+
5+
Avoid crash on country pages for countries without bbox

app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsMap/index.tsx

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import react, { useMemo } from 'react';
1+
import {
2+
useCallback,
3+
useMemo,
4+
useState,
5+
} from 'react';
26
import { useOutletContext } from 'react-router-dom';
37
import {
48
ArtboardLineIcon,
@@ -132,7 +136,7 @@ function LocalUnitsMap(props: Props) {
132136
pageSize: 9999,
133137
});
134138

135-
const urlQuery = react.useMemo<GoApiUrlQuery<'/api/v2/public-local-units/'>>(
139+
const urlQuery = useMemo<GoApiUrlQuery<'/api/v2/public-local-units/'>>(
136140
() => ({
137141
limit,
138142
type__code: filter.type,
@@ -183,11 +187,11 @@ function LocalUnitsMap(props: Props) {
183187
const [
184188
clickedPointProperties,
185189
setClickedPointProperties,
186-
] = react.useState<ClickedPoint | undefined>();
190+
] = useState<ClickedPoint | undefined>();
187191

188-
const [loadedIcons, setLoadedIcons] = react.useState<Record<string, boolean>>({});
192+
const [loadedIcons, setLoadedIcons] = useState<Record<string, boolean>>({});
189193

190-
const handleIconLoad = react.useCallback(
194+
const handleIconLoad = useCallback(
191195
(loaded: boolean, key: string) => {
192196
setLoadedIcons((prevValue) => ({
193197
...prevValue,
@@ -197,7 +201,7 @@ function LocalUnitsMap(props: Props) {
197201
[],
198202
);
199203

200-
const allIconsLoaded = react.useMemo(
204+
const allIconsLoaded = useMemo(
201205
() => (
202206
Object.values(loadedIcons).filter(Boolean).length === sumSafe([
203207
localUnitsOptions?.type.length,
@@ -207,7 +211,7 @@ function LocalUnitsMap(props: Props) {
207211
[loadedIcons, localUnitsOptions],
208212
);
209213

210-
const localUnitPointLayerOptions: Omit<CircleLayer, 'id'> = react.useMemo(() => ({
214+
const localUnitPointLayerOptions: Omit<CircleLayer, 'id'> = useMemo(() => ({
211215
layout: {
212216
visibility: 'visible',
213217
},
@@ -236,8 +240,10 @@ function LocalUnitsMap(props: Props) {
236240
},
237241
}), [localUnitsOptions]);
238242

239-
const countryBounds = react.useMemo(() => (
240-
countryResponse ? getBbox(countryResponse.bbox) : undefined
243+
const countryBounds = useMemo(() => (
244+
(countryResponse && countryResponse.bbox)
245+
? getBbox(countryResponse.bbox)
246+
: undefined
241247
), [countryResponse]);
242248

243249
const {
@@ -276,7 +282,7 @@ function LocalUnitsMap(props: Props) {
276282
? publicLocalUnitDetailError
277283
: superLocalUnitDetailError;
278284

279-
const localUnitsGeoJson = react.useMemo<GeoJSON.FeatureCollection<GeoJSON.Geometry>>(
285+
const localUnitsGeoJson = useMemo<GeoJSON.FeatureCollection<GeoJSON.Geometry>>(
280286
() => ({
281287
type: 'FeatureCollection' as const,
282288
features: localUnits?.results?.map(
@@ -305,7 +311,7 @@ function LocalUnitsMap(props: Props) {
305311
[localUnits],
306312
);
307313

308-
const handlePointClick = react.useCallback(
314+
const handlePointClick = useCallback(
309315
(feature: mapboxgl.MapboxGeoJSONFeature, lngLat: mapboxgl.LngLat) => {
310316
setClickedPointProperties({
311317
id: feature.properties?.id,
@@ -317,14 +323,14 @@ function LocalUnitsMap(props: Props) {
317323
[setClickedPointProperties],
318324
);
319325

320-
const handlePointClose = react.useCallback(
326+
const handlePointClose = useCallback(
321327
() => {
322328
setClickedPointProperties(undefined);
323329
},
324330
[setClickedPointProperties],
325331
);
326332

327-
const emailRendererParams = react.useCallback(
333+
const emailRendererParams = useCallback(
328334
(_: string, email: string): LinkProps => ({
329335
className: styles.email,
330336
withUnderline: true,

app/src/views/CountryOngoingActivitiesEmergencies/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,10 @@ export function Component(props: BaseProps) {
170170
pageSize: 5,
171171
});
172172

173-
const countryBounds = useMemo(() => (countryResponse
174-
? getBbox(countryResponse.bbox)
175-
: undefined
173+
const countryBounds = useMemo(() => (
174+
(countryResponse && countryResponse.bbox)
175+
? getBbox(countryResponse.bbox)
176+
: undefined
176177
), [countryResponse]);
177178

178179
const query = useMemo<AppealQueryParams>(

app/src/views/CountryOngoingActivitiesThreeWProjects/Map/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,9 @@ function CountryThreeWMap(props: Props) {
170170
} = useGlobalEnums();
171171

172172
const countryBounds = useMemo(() => (
173-
countryResponse ? getBbox(countryResponse.bbox) : undefined
173+
(countryResponse && countryResponse.bbox)
174+
? getBbox(countryResponse.bbox)
175+
: undefined
174176
), [countryResponse]);
175177

176178
const [

app/src/views/CountryProfileRiskWatch/index.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,11 @@ export function Component() {
116116

117117
// NOTE: we always get 1 child in the response
118118
const riskResponse = countryRiskResponse?.[0];
119-
const bbox = useMemo(
120-
() => (countryResponse ? getBbox(countryResponse.bbox) : undefined),
121-
[countryResponse],
122-
);
119+
const bbox = useMemo(() => (
120+
(countryResponse && countryResponse.bbox)
121+
? getBbox(countryResponse.bbox)
122+
: undefined
123+
), [countryResponse]);
123124

124125
return (
125126
<Container

0 commit comments

Comments
 (0)