44 _cs ,
55 isDefined ,
66 isFalsyString ,
7+ isNotDefined ,
78 isTruthyString ,
89} from '@togglecorp/fujs' ;
910
@@ -14,7 +15,6 @@ import Heading from '#components/printable/Heading';
1415import DescriptionText from '#components/printable/DescriptionText' ;
1516import Link from '#components/Link' ;
1617import DateOutput from '#components/DateOutput' ;
17- import { components } from '#generated/types' ;
1818import useTranslation from '#hooks/useTranslation' ;
1919import { useRequest } from '#utils/restRequest' ;
2020import {
@@ -25,7 +25,7 @@ import {
2525 DREF_TYPE_IMMINENT ,
2626 DisasterCategory ,
2727} from '#utils/constants' ;
28-
28+ import { components } from '#generated/types' ;
2929import ifrcLogo from '#assets/icons/ifrc-square.png' ;
3030
3131import i18n from './i18n.json' ;
@@ -52,57 +52,57 @@ const colorMap: Record<DisasterCategory, string> = {
5252 [ DISASTER_CATEGORY_RED ] : styles . red ,
5353} ;
5454
55- const plannedInterventionSortedList = [
56- ' shelter_housing_and_settlements' ,
57- ' livelihoods_and_basic_needs' ,
58- 'multi-purpose_cash' ,
59- ' health' ,
60- ' water_sanitation_and_hygiene' ,
61- ' protection_gender_and_inclusion' ,
62- ' education' ,
63- 'migration' ,
64- 'risk_reduction_climate_adaptation_and_recovery_' ,
65- ' community_engagement_and_accountability' ,
66- ' environmental_sustainability' ,
67- ' coordination_and_partnerships' ,
68- ' secretariat_services' ,
69- ' national_society_strengthening' ,
70- ] satisfies ( PlannedIntervention [ 'title' ] ) [ ] ;
55+ const plannedInterventionSortedList : Record < NonNullable < PlannedIntervention [ 'title' ] > , number > = {
56+ shelter_housing_and_settlements : 1 ,
57+ livelihoods_and_basic_needs : 2 ,
58+ multi_purpose_cash : 3 ,
59+ health : 4 ,
60+ water_sanitation_and_hygiene : 5 ,
61+ protection_gender_and_inclusion : 6 ,
62+ education : 7 ,
63+ migration_and_displacement : 8 ,
64+ risk_reduction_climate_adaptation_and_recovery : 9 ,
65+ community_engagement_and_accountability : 10 ,
66+ environmental_sustainability : 11 ,
67+ coordination_and_partnerships : 12 ,
68+ secretariat_services : 13 ,
69+ national_society_strengthening : 14 ,
70+ } ;
7171
72- const identifiedNeedsAndGapsSortedList = [
73- ' shelter_housing_and_settlements' ,
74- ' livelihoods_and_basic_needs' ,
75- ' multi_purpose_cash_grants' ,
76- ' health' ,
77- ' water_sanitation_and_hygiene' ,
78- ' protection_gender_and_inclusion' ,
79- ' education' ,
80- 'migration' ,
81- ' risk_reduction_climate_adaptation_and_recovery' ,
82- 'community_engagement_and _accountability' ,
83- ' environment_sustainability ' ,
84- ] satisfies ( IdentifiedNeedsAndGaps [ 'title' ] ) [ ] ;
72+ const identifiedNeedsAndGapsSortedList : Record < NonNullable < IdentifiedNeedsAndGaps [ 'title' ] > , number > = {
73+ shelter_housing_and_settlements : 1 ,
74+ livelihoods_and_basic_needs : 2 ,
75+ multi_purpose_cash_grants : 3 ,
76+ health : 4 ,
77+ water_sanitation_and_hygiene : 5 ,
78+ protection_gender_and_inclusion : 6 ,
79+ education : 7 ,
80+ migration_and_displacement : 8 ,
81+ risk_reduction_climate_adaptation_and_recovery : 9 ,
82+ community_engagement_and_accountability : 10 ,
83+ environment_sustainability : 11 ,
84+ } ;
8585
86- const nsActionsSortedList = [
87- ' shelter_housing_and_settlements' ,
88- ' livelihoods_and_basic_needs' ,
89- 'multi-purpose_cash' ,
90- ' health' ,
91- ' water_sanitation_and_hygiene' ,
92- ' protection_gender_and_inclusion' ,
93- ' education' ,
94- 'migration' ,
95- ' risk_reduction_climate_adaptation_and_recovery' ,
96- 'community_engagement_and _accountability' ,
97- ' environment_sustainability ' ,
98- ' coordination' ,
99- ' national_society_readiness' ,
100- ' assessment' ,
101- ' resource_mobilization' ,
102- ' activation_of_contingency_plans' ,
103- ' national_society_eoc' ,
104- ' other' ,
105- ] satisfies ( NsActions [ 'title' ] ) [ ] ;
86+ const nsActionsSortedList : Record < NsActions [ 'title' ] , number > = {
87+ shelter_housing_and_settlements : 1 ,
88+ livelihoods_and_basic_needs : 2 ,
89+ multi_purpose_cash : 3 ,
90+ health : 4 ,
91+ water_sanitation_and_hygiene : 5 ,
92+ protection_gender_and_inclusion : 6 ,
93+ education : 7 ,
94+ migration_and_displacement : 8 ,
95+ risk_reduction_climate_adaptation_and_recovery : 9 ,
96+ community_engagement_and_accountability : 10 ,
97+ environment_sustainability : 11 ,
98+ coordination : 12 ,
99+ national_society_readiness : 13 ,
100+ assessment : 14 ,
101+ resource_mobilization : 15 ,
102+ activation_of_contingency_plans : 16 ,
103+ national_society_eoc : 17 ,
104+ other : 18 ,
105+ } ;
106106
107107// eslint-disable-next-line import/prefer-default-export
108108export function Component ( ) {
@@ -153,28 +153,58 @@ export function Component() {
153153 } ,
154154 } ) ;
155155
156+ const filteredPlannedIntervention = useMemo (
157+ ( ) => drefResponse ?. planned_interventions ?. map ( ( intervention ) => {
158+ if ( isNotDefined ( intervention . title ) ) {
159+ return undefined ;
160+ }
161+ return { ...intervention , title : intervention . title } ;
162+ } ) . filter ( isDefined ) ,
163+ [ drefResponse ?. planned_interventions ] ,
164+ ) ;
165+
166+ const filteredIdentifiedNeedsAndGaps = useMemo (
167+ ( ) => drefResponse ?. needs_identified ?. map ( ( need ) => {
168+ if ( isNotDefined ( need . title ) ) {
169+ return undefined ;
170+ }
171+ return { ...need , title : need . title } ;
172+ } ) . filter ( isDefined ) ,
173+ [ drefResponse ?. needs_identified ] ,
174+ ) ;
175+
176+ const filteredNsActions = useMemo (
177+ ( ) => drefResponse ?. national_society_actions ?. map ( ( nsAction ) => {
178+ if ( isNotDefined ( nsAction . title ) ) {
179+ return undefined ;
180+ }
181+ return { ...nsAction , title : nsAction . title } ;
182+ } ) . filter ( isDefined ) ,
183+ [ drefResponse ?. national_society_actions ] ,
184+ ) ;
185+
156186 const sortedPlannedInterventions = useMemo (
157- ( ) => drefResponse ?. planned_interventions ?. sort ( ( a , b ) => (
187+ ( ) => filteredPlannedIntervention ?. sort (
158188 // eslint-disable-next-line max-len
159- plannedInterventionSortedList . indexOf ( a . title ) - plannedInterventionSortedList . indexOf ( b . title )
160- ) ) ,
161- [ drefResponse ?. planned_interventions ] ,
189+ ( a , b ) => plannedInterventionSortedList [ a . title ] - plannedInterventionSortedList [ b . title ] ,
190+ ) ,
191+ [ filteredPlannedIntervention ] ,
162192 ) ;
163193
164194 const sortedIdentifiedNeedsAndGaps = useMemo (
165- ( ) => drefResponse ?. needs_identified ?. sort ( ( a , b ) => (
195+ ( ) => filteredIdentifiedNeedsAndGaps ?. sort (
166196 // eslint-disable-next-line max-len
167- identifiedNeedsAndGapsSortedList . indexOf ( a . title ) - identifiedNeedsAndGapsSortedList . indexOf ( b . title )
168- ) ) ,
169- [ drefResponse ?. needs_identified ] ,
197+ ( a , b ) => identifiedNeedsAndGapsSortedList [ a . title ] - identifiedNeedsAndGapsSortedList [ b . title ] ,
198+ ) ,
199+ [ filteredIdentifiedNeedsAndGaps ] ,
170200 ) ;
171201
172202 const sortedNsActions = useMemo (
173- ( ) => drefResponse ?. national_society_actions ?. sort ( ( a , b ) => (
203+ ( ) => filteredNsActions ?. sort ( ( a , b ) => (
174204 // eslint-disable-next-line max-len
175- nsActionsSortedList . indexOf ( a . title ) - nsActionsSortedList . indexOf ( b . title )
205+ nsActionsSortedList [ a . title ] - nsActionsSortedList [ b . title ]
176206 ) ) ,
177- [ drefResponse ?. national_society_actions ] ,
207+ [ filteredNsActions ] ,
178208 ) ;
179209
180210 const eventDescriptionDefined = isTruthyString ( drefResponse ?. event_description ?. trim ( ) ) ;
0 commit comments