Skip to content

Commit f83c12b

Browse files
committed
fix: show Local name when available and use English name as fallback
1 parent 4e4faf4 commit f83c12b

File tree

4 files changed

+77
-47
lines changed

4 files changed

+77
-47
lines changed

.changeset/great-carrots-remain.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+
Show Local name when available and use English name as fallback for local units data

app/src/utils/common.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
compareNumber,
33
isNotDefined,
4+
isTruthyString,
45
} from '@togglecorp/fujs';
56

67
import type { GoApiResponse } from '#utils/restRequest';
@@ -75,3 +76,16 @@ export function downloadFile(
7576

7677
URL.revokeObjectURL(url);
7778
}
79+
80+
export function chooseName(
81+
primaryName: string | null | undefined,
82+
secondaryName: string | null | undefined,
83+
) {
84+
if (isTruthyString(primaryName)) {
85+
return primaryName;
86+
}
87+
if (isTruthyString(secondaryName)) {
88+
return secondaryName;
89+
}
90+
return '--';
91+
}

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

Lines changed: 54 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import MapContainerWithDisclaimer from '#components/MapContainerWithDisclaimer';
3636
import MapPopup from '#components/MapPopup';
3737
import useAuth from '#hooks/domain/useAuth';
3838
import useFilterState from '#hooks/useFilterState';
39+
import { chooseName } from '#utils/common';
3940
import {
4041
COLOR_DARK_GREY,
4142
COLOR_PRIMARY_BLUE,
@@ -330,6 +331,16 @@ function LocalUnitsMap() {
330331
&& countryResponse.emails.length > 0;
331332
const hasContactDetails = hasAddress || hasEmails;
332333

334+
const localUnitName = useMemo(() => chooseName(
335+
localUnitDetail?.local_branch_name,
336+
localUnitDetail?.english_branch_name,
337+
), [localUnitDetail?.local_branch_name, localUnitDetail?.english_branch_name]);
338+
339+
const localUnitAddress = useMemo(() => chooseName(
340+
localUnitDetail?.address_loc,
341+
localUnitDetail?.address_en,
342+
), [localUnitDetail?.address_loc, localUnitDetail?.address_en]);
343+
333344
return (
334345
<Container
335346
className={styles.localUnitsMap}
@@ -410,9 +421,7 @@ function LocalUnitsMap() {
410421
popupClassName={styles.mapPopup}
411422
coordinates={clickedPointProperties.lngLat}
412423
onCloseButtonClick={handlePointClose}
413-
heading={isTruthyString(localUnitDetail?.english_branch_name)
414-
? localUnitDetail?.english_branch_name
415-
: localUnitDetail?.local_branch_name ?? '--'}
424+
heading={localUnitName}
416425
contentViewType="vertical"
417426
pending={localUnitDetailPending}
418427
errored={isDefined(localUnitDetailError)}
@@ -429,8 +438,7 @@ function LocalUnitsMap() {
429438
<TextOutput
430439
label={strings.localUnitDetailAddress}
431440
strongLabel
432-
value={localUnitDetail?.address_en
433-
?? localUnitDetail?.address_loc}
441+
value={localUnitAddress}
434442
/>
435443
<TextOutput
436444
label={strings.localUnitLocalUnitType}
@@ -507,48 +515,50 @@ function LocalUnitsMap() {
507515
</Container>
508516
)}
509517
</div>
510-
{isDefined(localUnitsOptions) && (
511-
<Container
512-
contentViewType="vertical"
513-
spacing="comfortable"
514-
>
515-
<Container
516-
heading={strings.localUnitLegendLocalUnitTitle}
517-
headingLevel={4}
518-
contentViewType="grid"
519-
numPreferredGridContentColumns={5}
520-
spacing="compact"
521-
>
522-
{localUnitsOptions?.type.map((legendItem) => (
523-
<LegendItem
524-
key={legendItem.id}
525-
iconSrc={legendItem.image_url}
526-
iconClassName={styles.legendIcon}
527-
color={legendItem.colour ?? COLOR_DARK_GREY}
528-
label={legendItem.name}
529-
/>
530-
))}
531-
</Container>
518+
{
519+
isDefined(localUnitsOptions) && (
532520
<Container
533-
heading={strings.localUnitLegendHealthCareTitle}
534-
headingLevel={5}
535-
contentViewType="grid"
536-
numPreferredGridContentColumns={5}
537-
spacing="compact"
521+
contentViewType="vertical"
522+
spacing="comfortable"
538523
>
539-
{localUnitsOptions?.health_facility_type.map((legendItem) => (
540-
<LegendItem
541-
key={legendItem.id}
542-
// FIXME: use color from server
543-
color={COLOR_PRIMARY_BLUE}
544-
iconSrc={legendItem.image_url}
545-
iconClassName={styles.legendIcon}
546-
label={legendItem.name}
547-
/>
548-
))}
524+
<Container
525+
heading={strings.localUnitLegendLocalUnitTitle}
526+
headingLevel={4}
527+
contentViewType="grid"
528+
numPreferredGridContentColumns={5}
529+
spacing="compact"
530+
>
531+
{localUnitsOptions?.type.map((legendItem) => (
532+
<LegendItem
533+
key={legendItem.id}
534+
iconSrc={legendItem.image_url}
535+
iconClassName={styles.legendIcon}
536+
color={legendItem.colour ?? COLOR_DARK_GREY}
537+
label={legendItem.name}
538+
/>
539+
))}
540+
</Container>
541+
<Container
542+
heading={strings.localUnitLegendHealthCareTitle}
543+
headingLevel={5}
544+
contentViewType="grid"
545+
numPreferredGridContentColumns={5}
546+
spacing="compact"
547+
>
548+
{localUnitsOptions?.health_facility_type.map((legendItem) => (
549+
<LegendItem
550+
key={legendItem.id}
551+
// FIXME: use color from server
552+
color={COLOR_PRIMARY_BLUE}
553+
iconSrc={legendItem.image_url}
554+
iconClassName={styles.legendIcon}
555+
label={legendItem.name}
556+
/>
557+
))}
558+
</Container>
549559
</Container>
550-
</Container>
551-
)}
560+
)
561+
}
552562
</Container>
553563
);
554564
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
} from '@togglecorp/fujs';
1919

2020
import useFilterState from '#hooks/useFilterState';
21+
import { chooseName } from '#utils/common';
2122
import { type CountryOutletContext } from '#utils/outletContext';
2223
import {
2324
type GoApiResponse,
@@ -84,12 +85,12 @@ function LocalUnitsTable() {
8485
createStringColumn<LocalUnitsTableListItem, number>(
8586
'branch_name',
8687
strings.localUnitsTableName,
87-
(item) => item.local_branch_name ?? item.english_branch_name,
88+
(item) => chooseName(item.local_branch_name, item.english_branch_name),
8889
),
8990
createStringColumn<LocalUnitsTableListItem, number>(
9091
'address',
9192
strings.localUnitsTableAddress,
92-
(item) => item.address_loc ?? item.address_en,
93+
(item) => chooseName(item.address_loc, item.address_en),
9394
),
9495
createStringColumn<LocalUnitsTableListItem, number>(
9596
'type',
@@ -100,7 +101,7 @@ function LocalUnitsTable() {
100101
createStringColumn<LocalUnitsTableListItem, number>(
101102
'focal',
102103
strings.localUnitsTableFocal,
103-
(item) => item.focal_person_en,
104+
(item) => chooseName(item.focal_person_loc, item.focal_person_en),
104105
),
105106
createStringColumn<LocalUnitsTableListItem, number>(
106107
'phone',

0 commit comments

Comments
 (0)