1- import { useMemo } from 'react' ;
1+ import {
2+ useCallback ,
3+ useMemo ,
4+ } from 'react' ;
25import {
36 Container ,
47 KeyFigure ,
8+ ReducedListDisplay ,
59 TextOutput ,
610} from '@ifrc-go/ui' ;
711import { useTranslation } from '@ifrc-go/ui/hooks' ;
@@ -10,16 +14,17 @@ import {
1014 maxSafe ,
1115 minSafe ,
1216 resolveToComponent ,
17+ stringNameSelector ,
1318} from '@ifrc-go/ui/utils' ;
1419import {
1520 _cs ,
1621 isDefined ,
1722 unique ,
1823} from '@togglecorp/fujs' ;
1924
25+ import DisplayName from '#components/DisplayName' ;
2026import SeverityIndicator from '#components/domain/SeverityIndicator' ;
2127import Link from '#components/Link' ;
22- import { joinStrings } from '#utils/common' ;
2328import { type GoApiResponse } from '#utils/restRequest' ;
2429
2530import i18n from './i18n.json' ;
@@ -62,29 +67,44 @@ function SurgeCard(props: Props) {
6267 ? getDuration ( new Date ( operationStartDate ) , new Date ( operationEndDate ) ) : undefined ;
6368
6469 const deployedERUTypes = useMemo ( ( ) => (
65- joinStrings ( erus . map ( ( eru ) => eru . type_display ) . filter ( isDefined ) )
70+ unique ( erus
71+ . map ( ( eru ) => eru . type_display )
72+ . filter ( isDefined )
73+ . map ( ( eruType ) => ( { name : eruType } ) ) )
6674 ) , [ erus ] ) ;
6775
6876 const personnel = useMemo ( ( ) => (
6977 deployments . flatMap ( ( deployment ) => deployment . personnel )
7078 ) , [ deployments ] ) ;
7179
7280 const deployedPersonnelTypes = useMemo ( ( ) => (
73- joinStrings ( unique ( personnel . map ( ( person ) => person . role ) . filter ( isDefined ) ) )
81+ unique ( personnel
82+ . map ( ( person ) => person . role )
83+ . filter ( isDefined )
84+ . map ( ( role ) => ( { name : role } ) ) )
7485 ) , [ personnel ] ) ;
7586
7687 const eruDeployingOrganizations = useMemo ( ( ) => (
77- joinStrings ( unique ( erus . map ( ( eru ) => (
78- eru . eru_owner_details . national_society_country_details . society_name
79- ) ) . filter ( isDefined ) ) )
88+ unique ( erus
89+ . map ( ( eru ) => eru . eru_owner_details . national_society_country_details . society_name )
90+ . filter ( isDefined )
91+ . map ( ( nationalSociety ) => ( { name : nationalSociety } ) ) )
8092 ) , [ erus ] ) ;
8193
8294 const personnelDeployingOrganizations = useMemo ( ( ) => (
83- joinStrings ( unique ( personnel . map ( ( person ) => (
84- person . country_from . society_name
85- ) ) . filter ( isDefined ) ) )
95+ unique ( personnel
96+ . map ( ( person ) => ( person . country_from . society_name ) )
97+ . filter ( isDefined )
98+ . map ( ( nationalSociety ) => ( { name : nationalSociety } ) ) )
8699 ) , [ personnel ] ) ;
87100
101+ const rendererParams = useCallback (
102+ ( value : { name : string } ) => ( {
103+ name : value . name ,
104+ } ) ,
105+ [ ] ,
106+ ) ;
107+
88108 return (
89109 < Container
90110 className = { _cs ( styles . surgeCard , className ) }
@@ -132,11 +152,18 @@ function SurgeCard(props: Props) {
132152 childrenContainerClassName = { styles . figures }
133153 footerContent = { (
134154 < TextOutput
135- value = { eruDeployingOrganizations }
155+ value = { (
156+ < ReducedListDisplay
157+ list = { eruDeployingOrganizations }
158+ keySelector = { stringNameSelector }
159+ renderer = { DisplayName }
160+ rendererParams = { rendererParams }
161+ maxItems = { 3 }
162+ />
163+ ) }
136164 label = { strings . surgeDeployingOrganizations }
137165 strongValue
138166 withoutLabelColon
139- valueType = "text"
140167 />
141168 ) }
142169 >
@@ -150,7 +177,15 @@ function SurgeCard(props: Props) {
150177 < TextOutput
151178 className = { styles . figure }
152179 labelClassName = { styles . label }
153- label = { deployedERUTypes }
180+ label = { (
181+ < ReducedListDisplay
182+ list = { deployedERUTypes }
183+ keySelector = { stringNameSelector }
184+ renderer = { DisplayName }
185+ rendererParams = { rendererParams }
186+ maxItems = { 3 }
187+ />
188+ ) }
154189 value = { strings . surgeDeployedERUs }
155190 strongLabel
156191 withoutLabelColon
@@ -168,11 +203,18 @@ function SurgeCard(props: Props) {
168203 footerClassName = { styles . footerContent }
169204 footerContent = { (
170205 < TextOutput
171- value = { personnelDeployingOrganizations }
206+ value = { (
207+ < ReducedListDisplay
208+ list = { personnelDeployingOrganizations }
209+ keySelector = { stringNameSelector }
210+ renderer = { DisplayName }
211+ rendererParams = { rendererParams }
212+ maxItems = { 3 }
213+ />
214+ ) }
172215 label = { strings . surgeDeployingOrganizations }
173216 strongValue
174217 withoutLabelColon
175- valueType = "text"
176218 />
177219 ) }
178220 >
@@ -185,7 +227,15 @@ function SurgeCard(props: Props) {
185227 < div className = { styles . separator } />
186228 < TextOutput
187229 className = { styles . figure }
188- label = { deployedPersonnelTypes }
230+ label = { (
231+ < ReducedListDisplay
232+ list = { deployedPersonnelTypes }
233+ keySelector = { stringNameSelector }
234+ renderer = { DisplayName }
235+ rendererParams = { rendererParams }
236+ maxItems = { 3 }
237+ />
238+ ) }
189239 value = { strings . surgeDeployedRRs }
190240 strongLabel
191241 withoutLabelColon
0 commit comments