From 7b49445021ab7c5019cff65500090e4cf2d26ed9 Mon Sep 17 00:00:00 2001 From: Armanpreet Ghotra Date: Sun, 15 Dec 2024 13:48:08 +0100 Subject: [PATCH 01/18] feat: redesign accordions of fcs and ipc --- src/components/Cards/Card.tsx | 43 ++-- src/components/Map/FcsAccordion.tsx | 199 ------------------ src/components/Map/FcsMap/FcsAccordion.tsx | 43 ++++ .../Map/{ => FcsMap}/FcsChoropleth.tsx | 2 +- .../Map/{ => FcsMap}/FcsCountryChoropleth.tsx | 0 .../Map/FcsMap/FcsFoodSecurityAccordion.tsx | 103 +++++++++ .../Map/FcsMap/FcsMacroEconomicAccordion.tsx | 90 ++++++++ src/components/Map/IpcMap/IpcAccordion.tsx | 64 +----- .../Map/IpcMap/IpcFoodSecurityAccordion.tsx | 67 ++++++ src/components/Map/Map.tsx | 4 +- .../{ => NutritionMap}/NutritionAccordion.tsx | 0 .../NutritionChoropleth.tsx | 2 +- .../NutritionRegionTooltip.tsx | 0 .../NutritionStateChoropleth.tsx | 0 src/domain/entities/cards/CardContent.ts | 8 + src/domain/props/CardProps.tsx | 2 +- src/domain/props/FcsAccordionProps.tsx | 2 +- .../props/IpcFoodSecurityAccordionProps.tsx | 7 + .../NutritionStateChoroplethOperations.tsx | 2 +- 19 files changed, 365 insertions(+), 273 deletions(-) delete mode 100644 src/components/Map/FcsAccordion.tsx create mode 100644 src/components/Map/FcsMap/FcsAccordion.tsx rename src/components/Map/{ => FcsMap}/FcsChoropleth.tsx (98%) rename src/components/Map/{ => FcsMap}/FcsCountryChoropleth.tsx (100%) create mode 100644 src/components/Map/FcsMap/FcsFoodSecurityAccordion.tsx create mode 100644 src/components/Map/FcsMap/FcsMacroEconomicAccordion.tsx create mode 100644 src/components/Map/IpcMap/IpcFoodSecurityAccordion.tsx rename src/components/Map/{ => NutritionMap}/NutritionAccordion.tsx (100%) rename src/components/Map/{ => NutritionMap}/NutritionChoropleth.tsx (98%) rename src/components/Map/{ => NutritionMap}/NutritionRegionTooltip.tsx (100%) rename src/components/Map/{ => NutritionMap}/NutritionStateChoropleth.tsx (100%) create mode 100644 src/domain/props/IpcFoodSecurityAccordionProps.tsx diff --git a/src/components/Cards/Card.tsx b/src/components/Cards/Card.tsx index 9f03a016..00f4223a 100644 --- a/src/components/Cards/Card.tsx +++ b/src/components/Cards/Card.tsx @@ -1,27 +1,46 @@ 'use client'; -import { Card, CardBody, CardHeader, Image } from '@nextui-org/react'; +import { Card, CardBody } from '@nextui-org/react'; +import React from 'react'; import { v4 as uuid } from 'uuid'; import { CardProps } from '@/domain/props/CardProps'; export default function CustomCard({ title, content }: CardProps) { return ( - - -

{title}

-
+ -
+
{content.map((item) => ( -
+
{item.svgIcon ? ( -
{item.svgIcon}
- ) : ( - {item.altText} +
{item.svgIcon}
+ ) : item.imageSrc ? ( + {item.altText + ) : null} +
+ {title &&

{title}

} + {item.text &&

{item.text}

} + {item.value && ( +

+ {typeof item.value === 'number' ? `${item.value.toFixed(2)} M` : item.value || 'N/A'} +

+ )} +
+ {/* Additional Content (Time-based data) */} + {item.changeValues && ( +
+ {item.changeValues.map((delta) => ( +
+ {delta.altText} +
+

{delta.text}

+

{delta.timeText}

+
+
+ ))} +
)} -

{item.text}

- {item.timeText &&

{item.timeText}

}
))}
diff --git a/src/components/Map/FcsAccordion.tsx b/src/components/Map/FcsAccordion.tsx deleted file mode 100644 index 276f735a..00000000 --- a/src/components/Map/FcsAccordion.tsx +++ /dev/null @@ -1,199 +0,0 @@ -import { Spacer } from '@nextui-org/react'; - -import FcsAccordionProps from '@/domain/props/FcsAccordionProps'; -import { FcsAccordionOperations } from '@/operations/map/FcsAccordionOperations'; -import { cardsWrapperClass } from '@/utils/primitives'; - -import { ReactComponent as FoodConsumption } from '../../../public/Images/FoodConsumption.svg'; -import { ReactComponent as Import } from '../../../public/Images/Import.svg'; -import { ReactComponent as Population } from '../../../public/Images/Population.svg'; -import AccordionContainer from '../Accordions/AccordionContainer'; -import CustomCard from '../Cards/Card'; -import { LineChart } from '../Charts/LineChart'; -import CustomInfoCircle from '../CustomInfoCircle/CustomInfoCircle'; - -export default function FcsAccordion({ countryData, loading, countryIso3Data, countryName }: FcsAccordionProps) { - const deltaOneMonth = countryData?.fcsMinus1 ? countryData.fcs - countryData.fcsMinus1 : null; - const deltaThreeMonth = countryData?.fcsMinus3 ? countryData.fcs - countryData.fcsMinus3 : null; - const fcsChartData = FcsAccordionOperations.getFcsChartData(countryData); - const rcsiChartData = FcsAccordionOperations.getRcsiChartData(countryData); - const currencyExchangeChartData = FcsAccordionOperations.getCurrencyExchangeChartData(countryIso3Data); - const balanceOfTradeChartData = FcsAccordionOperations.getBalanceOfTradeChartData(countryIso3Data); - const headlineAndFoodInflationChartData = - FcsAccordionOperations.getHeadlineAndFoodInflationChartData(countryIso3Data); - return ( -
- , - popoverInfo: FcsAccordionOperations.getFoodSecutriyPopoverInfo(), - content: ( -
- , - text: countryData?.population ? `${countryData.population.toFixed(2)} M` : 'N/A', - altText: 'Population Icon', - }, - ]} - /> - , - text: countryData?.fcs ? `${countryData.fcs.toFixed(2)} M` : 'N/A', - altText: 'Food Consumption Icon', - }, - { - imageSrc: deltaOneMonth && deltaOneMonth > 0 ? '/Images/ArrowUp.svg' : '/Images/ArrowDown.svg', - text: deltaOneMonth ? `${deltaOneMonth.toFixed(2)} M` : 'N/A', - timeText: '1 Month ago', - altText: 'Icon', - }, - { - imageSrc: - deltaThreeMonth && deltaThreeMonth > 0 ? '/Images/ArrowUp.svg' : '/Images/ArrowDown.svg', - text: deltaThreeMonth ? `${deltaThreeMonth.toFixed(2)} M` : 'N/A', - timeText: '3 Month ago', - altText: 'Other Icon', - }, - ]} - /> -
- ), - }, - { - title: 'Food Security Trends', - infoIcon: , - popoverInfo: FcsAccordionOperations.getFoodSecutriyTrendsPopoverInfo(), - content: ( -
- {fcsChartData ? ( - - ) : ( -

No data about insufficient food consumption

- )} - - {rcsiChartData ? ( - - ) : ( -

No data about crisis or above crisis food-based coping

- )} -
- ), - }, - { - title: 'Macro-economic', - infoIcon: , - popoverInfo: FcsAccordionOperations.getMacroEconomicPopoverInfo(), - content: ( -
- , - text: countryData?.importDependency - ? `${countryData.importDependency.toFixed(1)}% of Cereals` - : 'N/A', - altText: 'Import Dependency Icon', - }, - ]} - /> -
- ), - }, - { - title: 'Currency Exchange', - infoIcon: , - popoverInfo: FcsAccordionOperations.getCurrencyExchangePopoverInfo(), - content: ( -
- {currencyExchangeChartData ? ( - - ) : ( -

No data about currency exchange

- )} -
- ), - }, - { - title: 'Balance of Trade', - infoIcon: , - popoverInfo: FcsAccordionOperations.getBalanceOfTradePopoverInfo(), - content: ( -
- {balanceOfTradeChartData ? ( - - ) : ( -

No data about balance of trade

- )} -
- ), - }, - { - title: 'Headline and food inflation', - infoIcon: , - popoverInfo: FcsAccordionOperations.getHeadlineAndFoodInflationPopoverInfo(), - content: ( -
- {headlineAndFoodInflationChartData ? ( - - ) : ( -

No data about headline and food inflation

- )} -
- ), - }, - ]} - /> -
- ); -} diff --git a/src/components/Map/FcsMap/FcsAccordion.tsx b/src/components/Map/FcsMap/FcsAccordion.tsx new file mode 100644 index 00000000..ca04ee66 --- /dev/null +++ b/src/components/Map/FcsMap/FcsAccordion.tsx @@ -0,0 +1,43 @@ +import FcsAccordionProps from '@/domain/props/FcsAccordionProps'; +import { useMediaQuery } from '@/utils/resolution.ts'; + +import AccordionContainer from '../../Accordions/AccordionContainer'; +import FcsFoodSecurityAccordion from './FcsFoodSecurityAccordion'; +import FcsMacroEconomicAccordion from './FcsMacroEconomicAccordion'; + +export default function FcsAccordion({ countryData, loading, countryIso3Data, countryName }: FcsAccordionProps) { + const isMobile = useMediaQuery('(max-width: 700px)'); + const foodSecurityAccordion = FcsFoodSecurityAccordion({ countryData }); + const macroEconomicAccordion = FcsMacroEconomicAccordion({ countryData, countryIso3Data }); + + return ( + <> + {!isMobile ? ( +
+ +
+ ) : ( +
+ +
+ )} + {!isMobile && ( +
+ +
+ )} + + ); +} diff --git a/src/components/Map/FcsChoropleth.tsx b/src/components/Map/FcsMap/FcsChoropleth.tsx similarity index 98% rename from src/components/Map/FcsChoropleth.tsx rename to src/components/Map/FcsMap/FcsChoropleth.tsx index ffad7960..fd1ab3fa 100644 --- a/src/components/Map/FcsChoropleth.tsx +++ b/src/components/Map/FcsMap/FcsChoropleth.tsx @@ -11,7 +11,7 @@ import FcsChoroplethProps from '@/domain/props/FcsChoroplethProps'; import FcsChoroplethOperations from '@/operations/map/FcsChoroplethOperations'; import { MapOperations } from '@/operations/map/MapOperations'; -import CountryLoadingLayer from './CountryLoading'; +import CountryLoadingLayer from '../CountryLoading'; import FscCountryChoropleth from './FcsCountryChoropleth'; export default function FcsChoropleth({ diff --git a/src/components/Map/FcsCountryChoropleth.tsx b/src/components/Map/FcsMap/FcsCountryChoropleth.tsx similarity index 100% rename from src/components/Map/FcsCountryChoropleth.tsx rename to src/components/Map/FcsMap/FcsCountryChoropleth.tsx diff --git a/src/components/Map/FcsMap/FcsFoodSecurityAccordion.tsx b/src/components/Map/FcsMap/FcsFoodSecurityAccordion.tsx new file mode 100644 index 00000000..14fdb62f --- /dev/null +++ b/src/components/Map/FcsMap/FcsFoodSecurityAccordion.tsx @@ -0,0 +1,103 @@ +import { Spacer } from '@nextui-org/react'; + +import FcsAccordionProps from '@/domain/props/FcsAccordionProps'; +import { FcsAccordionOperations } from '@/operations/map/FcsAccordionOperations'; +import { cardsWrapperClass } from '@/utils/primitives'; + +import { ReactComponent as FoodConsumption } from '../../../../public/Images/FoodConsumption.svg'; +import { ReactComponent as Population } from '../../../../public/Images/Population.svg'; +import CustomCard from '../../Cards/Card'; +import { LineChart } from '../../Charts/LineChart'; +import CustomInfoCircle from '../../CustomInfoCircle/CustomInfoCircle'; + +export default function FoodSecurityAccordion({ countryData }: FcsAccordionProps) { + const deltaOneMonth = countryData?.fcsMinus1 ? countryData.fcs - countryData.fcsMinus1 : null; + const deltaThreeMonth = countryData?.fcsMinus3 ? countryData.fcs - countryData.fcsMinus3 : null; + const fcsChartData = FcsAccordionOperations.getFcsChartData(countryData); + const rcsiChartData = FcsAccordionOperations.getRcsiChartData(countryData); + + const FcsFoodSecurityAccordion = [ + { + title: 'Food Security', + infoIcon: , + popoverInfo: FcsAccordionOperations.getFoodSecutriyPopoverInfo(), + content: ( +
+ , + text: countryData?.population ? `${countryData.population.toFixed(2)} M` : 'N/A', + altText: 'Population Icon', + textClass: 'text-base', + }, + ]} + /> + , + text: 'Population with insufficient food consumption', + value: countryData?.fcs ? `${countryData.fcs.toFixed(2)} M` : 'N/A', + textClass: 'text-xs', + changeValues: [ + { + imageSrc: deltaOneMonth && deltaOneMonth > 0 ? '/Images/ArrowUp.svg' : '/Images/ArrowDown.svg', + text: deltaOneMonth ? `${deltaOneMonth.toFixed(2)} M` : 'N/A', + timeText: '1 Month ago', + altText: 'Delta Icon', + }, + { + imageSrc: deltaThreeMonth && deltaThreeMonth > 0 ? '/Images/ArrowUp.svg' : '/Images/ArrowDown.svg', + text: deltaThreeMonth ? `${deltaThreeMonth.toFixed(2)} M` : 'N/A', + timeText: '3 Month ago', + altText: 'Delta Icon', + }, + ], + }, + ]} + /> +
+ ), + }, + { + title: 'Food Security Trends', + infoIcon: , + popoverInfo: FcsAccordionOperations.getFoodSecutriyTrendsPopoverInfo(), + content: ( +
+ {fcsChartData ? ( + + ) : ( +

No data about insufficient food consumption

+ )} + + {rcsiChartData ? ( + + ) : ( +

No data about crisis or above crisis food-based coping

+ )} +
+ ), + }, + ]; + + return FcsFoodSecurityAccordion; +} diff --git a/src/components/Map/FcsMap/FcsMacroEconomicAccordion.tsx b/src/components/Map/FcsMap/FcsMacroEconomicAccordion.tsx new file mode 100644 index 00000000..139adbf9 --- /dev/null +++ b/src/components/Map/FcsMap/FcsMacroEconomicAccordion.tsx @@ -0,0 +1,90 @@ +import FcsAccordionProps from '@/domain/props/FcsAccordionProps'; +import { FcsAccordionOperations } from '@/operations/map/FcsAccordionOperations'; +import { cardsWrapperClass } from '@/utils/primitives'; + +import { ReactComponent as Import } from '../../../../public/Images/Import.svg'; +import CustomCard from '../../Cards/Card'; +import { LineChart } from '../../Charts/LineChart'; +import CustomInfoCircle from '../../CustomInfoCircle/CustomInfoCircle'; + +export default function MacroEconomicAccordion({ countryData, countryIso3Data }: FcsAccordionProps) { + const currencyExchangeChartData = FcsAccordionOperations.getCurrencyExchangeChartData(countryIso3Data); + const balanceOfTradeChartData = FcsAccordionOperations.getBalanceOfTradeChartData(countryIso3Data); + const headlineAndFoodInflationChartData = + FcsAccordionOperations.getHeadlineAndFoodInflationChartData(countryIso3Data); + + const FcsMacroEconomicAccordion = [ + { + title: 'Macroeconomic', + infoIcon: , + popoverInfo: FcsAccordionOperations.getMacroEconomicPopoverInfo(), + content: ( +
+ , + text: countryData?.importDependency ? `${countryData.importDependency.toFixed(1)}% of Cereals` : 'N/A', + altText: 'Import Dependency Icon', + textClass: 'text-base', + }, + ]} + /> +
+ ), + }, + { + title: 'Currency Exchange', + infoIcon: , + popoverInfo: FcsAccordionOperations.getCurrencyExchangePopoverInfo(), + content: ( +
+ {currencyExchangeChartData ? ( + + ) : ( +

No data about currency exchange

+ )} +
+ ), + }, + { + title: 'Balance of Trade', + infoIcon: , + popoverInfo: FcsAccordionOperations.getBalanceOfTradePopoverInfo(), + content: ( +
+ {balanceOfTradeChartData ? ( + + ) : ( +

No data about balance of trade

+ )} +
+ ), + }, + { + title: 'Headline and food inflation', + infoIcon: , + popoverInfo: FcsAccordionOperations.getHeadlineAndFoodInflationPopoverInfo(), + content: ( +
+ {headlineAndFoodInflationChartData ? ( + + ) : ( +

No data about headline and food inflation

+ )} +
+ ), + }, + ]; + + return FcsMacroEconomicAccordion; +} diff --git a/src/components/Map/IpcMap/IpcAccordion.tsx b/src/components/Map/IpcMap/IpcAccordion.tsx index 57ec55e6..47c41aee 100644 --- a/src/components/Map/IpcMap/IpcAccordion.tsx +++ b/src/components/Map/IpcMap/IpcAccordion.tsx @@ -1,71 +1,25 @@ import AccordionContainer from '@/components/Accordions/AccordionContainer'; -import CustomCard from '@/components/Cards/Card'; -import CustomInfoCircle from '@/components/CustomInfoCircle/CustomInfoCircle'; import IpcAccordionProps from '@/domain/props/IpcAccordionProps'; -import { FcsAccordionOperations } from '@/operations/map/FcsAccordionOperations'; -import { cardsWrapperClass } from '@/utils/primitives'; -import { ReactComponent as FoodConsumption } from '../../../../public/Images/FoodConsumption.svg'; -import { ReactComponent as Population } from '../../../../public/Images/Population.svg'; +import IpcFoodSecurityAccordion from './IpcFoodSecurityAccordion'; export default function IpcAccordion({ countryData, countryName }: IpcAccordionProps) { const deltaOneMonth = countryData?.fcsMinus1 ? countryData.fcs - countryData.fcsMinus1 : null; const deltaThreeMonth = countryData?.fcsMinus3 ? countryData.fcs - countryData.fcsMinus3 : null; - const hasNoData: boolean = - !countryData || !countryData.population || !countryData.fcs || !deltaOneMonth || !deltaThreeMonth; + + const ipcFoodSecurityAccordion = IpcFoodSecurityAccordion({ + countryData, + deltaOneMonth, + deltaThreeMonth, + }); return ( -
+
, - popoverInfo: FcsAccordionOperations.getFoodSecutriyPopoverInfo(), - content: !hasNoData ? ( -
- , - text: countryData?.population ? `${countryData?.population.toFixed(2)} M` : 'N/A', - altText: 'Population Icon', - }, - ]} - /> - , - text: countryData?.fcs ? `${countryData?.fcs.toFixed(2)} M` : 'N/A', - altText: 'Food Consumption Icon', - }, - { - imageSrc: deltaOneMonth && deltaOneMonth > 0 ? '/Images/ArrowUp.svg' : '/Images/ArrowDown.svg', - text: deltaOneMonth ? `${deltaOneMonth.toFixed(2)} M` : 'N/A', - timeText: '1 Months ago', - altText: 'Other Icon', - }, - { - imageSrc: - deltaThreeMonth && deltaThreeMonth > 0 ? '/Images/ArrowUp.svg' : '/Images/ArrowDown.svg', - text: deltaThreeMonth ? `${deltaThreeMonth.toFixed(2)} M` : 'N/A', - timeText: '3 Month ago', - altText: 'Other Icon', - }, - ]} - /> -
- ) : ( -

No data about food security

- ), - }, - ]} + items={[ipcFoodSecurityAccordion]} />
); diff --git a/src/components/Map/IpcMap/IpcFoodSecurityAccordion.tsx b/src/components/Map/IpcMap/IpcFoodSecurityAccordion.tsx new file mode 100644 index 00000000..601d2d7b --- /dev/null +++ b/src/components/Map/IpcMap/IpcFoodSecurityAccordion.tsx @@ -0,0 +1,67 @@ +import React from 'react'; + +import CustomCard from '@/components/Cards/Card'; +import CustomInfoCircle from '@/components/CustomInfoCircle/CustomInfoCircle'; +import IpcFoodSecurityAccordionProps from '@/domain/props/IpcFoodSecurityAccordionProps'; +import { FcsAccordionOperations } from '@/operations/map/FcsAccordionOperations'; +import { cardsWrapperClass } from '@/utils/primitives'; + +import { ReactComponent as FoodConsumption } from '../../../../public/Images/FoodConsumption.svg'; +import { ReactComponent as Population } from '../../../../public/Images/Population.svg'; + +export default function IpcFoodSecurityAccordion({ + countryData, + deltaOneMonth, + deltaThreeMonth, +}: IpcFoodSecurityAccordionProps) { + const hasNoData: boolean = + !countryData || !countryData.population || !countryData.fcs || !deltaOneMonth || !deltaThreeMonth; + + return { + title: 'Food Security', + infoIcon: , + popoverInfo: FcsAccordionOperations.getFoodSecutriyPopoverInfo(), + content: !hasNoData ? ( +
+ {/* Population Card */} + , + text: countryData?.population ? `${countryData?.population.toFixed(2)} M` : 'N/A', + altText: 'Population Icon', + textClass: 'text-base', + }, + ]} + /> + , + text: 'Population with insufficient food consumption', + value: countryData?.fcs ? `${countryData?.fcs.toFixed(2)} M` : 'N/A', + textClass: 'text-xs', + changeValues: [ + { + imageSrc: deltaOneMonth && deltaOneMonth > 0 ? '/Images/ArrowUp.svg' : '/Images/ArrowDown.svg', + text: deltaOneMonth ? `${deltaOneMonth.toFixed(2)} M` : 'N/A', + timeText: '1 Month ago', + altText: 'Delta Icon', + }, + { + imageSrc: deltaThreeMonth && deltaThreeMonth > 0 ? '/Images/ArrowUp.svg' : '/Images/ArrowDown.svg', + text: deltaThreeMonth ? `${deltaThreeMonth.toFixed(2)} M` : 'N/A', + timeText: '3 Month ago', + altText: 'Delta Icon', + }, + ], + }, + ]} + /> +
+ ) : ( +

No data about food security

+ ), + }; +} diff --git a/src/components/Map/Map.tsx b/src/components/Map/Map.tsx index 195ebbed..01db6a9c 100644 --- a/src/components/Map/Map.tsx +++ b/src/components/Map/Map.tsx @@ -26,9 +26,9 @@ import { MapProps } from '@/domain/props/MapProps'; import { MapOperations } from '@/operations/map/MapOperations'; import { AlertContainer } from './Alerts/AlertContainer'; -import FcsChoropleth from './FcsChoropleth'; +import FcsChoropleth from './FcsMap/FcsChoropleth'; import IpcChoropleth from './IpcMap/IpcChoropleth'; -import NutritionChoropleth from './NutritionChoropleth'; +import NutritionChoropleth from './NutritionMap/NutritionChoropleth'; import ZoomControl from './ZoomControl'; export default function Map({ countries, disputedAreas, fcsData, alertData }: MapProps) { diff --git a/src/components/Map/NutritionAccordion.tsx b/src/components/Map/NutritionMap/NutritionAccordion.tsx similarity index 100% rename from src/components/Map/NutritionAccordion.tsx rename to src/components/Map/NutritionMap/NutritionAccordion.tsx diff --git a/src/components/Map/NutritionChoropleth.tsx b/src/components/Map/NutritionMap/NutritionChoropleth.tsx similarity index 98% rename from src/components/Map/NutritionChoropleth.tsx rename to src/components/Map/NutritionMap/NutritionChoropleth.tsx index 3dd4d627..3e9b0ff8 100644 --- a/src/components/Map/NutritionChoropleth.tsx +++ b/src/components/Map/NutritionMap/NutritionChoropleth.tsx @@ -12,7 +12,7 @@ import NutritionChoroplethProps from '@/domain/props/NutritionChoroplethProps'; import { MapOperations } from '@/operations/map/MapOperations'; import NutritionChoroplethOperations from '@/operations/map/NutritionChoroplethOperations'; -import CountryLoadingLayer from './CountryLoading'; +import CountryLoadingLayer from '../CountryLoading'; import NutritionStateChoropleth from './NutritionStateChoropleth'; export default function NutritionChoropleth({ diff --git a/src/components/Map/NutritionRegionTooltip.tsx b/src/components/Map/NutritionMap/NutritionRegionTooltip.tsx similarity index 100% rename from src/components/Map/NutritionRegionTooltip.tsx rename to src/components/Map/NutritionMap/NutritionRegionTooltip.tsx diff --git a/src/components/Map/NutritionStateChoropleth.tsx b/src/components/Map/NutritionMap/NutritionStateChoropleth.tsx similarity index 100% rename from src/components/Map/NutritionStateChoropleth.tsx rename to src/components/Map/NutritionMap/NutritionStateChoropleth.tsx diff --git a/src/domain/entities/cards/CardContent.ts b/src/domain/entities/cards/CardContent.ts index 091f7fce..62dd7462 100644 --- a/src/domain/entities/cards/CardContent.ts +++ b/src/domain/entities/cards/CardContent.ts @@ -2,7 +2,15 @@ export interface CardContent { imageSrc?: string; svgIcon?: React.ReactNode; text?: string; + value?: string | number; content?: React.ReactNode; timeText?: string; altText?: string; + changeValues?: { + imageSrc: string; + text: string; + timeText: string; + altText: string; + }[]; + textClass?: string; } diff --git a/src/domain/props/CardProps.tsx b/src/domain/props/CardProps.tsx index 395c2dbf..7c3915a2 100644 --- a/src/domain/props/CardProps.tsx +++ b/src/domain/props/CardProps.tsx @@ -1,6 +1,6 @@ import { CardContent } from '../entities/cards/CardContent'; export interface CardProps { - title: string; + title?: string; content: CardContent[]; } diff --git a/src/domain/props/FcsAccordionProps.tsx b/src/domain/props/FcsAccordionProps.tsx index d17756bf..fa9e49c8 100644 --- a/src/domain/props/FcsAccordionProps.tsx +++ b/src/domain/props/FcsAccordionProps.tsx @@ -4,6 +4,6 @@ import { CountryIso3Data } from '../entities/country/CountryIso3Data'; export default interface FcsAccordionProps { countryData?: CountryData; countryIso3Data?: CountryIso3Data; - loading: boolean; + loading?: boolean; countryName?: string; } diff --git a/src/domain/props/IpcFoodSecurityAccordionProps.tsx b/src/domain/props/IpcFoodSecurityAccordionProps.tsx new file mode 100644 index 00000000..debee2c0 --- /dev/null +++ b/src/domain/props/IpcFoodSecurityAccordionProps.tsx @@ -0,0 +1,7 @@ +import { CountryData } from '../entities/country/CountryData'; + +export default interface IpcFoodSecurityAccordionProps { + countryData: CountryData | undefined; + deltaOneMonth: number | null; + deltaThreeMonth: number | null; +} diff --git a/src/operations/map/NutritionStateChoroplethOperations.tsx b/src/operations/map/NutritionStateChoroplethOperations.tsx index 7b34d87a..87db874d 100644 --- a/src/operations/map/NutritionStateChoroplethOperations.tsx +++ b/src/operations/map/NutritionStateChoroplethOperations.tsx @@ -2,7 +2,7 @@ import { Feature } from 'geojson'; import { PathOptions } from 'leaflet'; import { createRoot } from 'react-dom/client'; -import NutritionRegionTooltip from '@/components/Map/NutritionRegionTooltip'; +import NutritionRegionTooltip from '@/components/Map/NutritionMap/NutritionRegionTooltip'; import { NUTRIENT_LABELS } from '@/domain/constant/map/NutritionChoropleth.ts'; import { LayerWithFeature } from '@/domain/entities/map/LayerWithFeature.ts'; import { Nutrition } from '@/domain/entities/region/RegionNutritionProperties.ts'; From a2d5221f66c67fbe75fa131fd1a2575d19dc7b83 Mon Sep 17 00:00:00 2001 From: Armanpreet Ghotra Date: Mon, 16 Dec 2024 10:19:38 +0100 Subject: [PATCH 02/18] feat: add nutrition accordion in ipc and fcs --- public/Images/Nutrition.svg | 5 + src/components/Cards/Card.tsx | 15 +- src/components/Map/FcsMap/FcsAccordion.tsx | 8 +- .../Map/FcsMap/FcsFoodSecurityAccordion.tsx | 102 +----------- .../Map/FcsMap/FcsMacroEconomicAccordion.tsx | 87 +--------- src/components/Map/IpcMap/IpcAccordion.tsx | 7 +- src/components/Map/IpcMap/IpcChoropleth.tsx | 9 +- .../Map/IpcMap/IpcCountryChoropleth.tsx | 4 +- .../Map/IpcMap/IpcFoodSecurityAccordion.tsx | 66 +------- .../Map/IpcMap/IpcNutritionAccordion.tsx | 7 + src/components/Map/Map.tsx | 1 + src/domain/entities/cards/CardContent.ts | 2 +- src/domain/props/IpcAccordionProps.tsx | 2 + src/domain/props/IpcChoroplethProps.tsx | 3 + .../props/IpcCountryChoroplethProps.tsx | 2 + .../props/IpcNutritionAccordionProps.tsx | 5 + src/operations/map/FcsAccordionOperations.tsx | 12 ++ .../map/FcsFoodSecurityOperations.tsx | 151 ++++++++++++++++++ .../map/FcsMacroEconomicOperations.tsx | 93 +++++++++++ .../map/IpcFoodSecurityOperations.tsx | 119 ++++++++++++++ src/operations/map/MapOperations.tsx | 2 +- src/utils/primitives.ts | 2 +- 22 files changed, 444 insertions(+), 260 deletions(-) create mode 100644 public/Images/Nutrition.svg create mode 100644 src/components/Map/IpcMap/IpcNutritionAccordion.tsx create mode 100644 src/domain/props/IpcNutritionAccordionProps.tsx create mode 100644 src/operations/map/FcsFoodSecurityOperations.tsx create mode 100644 src/operations/map/FcsMacroEconomicOperations.tsx create mode 100644 src/operations/map/IpcFoodSecurityOperations.tsx diff --git a/public/Images/Nutrition.svg b/public/Images/Nutrition.svg new file mode 100644 index 00000000..1dc24e38 --- /dev/null +++ b/public/Images/Nutrition.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/src/components/Cards/Card.tsx b/src/components/Cards/Card.tsx index 00f4223a..b21be237 100644 --- a/src/components/Cards/Card.tsx +++ b/src/components/Cards/Card.tsx @@ -1,6 +1,7 @@ 'use client'; import { Card, CardBody } from '@nextui-org/react'; +import Image from 'next/image'; import React from 'react'; import { v4 as uuid } from 'uuid'; @@ -9,20 +10,20 @@ import { CardProps } from '@/domain/props/CardProps'; export default function CustomCard({ title, content }: CardProps) { return ( - -
+ +
{content.map((item) => (
{item.svgIcon ? (
{item.svgIcon}
) : item.imageSrc ? ( - {item.altText + {item.altText ) : null}
- {title &&

{title}

} - {item.text &&

{item.text}

} + {title &&

{title}

} + {item.text &&

{item.text}

} {item.value && ( -

+

{typeof item.value === 'number' ? `${item.value.toFixed(2)} M` : item.value || 'N/A'}

)} @@ -32,7 +33,7 @@ export default function CustomCard({ title, content }: CardProps) {
{item.changeValues.map((delta) => (
- {delta.altText} + {delta.altText}

{delta.text}

{delta.timeText}

diff --git a/src/components/Map/FcsMap/FcsAccordion.tsx b/src/components/Map/FcsMap/FcsAccordion.tsx index ca04ee66..809b6595 100644 --- a/src/components/Map/FcsMap/FcsAccordion.tsx +++ b/src/components/Map/FcsMap/FcsAccordion.tsx @@ -7,19 +7,23 @@ import FcsMacroEconomicAccordion from './FcsMacroEconomicAccordion'; export default function FcsAccordion({ countryData, loading, countryIso3Data, countryName }: FcsAccordionProps) { const isMobile = useMediaQuery('(max-width: 700px)'); - const foodSecurityAccordion = FcsFoodSecurityAccordion({ countryData }); + const foodSecurityAccordion = FcsFoodSecurityAccordion({ countryData, countryIso3Data }); const macroEconomicAccordion = FcsMacroEconomicAccordion({ countryData, countryIso3Data }); return ( <> {!isMobile ? ( -
+
) : ( diff --git a/src/components/Map/FcsMap/FcsFoodSecurityAccordion.tsx b/src/components/Map/FcsMap/FcsFoodSecurityAccordion.tsx index 14fdb62f..f093297f 100644 --- a/src/components/Map/FcsMap/FcsFoodSecurityAccordion.tsx +++ b/src/components/Map/FcsMap/FcsFoodSecurityAccordion.tsx @@ -1,103 +1,7 @@ -import { Spacer } from '@nextui-org/react'; - import FcsAccordionProps from '@/domain/props/FcsAccordionProps'; -import { FcsAccordionOperations } from '@/operations/map/FcsAccordionOperations'; -import { cardsWrapperClass } from '@/utils/primitives'; - -import { ReactComponent as FoodConsumption } from '../../../../public/Images/FoodConsumption.svg'; -import { ReactComponent as Population } from '../../../../public/Images/Population.svg'; -import CustomCard from '../../Cards/Card'; -import { LineChart } from '../../Charts/LineChart'; -import CustomInfoCircle from '../../CustomInfoCircle/CustomInfoCircle'; - -export default function FoodSecurityAccordion({ countryData }: FcsAccordionProps) { - const deltaOneMonth = countryData?.fcsMinus1 ? countryData.fcs - countryData.fcsMinus1 : null; - const deltaThreeMonth = countryData?.fcsMinus3 ? countryData.fcs - countryData.fcsMinus3 : null; - const fcsChartData = FcsAccordionOperations.getFcsChartData(countryData); - const rcsiChartData = FcsAccordionOperations.getRcsiChartData(countryData); - - const FcsFoodSecurityAccordion = [ - { - title: 'Food Security', - infoIcon: , - popoverInfo: FcsAccordionOperations.getFoodSecutriyPopoverInfo(), - content: ( -
- , - text: countryData?.population ? `${countryData.population.toFixed(2)} M` : 'N/A', - altText: 'Population Icon', - textClass: 'text-base', - }, - ]} - /> - , - text: 'Population with insufficient food consumption', - value: countryData?.fcs ? `${countryData.fcs.toFixed(2)} M` : 'N/A', - textClass: 'text-xs', - changeValues: [ - { - imageSrc: deltaOneMonth && deltaOneMonth > 0 ? '/Images/ArrowUp.svg' : '/Images/ArrowDown.svg', - text: deltaOneMonth ? `${deltaOneMonth.toFixed(2)} M` : 'N/A', - timeText: '1 Month ago', - altText: 'Delta Icon', - }, - { - imageSrc: deltaThreeMonth && deltaThreeMonth > 0 ? '/Images/ArrowUp.svg' : '/Images/ArrowDown.svg', - text: deltaThreeMonth ? `${deltaThreeMonth.toFixed(2)} M` : 'N/A', - timeText: '3 Month ago', - altText: 'Delta Icon', - }, - ], - }, - ]} - /> -
- ), - }, - { - title: 'Food Security Trends', - infoIcon: , - popoverInfo: FcsAccordionOperations.getFoodSecutriyTrendsPopoverInfo(), - content: ( -
- {fcsChartData ? ( - - ) : ( -

No data about insufficient food consumption

- )} - - {rcsiChartData ? ( - - ) : ( -

No data about crisis or above crisis food-based coping

- )} -
- ), - }, - ]; +import { getFcsFoodSecurityAccordionItems } from '@/operations/map/FcsFoodSecurityOperations'; +export default function FoodSecurityAccordion({ countryData, countryIso3Data }: FcsAccordionProps) { + const FcsFoodSecurityAccordion = getFcsFoodSecurityAccordionItems(countryData, countryIso3Data); return FcsFoodSecurityAccordion; } diff --git a/src/components/Map/FcsMap/FcsMacroEconomicAccordion.tsx b/src/components/Map/FcsMap/FcsMacroEconomicAccordion.tsx index 139adbf9..253855ef 100644 --- a/src/components/Map/FcsMap/FcsMacroEconomicAccordion.tsx +++ b/src/components/Map/FcsMap/FcsMacroEconomicAccordion.tsx @@ -1,90 +1,7 @@ import FcsAccordionProps from '@/domain/props/FcsAccordionProps'; -import { FcsAccordionOperations } from '@/operations/map/FcsAccordionOperations'; -import { cardsWrapperClass } from '@/utils/primitives'; - -import { ReactComponent as Import } from '../../../../public/Images/Import.svg'; -import CustomCard from '../../Cards/Card'; -import { LineChart } from '../../Charts/LineChart'; -import CustomInfoCircle from '../../CustomInfoCircle/CustomInfoCircle'; +import { getMacroEconomicAccordionOperations } from '@/operations/map/FcsMacroEconomicOperations'; export default function MacroEconomicAccordion({ countryData, countryIso3Data }: FcsAccordionProps) { - const currencyExchangeChartData = FcsAccordionOperations.getCurrencyExchangeChartData(countryIso3Data); - const balanceOfTradeChartData = FcsAccordionOperations.getBalanceOfTradeChartData(countryIso3Data); - const headlineAndFoodInflationChartData = - FcsAccordionOperations.getHeadlineAndFoodInflationChartData(countryIso3Data); - - const FcsMacroEconomicAccordion = [ - { - title: 'Macroeconomic', - infoIcon: , - popoverInfo: FcsAccordionOperations.getMacroEconomicPopoverInfo(), - content: ( -
- , - text: countryData?.importDependency ? `${countryData.importDependency.toFixed(1)}% of Cereals` : 'N/A', - altText: 'Import Dependency Icon', - textClass: 'text-base', - }, - ]} - /> -
- ), - }, - { - title: 'Currency Exchange', - infoIcon: , - popoverInfo: FcsAccordionOperations.getCurrencyExchangePopoverInfo(), - content: ( -
- {currencyExchangeChartData ? ( - - ) : ( -

No data about currency exchange

- )} -
- ), - }, - { - title: 'Balance of Trade', - infoIcon: , - popoverInfo: FcsAccordionOperations.getBalanceOfTradePopoverInfo(), - content: ( -
- {balanceOfTradeChartData ? ( - - ) : ( -

No data about balance of trade

- )} -
- ), - }, - { - title: 'Headline and food inflation', - infoIcon: , - popoverInfo: FcsAccordionOperations.getHeadlineAndFoodInflationPopoverInfo(), - content: ( -
- {headlineAndFoodInflationChartData ? ( - - ) : ( -

No data about headline and food inflation

- )} -
- ), - }, - ]; - + const FcsMacroEconomicAccordion = getMacroEconomicAccordionOperations(countryData, countryIso3Data); return FcsMacroEconomicAccordion; } diff --git a/src/components/Map/IpcMap/IpcAccordion.tsx b/src/components/Map/IpcMap/IpcAccordion.tsx index 47c41aee..e36bbb75 100644 --- a/src/components/Map/IpcMap/IpcAccordion.tsx +++ b/src/components/Map/IpcMap/IpcAccordion.tsx @@ -2,8 +2,9 @@ import AccordionContainer from '@/components/Accordions/AccordionContainer'; import IpcAccordionProps from '@/domain/props/IpcAccordionProps'; import IpcFoodSecurityAccordion from './IpcFoodSecurityAccordion'; +import IpcNutritionAccordion from './IpcNutritionAccordion'; -export default function IpcAccordion({ countryData, countryName }: IpcAccordionProps) { +export default function IpcAccordion({ countryData, countryName, countryIso3Data }: IpcAccordionProps) { const deltaOneMonth = countryData?.fcsMinus1 ? countryData.fcs - countryData.fcsMinus1 : null; const deltaThreeMonth = countryData?.fcsMinus3 ? countryData.fcs - countryData.fcsMinus3 : null; @@ -12,6 +13,7 @@ export default function IpcAccordion({ countryData, countryName }: IpcAccordionP deltaOneMonth, deltaThreeMonth, }); + const ipcNutrititonAccordion = IpcNutritionAccordion({ countryIso3Data }); return (
@@ -19,7 +21,8 @@ export default function IpcAccordion({ countryData, countryName }: IpcAccordionP title={countryName ?? undefined} accordionModalActive maxWidth={600} - items={[ipcFoodSecurityAccordion]} + items={[ipcFoodSecurityAccordion, ipcNutrititonAccordion]} + expandAll />
); diff --git a/src/components/Map/IpcMap/IpcChoropleth.tsx b/src/components/Map/IpcMap/IpcChoropleth.tsx index 5dcb627a..431975c1 100644 --- a/src/components/Map/IpcMap/IpcChoropleth.tsx +++ b/src/components/Map/IpcMap/IpcChoropleth.tsx @@ -9,7 +9,13 @@ import { IpcChoroplethProps } from '@/domain/props/IpcChoroplethProps'; import IpcCountryChoropleth from './IpcCountryChoropleth'; import IpcGlobalChoropleth from './IpcGlobalChoropleth'; -function IpcChoropleth({ countries, countryData, ipcRegionData, selectedCountryName }: IpcChoroplethProps) { +function IpcChoropleth({ + countries, + countryData, + ipcRegionData, + selectedCountryName, + countryIso3Data, +}: IpcChoroplethProps) { const { data: ipcData } = useIpcQuery(true); const { selectedCountryId, setSelectedCountryId } = useSelectedCountryId(); @@ -41,6 +47,7 @@ function IpcChoropleth({ countries, countryData, ipcRegionData, selectedCountryN regionIpcData={ipcRegionData} countryData={countryData} countryName={selectedCountryName} + countryIso3Data={countryIso3Data} /> )} diff --git a/src/components/Map/IpcMap/IpcCountryChoropleth.tsx b/src/components/Map/IpcMap/IpcCountryChoropleth.tsx index 77284d9b..f342ce09 100644 --- a/src/components/Map/IpcMap/IpcCountryChoropleth.tsx +++ b/src/components/Map/IpcMap/IpcCountryChoropleth.tsx @@ -7,13 +7,13 @@ import { IpcChoroplethOperations } from '@/operations/map/IpcChoroplethOperation import IpcAccordion from './IpcAccordion'; -function IpcCountryChoropleth({ regionIpcData, countryData, countryName }: IpcCountryChoroplethProps) { +function IpcCountryChoropleth({ regionIpcData, countryData, countryName, countryIso3Data }: IpcCountryChoroplethProps) { const handleCountryFeature = (feature: Feature, layer: L.Layer) => { IpcChoroplethOperations.attachEventsRegion(feature, layer); }; return ( <> - + , - popoverInfo: FcsAccordionOperations.getFoodSecutriyPopoverInfo(), - content: !hasNoData ? ( -
- {/* Population Card */} - , - text: countryData?.population ? `${countryData?.population.toFixed(2)} M` : 'N/A', - altText: 'Population Icon', - textClass: 'text-base', - }, - ]} - /> - , - text: 'Population with insufficient food consumption', - value: countryData?.fcs ? `${countryData?.fcs.toFixed(2)} M` : 'N/A', - textClass: 'text-xs', - changeValues: [ - { - imageSrc: deltaOneMonth && deltaOneMonth > 0 ? '/Images/ArrowUp.svg' : '/Images/ArrowDown.svg', - text: deltaOneMonth ? `${deltaOneMonth.toFixed(2)} M` : 'N/A', - timeText: '1 Month ago', - altText: 'Delta Icon', - }, - { - imageSrc: deltaThreeMonth && deltaThreeMonth > 0 ? '/Images/ArrowUp.svg' : '/Images/ArrowDown.svg', - text: deltaThreeMonth ? `${deltaThreeMonth.toFixed(2)} M` : 'N/A', - timeText: '3 Month ago', - altText: 'Delta Icon', - }, - ], - }, - ]} - /> -
- ) : ( -

No data about food security

- ), - }; + const foodSecurityAccordion = IpcFoodSecurityAccordionOperations.getFoodSecurityAccordionItems( + countryData, + deltaOneMonth, + deltaThreeMonth + ); + return foodSecurityAccordion; } diff --git a/src/components/Map/IpcMap/IpcNutritionAccordion.tsx b/src/components/Map/IpcMap/IpcNutritionAccordion.tsx new file mode 100644 index 00000000..7efa4e2d --- /dev/null +++ b/src/components/Map/IpcMap/IpcNutritionAccordion.tsx @@ -0,0 +1,7 @@ +import IpcNutritionAccordionProps from '@/domain/props/IpcNutritionAccordionProps'; +import { IpcFoodSecurityAccordionOperations } from '@/operations/map/IpcFoodSecurityOperations'; + +export default function IpcNutritionAccordion({ countryIso3Data }: IpcNutritionAccordionProps) { + const nutritionAccordion = IpcFoodSecurityAccordionOperations.getNutritionAccordion(countryIso3Data); + return nutritionAccordion; +} diff --git a/src/components/Map/Map.tsx b/src/components/Map/Map.tsx index 01db6a9c..2ea3c0c3 100644 --- a/src/components/Map/Map.tsx +++ b/src/components/Map/Map.tsx @@ -173,6 +173,7 @@ export default function Map({ countries, disputedAreas, fcsData, alertData }: Ma countryData={countryData} ipcRegionData={ipcRegionData} selectedCountryName={selectedCountryName} + countryIso3Data={countryIso3Data} /> )} diff --git a/src/domain/entities/cards/CardContent.ts b/src/domain/entities/cards/CardContent.ts index 62dd7462..a593d4a9 100644 --- a/src/domain/entities/cards/CardContent.ts +++ b/src/domain/entities/cards/CardContent.ts @@ -1,7 +1,7 @@ export interface CardContent { imageSrc?: string; svgIcon?: React.ReactNode; - text?: string; + text?: React.ReactNode; value?: string | number; content?: React.ReactNode; timeText?: string; diff --git a/src/domain/props/IpcAccordionProps.tsx b/src/domain/props/IpcAccordionProps.tsx index e60f69a7..78e96cf9 100644 --- a/src/domain/props/IpcAccordionProps.tsx +++ b/src/domain/props/IpcAccordionProps.tsx @@ -1,6 +1,8 @@ import { CountryData } from '../entities/country/CountryData'; +import { CountryIso3Data } from '../entities/country/CountryIso3Data'; export default interface IpcAccordionProps { countryData: CountryData | undefined; countryName?: string; + countryIso3Data: CountryIso3Data | undefined; } diff --git a/src/domain/props/IpcChoroplethProps.tsx b/src/domain/props/IpcChoroplethProps.tsx index 28728fa1..8f87d388 100644 --- a/src/domain/props/IpcChoroplethProps.tsx +++ b/src/domain/props/IpcChoroplethProps.tsx @@ -3,10 +3,13 @@ import { FeatureCollection, GeoJsonProperties, Geometry } from 'geojson'; import { CountryData } from '@/domain/entities/country/CountryData.ts'; import { CountryMapDataWrapper } from '@/domain/entities/country/CountryMapData'; +import { CountryIso3Data } from '../entities/country/CountryIso3Data'; + export interface IpcChoroplethProps { countries: CountryMapDataWrapper; handleBackButtonClick?: () => void; countryData?: CountryData; ipcRegionData?: FeatureCollection; selectedCountryName?: string; + countryIso3Data: CountryIso3Data | undefined; } diff --git a/src/domain/props/IpcCountryChoroplethProps.tsx b/src/domain/props/IpcCountryChoroplethProps.tsx index 4ecd7366..9b66d19b 100644 --- a/src/domain/props/IpcCountryChoroplethProps.tsx +++ b/src/domain/props/IpcCountryChoroplethProps.tsx @@ -1,9 +1,11 @@ import { FeatureCollection, GeoJsonProperties, Geometry } from 'geojson'; import { CountryData } from '../entities/country/CountryData'; +import { CountryIso3Data } from '../entities/country/CountryIso3Data'; export default interface IpcCountryChoroplethProps { regionIpcData: FeatureCollection; countryData: CountryData | undefined; countryName?: string; + countryIso3Data: CountryIso3Data | undefined; } diff --git a/src/domain/props/IpcNutritionAccordionProps.tsx b/src/domain/props/IpcNutritionAccordionProps.tsx new file mode 100644 index 00000000..a3febeae --- /dev/null +++ b/src/domain/props/IpcNutritionAccordionProps.tsx @@ -0,0 +1,5 @@ +import { CountryIso3Data } from '../entities/country/CountryIso3Data'; + +export default interface IpcFoodSecurityAccordionProps { + countryIso3Data: CountryIso3Data | undefined; +} diff --git a/src/operations/map/FcsAccordionOperations.tsx b/src/operations/map/FcsAccordionOperations.tsx index 7a86f439..fb5c837d 100644 --- a/src/operations/map/FcsAccordionOperations.tsx +++ b/src/operations/map/FcsAccordionOperations.tsx @@ -104,6 +104,18 @@ export class FcsAccordionOperations { }; } + static getNutritionData(countryIso3Data?: CountryIso3Data) { + if (!countryIso3Data?.nutrition) { + return null; + } + + const { wasting, stunting } = countryIso3Data.nutrition; + return { + Acute: wasting || null, + Chronic: stunting || null, + }; + } + static getFoodSecutriyPopoverInfo(): ReactNode { return (
diff --git a/src/operations/map/FcsFoodSecurityOperations.tsx b/src/operations/map/FcsFoodSecurityOperations.tsx new file mode 100644 index 00000000..3e1f0dad --- /dev/null +++ b/src/operations/map/FcsFoodSecurityOperations.tsx @@ -0,0 +1,151 @@ +// FcsAccordionOperations.js +import { Spacer } from '@nextui-org/react'; + +import CustomCard from '@/components/Cards/Card'; +import { LineChart } from '@/components/Charts/LineChart'; +import CustomInfoCircle from '@/components/CustomInfoCircle/CustomInfoCircle'; +import { CountryData } from '@/domain/entities/country/CountryData'; +import { CountryIso3Data } from '@/domain/entities/country/CountryIso3Data'; +import { cardsWrapperClass } from '@/utils/primitives'; + +import { ReactComponent as FoodConsumption } from '../../../public/Images/FoodConsumption.svg'; +import { ReactComponent as Nutrition } from '../../../public/Images/Nutrition.svg'; +import { ReactComponent as Population } from '../../../public/Images/Population.svg'; +import { FcsAccordionOperations } from './FcsAccordionOperations'; + +export function getFcsFoodSecurityAccordionItems( + countryData: CountryData | undefined, + countryIso3Data: CountryIso3Data | undefined +) { + const deltaOneMonth = countryData?.fcsMinus1 ? countryData.fcs - countryData.fcsMinus1 : null; + const deltaThreeMonth = countryData?.fcsMinus3 ? countryData.fcs - countryData.fcsMinus3 : null; + const fcsChartData = FcsAccordionOperations.getFcsChartData(countryData); + const rcsiChartData = FcsAccordionOperations.getRcsiChartData(countryData); + const nutritionData = FcsAccordionOperations.getNutritionData(countryIso3Data); + return [ + { + title: 'Food Security', + infoIcon: , + popoverInfo: FcsAccordionOperations.getFoodSecutriyPopoverInfo(), + content: ( +
+ , + text: countryData?.population ? `${countryData.population.toFixed(2)} M` : 'N/A', + altText: 'Population Icon', + textClass: 'text-base', + }, + ]} + /> + , + text: 'Population with insufficient food consumption', + value: countryData?.fcs ? `${countryData.fcs.toFixed(2)} M` : 'N/A', + textClass: 'text-xs', + changeValues: [ + { + imageSrc: deltaOneMonth && deltaOneMonth > 0 ? '/Images/ArrowUp.svg' : '/Images/ArrowDown.svg', + text: deltaOneMonth ? `${deltaOneMonth.toFixed(2)} M` : 'N/A', + timeText: '1 Month ago', + altText: 'Delta Icon', + }, + { + imageSrc: deltaThreeMonth && deltaThreeMonth > 0 ? '/Images/ArrowUp.svg' : '/Images/ArrowDown.svg', + text: deltaThreeMonth ? `${deltaThreeMonth.toFixed(2)} M` : 'N/A', + timeText: '3 Months ago', + altText: 'Delta Icon', + }, + ], + }, + ]} + /> +
+ ), + }, + { + title: 'Nutrition', + infoIcon: , + content: ( +
+ , + text: nutritionData?.Acute ? ( + <> + {`${nutritionData.Acute} %`} + of children (under 5) + + ) : ( + 'N/A' + ), + altText: 'Population Icon', + textClass: 'text-base', + }, + ]} + /> + , + text: nutritionData?.Chronic ? ( + <> + {`${nutritionData.Chronic} %`} + of children (under 5) + + ) : ( + 'N/A' + ), + altText: 'Population Icon', + textClass: 'text-base', + }, + ]} + /> +
+ ), + }, + { + title: 'Food Security Trends', + infoIcon: , + popoverInfo: FcsAccordionOperations.getFoodSecutriyTrendsPopoverInfo(), + content: ( +
+ {fcsChartData ? ( + + ) : ( +

No data about insufficient food consumption

+ )} + + {rcsiChartData ? ( + + ) : ( +

No data about crisis or above crisis food-based coping

+ )} +
+ ), + }, + ]; +} diff --git a/src/operations/map/FcsMacroEconomicOperations.tsx b/src/operations/map/FcsMacroEconomicOperations.tsx new file mode 100644 index 00000000..80f6f505 --- /dev/null +++ b/src/operations/map/FcsMacroEconomicOperations.tsx @@ -0,0 +1,93 @@ +// FcsAccordionOperations.js +import CustomCard from '@/components/Cards/Card'; +import { LineChart } from '@/components/Charts/LineChart'; +import CustomInfoCircle from '@/components/CustomInfoCircle/CustomInfoCircle'; +import { CountryData } from '@/domain/entities/country/CountryData'; +import { CountryIso3Data } from '@/domain/entities/country/CountryIso3Data'; +import { cardsWrapperClass } from '@/utils/primitives'; + +import { ReactComponent as Import } from '../../../public/Images/Import.svg'; +import { FcsAccordionOperations } from './FcsAccordionOperations'; + +export function getMacroEconomicAccordionOperations( + countryData: CountryData | undefined, + countryIso3Data: CountryIso3Data | undefined +) { + const currencyExchangeChartData = FcsAccordionOperations.getCurrencyExchangeChartData(countryIso3Data); + const balanceOfTradeChartData = FcsAccordionOperations.getBalanceOfTradeChartData(countryIso3Data); + const headlineAndFoodInflationChartData = + FcsAccordionOperations.getHeadlineAndFoodInflationChartData(countryIso3Data); + + return [ + { + title: 'Macroeconomic', + infoIcon: , + popoverInfo: FcsAccordionOperations.getMacroEconomicPopoverInfo(), + content: ( +
+ , + text: countryData?.importDependency ? `${countryData.importDependency.toFixed(1)}% of Cereals` : 'N/A', + altText: 'Import Dependency Icon', + textClass: 'text-base', + }, + ]} + /> +
+ ), + }, + { + title: 'Currency Exchange', + infoIcon: , + popoverInfo: FcsAccordionOperations.getCurrencyExchangePopoverInfo(), + content: ( +
+ {currencyExchangeChartData ? ( + + ) : ( +

No data about currency exchange

+ )} +
+ ), + }, + { + title: 'Balance of Trade', + infoIcon: , + popoverInfo: FcsAccordionOperations.getBalanceOfTradePopoverInfo(), + content: ( +
+ {balanceOfTradeChartData ? ( + + ) : ( +

No data about balance of trade

+ )} +
+ ), + }, + { + title: 'Headline and food inflation', + infoIcon: , + popoverInfo: FcsAccordionOperations.getHeadlineAndFoodInflationPopoverInfo(), + content: ( +
+ {headlineAndFoodInflationChartData ? ( + + ) : ( +

No data about headline and food inflation

+ )} +
+ ), + }, + ]; +} diff --git a/src/operations/map/IpcFoodSecurityOperations.tsx b/src/operations/map/IpcFoodSecurityOperations.tsx new file mode 100644 index 00000000..fce7ca3d --- /dev/null +++ b/src/operations/map/IpcFoodSecurityOperations.tsx @@ -0,0 +1,119 @@ +import React from 'react'; + +import CustomCard from '@/components/Cards/Card'; +import CustomInfoCircle from '@/components/CustomInfoCircle/CustomInfoCircle'; +import { CountryData } from '@/domain/entities/country/CountryData'; +import { CountryIso3Data } from '@/domain/entities/country/CountryIso3Data'; +import { cardsWrapperClass } from '@/utils/primitives'; + +import { ReactComponent as FoodConsumption } from '../../../public/Images/FoodConsumption.svg'; +import { ReactComponent as Nutrition } from '../../../public/Images/Nutrition.svg'; +import { ReactComponent as Population } from '../../../public/Images/Population.svg'; +import { FcsAccordionOperations } from './FcsAccordionOperations'; + +export const IpcFoodSecurityAccordionOperations = { + getFoodSecurityAccordionItems: ( + countryData: CountryData | undefined, + deltaOneMonth: number | null, + deltaThreeMonth: number | null + ) => { + const hasNoData: boolean = + !countryData || !countryData.population || !countryData.fcs || !deltaOneMonth || !deltaThreeMonth; + + return { + title: 'Food Security', + infoIcon: , + content: !hasNoData ? ( +
+ {/* Population Card */} + , + text: countryData?.population ? `${countryData?.population.toFixed(2)} M` : 'N/A', + altText: 'Population Icon', + textClass: 'text-base', + }, + ]} + /> + {/* Food Consumption Card */} + , + text: 'Population with insufficient food consumption', + value: countryData?.fcs ? `${countryData?.fcs.toFixed(2)} M` : 'N/A', + textClass: 'text-xs', + changeValues: [ + { + imageSrc: deltaOneMonth && deltaOneMonth > 0 ? '/Images/ArrowUp.svg' : '/Images/ArrowDown.svg', + text: deltaOneMonth ? `${deltaOneMonth.toFixed(2)} M` : 'N/A', + timeText: '1 Month ago', + altText: 'Delta Icon', + }, + { + imageSrc: deltaThreeMonth && deltaThreeMonth > 0 ? '/Images/ArrowUp.svg' : '/Images/ArrowDown.svg', + text: deltaThreeMonth ? `${deltaThreeMonth.toFixed(2)} M` : 'N/A', + timeText: '3 Months ago', + altText: 'Delta Icon', + }, + ], + }, + ]} + /> +
+ ) : ( +

No data about food security

+ ), + }; + }, + getNutritionAccordion: (countryIso3Data: CountryIso3Data | undefined) => { + return { + title: 'Nutrition', + infoIcon: , + content: ( +
+ {/* Acute Nutrition Card */} + , + text: FcsAccordionOperations.getNutritionData(countryIso3Data)?.Acute ? ( + <> + {`${FcsAccordionOperations.getNutritionData(countryIso3Data)?.Acute} %`} + of children (under 5) + + ) : ( + 'N/A' + ), + altText: 'Acute Nutrition Icon', + textClass: 'text-base', + }, + ]} + /> + {/* Chronic Nutrition Card */} + , + text: FcsAccordionOperations.getNutritionData(countryIso3Data)?.Chronic ? ( + <> + {`${FcsAccordionOperations.getNutritionData(countryIso3Data)?.Chronic} %`} + of children (under 5) + + ) : ( + 'N/A' + ), + altText: 'Chronic Nutrition Icon', + textClass: 'text-base', + }, + ]} + /> +
+ ), + }; + }, +}; diff --git a/src/operations/map/MapOperations.tsx b/src/operations/map/MapOperations.tsx index cba69e42..1fd1eaa2 100644 --- a/src/operations/map/MapOperations.tsx +++ b/src/operations/map/MapOperations.tsx @@ -51,7 +51,7 @@ export class MapOperations { setCountryData(newCountryData); } - if (selectedMapType === GlobalInsight.FOOD) { + if (selectedMapType === GlobalInsight.FOOD || selectedMapType === GlobalInsight.IPC) { const newCountryIso3Data = await countryRepository.getCountryIso3Data(selectedCountryData.properties.iso3); setCountryIso3Data(newCountryIso3Data); } diff --git a/src/utils/primitives.ts b/src/utils/primitives.ts index 48ed96a9..95e98dcc 100644 --- a/src/utils/primitives.ts +++ b/src/utils/primitives.ts @@ -44,4 +44,4 @@ export const subtitle = tv({ }, }); -export const cardsWrapperClass = 'cards-wrapper flex flex-row gap-4 justify-center flex-wrap'; +export const cardsWrapperClass = 'cards-wrapper flex flex-row gap-1 justify-center flex-wrap'; From de66d732887c19a585caa69c6d02407ec182830b Mon Sep 17 00:00:00 2001 From: Armanpreet Ghotra Date: Thu, 19 Dec 2024 08:07:29 +0100 Subject: [PATCH 03/18] feat: downsize the accordions, add flex to population card --- public/Images/Nutrition.svg | 16 +++- src/components/Cards/Card.tsx | 24 +++--- src/components/Map/FcsMap/FcsAccordion.tsx | 7 +- src/components/Map/IpcMap/IpcAccordion.tsx | 6 +- .../map/FcsFoodSecurityOperations.tsx | 82 +++++++++--------- .../map/IpcFoodSecurityOperations.tsx | 86 +++++++++---------- 6 files changed, 113 insertions(+), 108 deletions(-) diff --git a/public/Images/Nutrition.svg b/public/Images/Nutrition.svg index 1dc24e38..e84cd80d 100644 --- a/public/Images/Nutrition.svg +++ b/public/Images/Nutrition.svg @@ -1,5 +1,13 @@ - - - - + + + + + + + + + + diff --git a/src/components/Cards/Card.tsx b/src/components/Cards/Card.tsx index b21be237..d316120e 100644 --- a/src/components/Cards/Card.tsx +++ b/src/components/Cards/Card.tsx @@ -9,18 +9,17 @@ import { CardProps } from '@/domain/props/CardProps'; export default function CustomCard({ title, content }: CardProps) { return ( - - + +
{content.map((item) => ( -
- {item.svgIcon ? ( -
{item.svgIcon}
- ) : item.imageSrc ? ( - {item.altText - ) : null} +
+ {item.svgIcon &&
{item.svgIcon}
} + {!item.svgIcon && item.imageSrc && ( + {item.altText + )}
- {title &&

{title}

} + {title &&

{title}

} {item.text &&

{item.text}

} {item.value && (

@@ -28,14 +27,13 @@ export default function CustomCard({ title, content }: CardProps) {

)}
- {/* Additional Content (Time-based data) */} {item.changeValues && ( -
+
{item.changeValues.map((delta) => ( -
+
{delta.altText}
-

{delta.text}

+

{delta.text}

{delta.timeText}

diff --git a/src/components/Map/FcsMap/FcsAccordion.tsx b/src/components/Map/FcsMap/FcsAccordion.tsx index 809b6595..aed7b178 100644 --- a/src/components/Map/FcsMap/FcsAccordion.tsx +++ b/src/components/Map/FcsMap/FcsAccordion.tsx @@ -13,10 +13,7 @@ export default function FcsAccordion({ countryData, loading, countryIso3Data, co return ( <> {!isMobile ? ( -
+
)} {!isMobile && ( -
+
)} diff --git a/src/components/Map/IpcMap/IpcAccordion.tsx b/src/components/Map/IpcMap/IpcAccordion.tsx index e36bbb75..62fdbb8e 100644 --- a/src/components/Map/IpcMap/IpcAccordion.tsx +++ b/src/components/Map/IpcMap/IpcAccordion.tsx @@ -1,5 +1,6 @@ import AccordionContainer from '@/components/Accordions/AccordionContainer'; import IpcAccordionProps from '@/domain/props/IpcAccordionProps'; +import { useMediaQuery } from '@/utils/resolution.ts'; import IpcFoodSecurityAccordion from './IpcFoodSecurityAccordion'; import IpcNutritionAccordion from './IpcNutritionAccordion'; @@ -14,15 +15,16 @@ export default function IpcAccordion({ countryData, countryName, countryIso3Data deltaThreeMonth, }); const ipcNutrititonAccordion = IpcNutritionAccordion({ countryIso3Data }); + const isMobile = useMediaQuery('(max-width: 700px)'); return ( -
+
); diff --git a/src/operations/map/FcsFoodSecurityOperations.tsx b/src/operations/map/FcsFoodSecurityOperations.tsx index 3e1f0dad..4b27a86e 100644 --- a/src/operations/map/FcsFoodSecurityOperations.tsx +++ b/src/operations/map/FcsFoodSecurityOperations.tsx @@ -43,7 +43,7 @@ export function getFcsFoodSecurityAccordionItems( , + svgIcon: , text: 'Population with insufficient food consumption', value: countryData?.fcs ? `${countryData.fcs.toFixed(2)} M` : 'N/A', textClass: 'text-xs', @@ -70,46 +70,46 @@ export function getFcsFoodSecurityAccordionItems( { title: 'Nutrition', infoIcon: , - content: ( -
- , - text: nutritionData?.Acute ? ( - <> - {`${nutritionData.Acute} %`} - of children (under 5) - - ) : ( - 'N/A' - ), - altText: 'Population Icon', - textClass: 'text-base', - }, - ]} - /> - , - text: nutritionData?.Chronic ? ( - <> - {`${nutritionData.Chronic} %`} - of children (under 5) - - ) : ( - 'N/A' - ), - altText: 'Population Icon', - textClass: 'text-base', - }, - ]} - /> -
- ), + popoverInfo: FcsAccordionOperations.getFoodSecutriyPopoverInfo(), + content: + nutritionData && (nutritionData.Acute != null || nutritionData.Chronic != null) ? ( +
+ {nutritionData.Acute != null && ( + , + text: ( + <> + {`${nutritionData.Acute} %`} + of children (under 5) + + ), + }, + ]} + /> + )} + {nutritionData.Chronic != null && ( + , + text: ( + <> + {`${nutritionData.Chronic} %`} + of children (under 5) + + ), + }, + ]} + /> + )} +
+ ) : ( +

No data about Nutrition is available

+ ), }, { title: 'Food Security Trends', diff --git a/src/operations/map/IpcFoodSecurityOperations.tsx b/src/operations/map/IpcFoodSecurityOperations.tsx index fce7ca3d..58000c4a 100644 --- a/src/operations/map/IpcFoodSecurityOperations.tsx +++ b/src/operations/map/IpcFoodSecurityOperations.tsx @@ -23,6 +23,7 @@ export const IpcFoodSecurityAccordionOperations = { return { title: 'Food Security', infoIcon: , + popoverInfo: FcsAccordionOperations.getFoodSecutriyPopoverInfo(), content: !hasNoData ? (
{/* Population Card */} @@ -41,7 +42,7 @@ export const IpcFoodSecurityAccordionOperations = { , + svgIcon: , text: 'Population with insufficient food consumption', value: countryData?.fcs ? `${countryData?.fcs.toFixed(2)} M` : 'N/A', textClass: 'text-xs', @@ -69,51 +70,50 @@ export const IpcFoodSecurityAccordionOperations = { }; }, getNutritionAccordion: (countryIso3Data: CountryIso3Data | undefined) => { + const nutritionData = FcsAccordionOperations.getNutritionData(countryIso3Data); + return { title: 'Nutrition', infoIcon: , - content: ( -
- {/* Acute Nutrition Card */} - , - text: FcsAccordionOperations.getNutritionData(countryIso3Data)?.Acute ? ( - <> - {`${FcsAccordionOperations.getNutritionData(countryIso3Data)?.Acute} %`} - of children (under 5) - - ) : ( - 'N/A' - ), - altText: 'Acute Nutrition Icon', - textClass: 'text-base', - }, - ]} - /> - {/* Chronic Nutrition Card */} - , - text: FcsAccordionOperations.getNutritionData(countryIso3Data)?.Chronic ? ( - <> - {`${FcsAccordionOperations.getNutritionData(countryIso3Data)?.Chronic} %`} - of children (under 5) - - ) : ( - 'N/A' - ), - altText: 'Chronic Nutrition Icon', - textClass: 'text-base', - }, - ]} - /> -
- ), + content: + nutritionData && (nutritionData.Acute != null || nutritionData.Chronic != null) ? ( +
+ {nutritionData.Acute != null && ( + , + text: ( + <> + {`${nutritionData.Acute} %`} + of children (under 5) + + ), + }, + ]} + /> + )} + {nutritionData.Chronic != null && ( + , + text: ( + <> + {`${nutritionData.Chronic} %`} + of children (under 5) + + ), + }, + ]} + /> + )} +
+ ) : ( +

No data about Nutrition is available

+ ), }; }, }; From ab1fa4a947ff9159d4337f91140f98f754d7241b Mon Sep 17 00:00:00 2001 From: Armanpreet Ghotra Date: Thu, 19 Dec 2024 08:18:34 +0100 Subject: [PATCH 04/18] fix: reduce the size of nutrition svg --- src/operations/map/FcsFoodSecurityOperations.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/operations/map/FcsFoodSecurityOperations.tsx b/src/operations/map/FcsFoodSecurityOperations.tsx index 4b27a86e..fcbde7ef 100644 --- a/src/operations/map/FcsFoodSecurityOperations.tsx +++ b/src/operations/map/FcsFoodSecurityOperations.tsx @@ -95,7 +95,7 @@ export function getFcsFoodSecurityAccordionItems( title="Chronic Nutrition" content={[ { - svgIcon: , + svgIcon: , text: ( <> {`${nutritionData.Chronic} %`} From 38749c527d135be44c9b64de28da1a9e66983de4 Mon Sep 17 00:00:00 2001 From: Armanpreet Ghotra Date: Thu, 19 Dec 2024 08:54:00 +0100 Subject: [PATCH 05/18] fix: fix macroAccordion lineChart --- src/operations/map/FcsMacroEconomicOperations.tsx | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/operations/map/FcsMacroEconomicOperations.tsx b/src/operations/map/FcsMacroEconomicOperations.tsx index 80f6f505..d246268e 100644 --- a/src/operations/map/FcsMacroEconomicOperations.tsx +++ b/src/operations/map/FcsMacroEconomicOperations.tsx @@ -46,7 +46,7 @@ export function getMacroEconomicAccordionOperations( content: (
{currencyExchangeChartData ? ( - + ) : (

No data about currency exchange

)} @@ -60,7 +60,7 @@ export function getMacroEconomicAccordionOperations( content: (
{balanceOfTradeChartData ? ( - + ) : (

No data about balance of trade

)} @@ -74,15 +74,7 @@ export function getMacroEconomicAccordionOperations( content: (
{headlineAndFoodInflationChartData ? ( - + ) : (

No data about headline and food inflation

)} From 1b4750ac0f2b4e33507dd45f5dfc3303d9bb0e67 Mon Sep 17 00:00:00 2001 From: Armanpreet Ghotra Date: Thu, 19 Dec 2024 09:18:21 +0100 Subject: [PATCH 06/18] fix: fix after merge --- src/components/Map/FcsAccordion.tsx | 173 ------------------ .../Map/{ => FcsMap}/FcsRegionTooltip.tsx | 2 +- .../map/FcsCountryChoroplethOperations.tsx | 2 +- 3 files changed, 2 insertions(+), 175 deletions(-) delete mode 100644 src/components/Map/FcsAccordion.tsx rename src/components/Map/{ => FcsMap}/FcsRegionTooltip.tsx (97%) diff --git a/src/components/Map/FcsAccordion.tsx b/src/components/Map/FcsAccordion.tsx deleted file mode 100644 index b7a32e8a..00000000 --- a/src/components/Map/FcsAccordion.tsx +++ /dev/null @@ -1,173 +0,0 @@ -import { Spacer } from '@nextui-org/react'; - -import FcsAccordionProps from '@/domain/props/FcsAccordionProps'; -import { FcsAccordionOperations } from '@/operations/map/FcsAccordionOperations'; -import { cardsWrapperClass } from '@/utils/primitives'; - -import { ReactComponent as FoodConsumption } from '../../../public/Images/FoodConsumption.svg'; -import { ReactComponent as Import } from '../../../public/Images/Import.svg'; -import { ReactComponent as Population } from '../../../public/Images/Population.svg'; -import AccordionContainer from '../Accordions/AccordionContainer'; -import CustomCard from '../Cards/Card'; -import { LineChart } from '../Charts/LineChart'; -import CustomInfoCircle from '../CustomInfoCircle/CustomInfoCircle'; - -export default function FcsAccordion({ countryData, loading, countryIso3Data, countryName }: FcsAccordionProps) { - const deltaOneMonth = countryData?.fcsMinus1 ? countryData.fcs - countryData.fcsMinus1 : null; - const deltaThreeMonth = countryData?.fcsMinus3 ? countryData.fcs - countryData.fcsMinus3 : null; - const fcsChartData = FcsAccordionOperations.getFcsChartData(countryData); - const rcsiChartData = FcsAccordionOperations.getRcsiChartData(countryData); - const currencyExchangeChartData = FcsAccordionOperations.getCurrencyExchangeChartData(countryIso3Data); - const balanceOfTradeChartData = FcsAccordionOperations.getBalanceOfTradeChartData(countryIso3Data); - const headlineAndFoodInflationChartData = - FcsAccordionOperations.getHeadlineAndFoodInflationChartData(countryIso3Data); - return ( -
- , - popoverInfo: FcsAccordionOperations.getFoodSecutriyPopoverInfo(), - content: ( -
- , - text: countryData?.population ? `${countryData.population.toFixed(2)} M` : 'N/A', - altText: 'Population Icon', - }, - ]} - /> - , - text: countryData?.fcs ? `${countryData.fcs.toFixed(2)} M` : 'N/A', - altText: 'Food Consumption Icon', - }, - { - imageSrc: deltaOneMonth && deltaOneMonth > 0 ? '/Images/ArrowUp.svg' : '/Images/ArrowDown.svg', - text: deltaOneMonth ? `${deltaOneMonth.toFixed(2)} M` : 'N/A', - timeText: '1 Month ago', - altText: 'Icon', - }, - { - imageSrc: - deltaThreeMonth && deltaThreeMonth > 0 ? '/Images/ArrowUp.svg' : '/Images/ArrowDown.svg', - text: deltaThreeMonth ? `${deltaThreeMonth.toFixed(2)} M` : 'N/A', - timeText: '3 Month ago', - altText: 'Other Icon', - }, - ]} - /> -
- ), - }, - { - title: 'Food Security Trends', - infoIcon: , - popoverInfo: FcsAccordionOperations.getFoodSecutriyTrendsPopoverInfo(), - content: ( -
- {fcsChartData ? ( - - ) : ( -

No data about insufficient food consumption

- )} - - {rcsiChartData ? ( - - ) : ( -

No data about crisis or above crisis food-based coping

- )} -
- ), - }, - { - title: 'Macro-economic', - infoIcon: , - popoverInfo: FcsAccordionOperations.getMacroEconomicPopoverInfo(), - content: ( -
- , - text: countryData?.importDependency - ? `${countryData.importDependency.toFixed(1)}% of Cereals` - : 'N/A', - altText: 'Import Dependency Icon', - }, - ]} - /> -
- ), - }, - { - title: 'Currency Exchange', - infoIcon: , - popoverInfo: FcsAccordionOperations.getCurrencyExchangePopoverInfo(), - content: ( -
- {currencyExchangeChartData ? ( - - ) : ( -

No data about currency exchange

- )} -
- ), - }, - { - title: 'Balance of Trade', - infoIcon: , - popoverInfo: FcsAccordionOperations.getBalanceOfTradePopoverInfo(), - content: ( -
- {balanceOfTradeChartData ? ( - - ) : ( -

No data about balance of trade

- )} -
- ), - }, - { - title: 'Headline and food inflation', - infoIcon: , - popoverInfo: FcsAccordionOperations.getHeadlineAndFoodInflationPopoverInfo(), - content: ( -
- {headlineAndFoodInflationChartData ? ( - - ) : ( -

No data about headline and food inflation

- )} -
- ), - }, - ]} - /> -
- ); -} diff --git a/src/components/Map/FcsRegionTooltip.tsx b/src/components/Map/FcsMap/FcsRegionTooltip.tsx similarity index 97% rename from src/components/Map/FcsRegionTooltip.tsx rename to src/components/Map/FcsMap/FcsRegionTooltip.tsx index 3ad1ad99..67017b26 100644 --- a/src/components/Map/FcsRegionTooltip.tsx +++ b/src/components/Map/FcsMap/FcsRegionTooltip.tsx @@ -3,7 +3,7 @@ import { Feature, GeoJsonProperties, Geometry } from 'geojson'; import { FcsRegionTooltipOperations } from '@/operations/map/FcsRegionTooltipOperations'; import { formatToMillion } from '@/utils/formatting'; -import { LineChart } from '../Charts/LineChart'; +import { LineChart } from '../../Charts/LineChart'; interface FcsRegionTooltipProps { feature: Feature; diff --git a/src/operations/map/FcsCountryChoroplethOperations.tsx b/src/operations/map/FcsCountryChoroplethOperations.tsx index fc0c22e0..dbb20ed3 100644 --- a/src/operations/map/FcsCountryChoroplethOperations.tsx +++ b/src/operations/map/FcsCountryChoroplethOperations.tsx @@ -3,7 +3,7 @@ import L from 'leaflet'; import React from 'react'; import { createRoot } from 'react-dom/client'; -import FcsRegionTooltip from '@/components/Map/FcsRegionTooltip'; +import FcsRegionTooltip from '@/components/Map/FcsMap/FcsRegionTooltip'; import { CountryMapData } from '@/domain/entities/country/CountryMapData.ts'; import { MapOperations } from '@/operations/map/MapOperations'; From be3ca0d70f66365969adb4c902b933f9a2b2e7e1 Mon Sep 17 00:00:00 2001 From: Armanpreet Ghotra Date: Thu, 19 Dec 2024 09:51:50 +0100 Subject: [PATCH 07/18] fix: restyle the nutrition accordion text --- src/components/Cards/Card.tsx | 3 +-- .../props/NutritionAccordionTextProps.tsx | 4 ++++ .../map/FcsFoodSecurityOperations.tsx | 17 +++++++++-------- .../map/IpcFoodSecurityOperations.tsx | 17 +++++++++-------- src/operations/map/NutritionAccordionText.tsx | 11 +++++++++++ 5 files changed, 34 insertions(+), 18 deletions(-) create mode 100644 src/domain/props/NutritionAccordionTextProps.tsx create mode 100644 src/operations/map/NutritionAccordionText.tsx diff --git a/src/components/Cards/Card.tsx b/src/components/Cards/Card.tsx index d316120e..d56c3704 100644 --- a/src/components/Cards/Card.tsx +++ b/src/components/Cards/Card.tsx @@ -1,7 +1,6 @@ 'use client'; -import { Card, CardBody } from '@nextui-org/react'; -import Image from 'next/image'; +import { Card, CardBody, Image } from '@nextui-org/react'; import React from 'react'; import { v4 as uuid } from 'uuid'; diff --git a/src/domain/props/NutritionAccordionTextProps.tsx b/src/domain/props/NutritionAccordionTextProps.tsx new file mode 100644 index 00000000..29665514 --- /dev/null +++ b/src/domain/props/NutritionAccordionTextProps.tsx @@ -0,0 +1,4 @@ +export default interface NutritionAccordionTextProps { + nutritionValue: string; + text: string; +} diff --git a/src/operations/map/FcsFoodSecurityOperations.tsx b/src/operations/map/FcsFoodSecurityOperations.tsx index 79aebaab..b55f64b1 100644 --- a/src/operations/map/FcsFoodSecurityOperations.tsx +++ b/src/operations/map/FcsFoodSecurityOperations.tsx @@ -12,6 +12,7 @@ import { ReactComponent as FoodConsumption } from '../../../public/Images/FoodCo import { ReactComponent as Nutrition } from '../../../public/Images/Nutrition.svg'; import { ReactComponent as Population } from '../../../public/Images/Population.svg'; import { FcsAccordionOperations } from './FcsAccordionOperations'; +import NutritionAccordionText from './NutritionAccordionText'; export function getFcsFoodSecurityAccordionItems( countryData: CountryData | undefined, @@ -81,10 +82,10 @@ export function getFcsFoodSecurityAccordionItems( { svgIcon: , text: ( - <> - {`${nutritionData.Acute} %`} - of children (under 5) - + ), }, ]} @@ -97,10 +98,10 @@ export function getFcsFoodSecurityAccordionItems( { svgIcon: , text: ( - <> - {`${nutritionData.Chronic} %`} - of children (under 5) - + ), }, ]} diff --git a/src/operations/map/IpcFoodSecurityOperations.tsx b/src/operations/map/IpcFoodSecurityOperations.tsx index 58000c4a..295446c2 100644 --- a/src/operations/map/IpcFoodSecurityOperations.tsx +++ b/src/operations/map/IpcFoodSecurityOperations.tsx @@ -10,6 +10,7 @@ import { ReactComponent as FoodConsumption } from '../../../public/Images/FoodCo import { ReactComponent as Nutrition } from '../../../public/Images/Nutrition.svg'; import { ReactComponent as Population } from '../../../public/Images/Population.svg'; import { FcsAccordionOperations } from './FcsAccordionOperations'; +import NutritionAccordionText from './NutritionAccordionText'; export const IpcFoodSecurityAccordionOperations = { getFoodSecurityAccordionItems: ( @@ -85,10 +86,10 @@ export const IpcFoodSecurityAccordionOperations = { { svgIcon: , text: ( - <> - {`${nutritionData.Acute} %`} - of children (under 5) - + ), }, ]} @@ -101,10 +102,10 @@ export const IpcFoodSecurityAccordionOperations = { { svgIcon: , text: ( - <> - {`${nutritionData.Chronic} %`} - of children (under 5) - + ), }, ]} diff --git a/src/operations/map/NutritionAccordionText.tsx b/src/operations/map/NutritionAccordionText.tsx new file mode 100644 index 00000000..59550e6d --- /dev/null +++ b/src/operations/map/NutritionAccordionText.tsx @@ -0,0 +1,11 @@ +import NutritionAccordionTextProps from '@/domain/props/NutritionAccordionTextProps'; + +function NutritionAccordionText({ nutritionValue, text }: NutritionAccordionTextProps) { + return ( + <> + {nutritionValue} + {text} + + ); +} +export default NutritionAccordionText; From 1f5b2adf5395b4399d9ea655304ddeac2ef2c8f6 Mon Sep 17 00:00:00 2001 From: Armanpreet Ghotra Date: Thu, 19 Dec 2024 13:06:56 +0100 Subject: [PATCH 08/18] fix: remove the extra accordion files and fix chronic nutrition svg --- src/components/Map/FcsMap/FcsAccordion.tsx | 8 ++++---- .../Map/FcsMap/FcsFoodSecurityAccordion.tsx | 7 ------- .../Map/FcsMap/FcsMacroEconomicAccordion.tsx | 7 ------- src/components/Map/IpcMap/IpcAccordion.tsx | 12 +++++------- .../Map/IpcMap/IpcFoodSecurityAccordion.tsx | 15 --------------- .../Map/IpcMap/IpcNutritionAccordion.tsx | 7 ------- src/operations/map/FcsFoodSecurityOperations.tsx | 2 +- src/operations/map/IpcFoodSecurityOperations.tsx | 2 +- 8 files changed, 11 insertions(+), 49 deletions(-) delete mode 100644 src/components/Map/FcsMap/FcsFoodSecurityAccordion.tsx delete mode 100644 src/components/Map/FcsMap/FcsMacroEconomicAccordion.tsx delete mode 100644 src/components/Map/IpcMap/IpcFoodSecurityAccordion.tsx delete mode 100644 src/components/Map/IpcMap/IpcNutritionAccordion.tsx diff --git a/src/components/Map/FcsMap/FcsAccordion.tsx b/src/components/Map/FcsMap/FcsAccordion.tsx index aed7b178..37cd601e 100644 --- a/src/components/Map/FcsMap/FcsAccordion.tsx +++ b/src/components/Map/FcsMap/FcsAccordion.tsx @@ -1,14 +1,14 @@ import FcsAccordionProps from '@/domain/props/FcsAccordionProps'; +import { getFcsFoodSecurityAccordionItems } from '@/operations/map/FcsFoodSecurityOperations'; +import { getMacroEconomicAccordionOperations } from '@/operations/map/FcsMacroEconomicOperations'; import { useMediaQuery } from '@/utils/resolution.ts'; import AccordionContainer from '../../Accordions/AccordionContainer'; -import FcsFoodSecurityAccordion from './FcsFoodSecurityAccordion'; -import FcsMacroEconomicAccordion from './FcsMacroEconomicAccordion'; export default function FcsAccordion({ countryData, loading, countryIso3Data, countryName }: FcsAccordionProps) { const isMobile = useMediaQuery('(max-width: 700px)'); - const foodSecurityAccordion = FcsFoodSecurityAccordion({ countryData, countryIso3Data }); - const macroEconomicAccordion = FcsMacroEconomicAccordion({ countryData, countryIso3Data }); + const foodSecurityAccordion = getFcsFoodSecurityAccordionItems(countryData, countryIso3Data); + const macroEconomicAccordion = getMacroEconomicAccordionOperations(countryData, countryIso3Data); return ( <> diff --git a/src/components/Map/FcsMap/FcsFoodSecurityAccordion.tsx b/src/components/Map/FcsMap/FcsFoodSecurityAccordion.tsx deleted file mode 100644 index f093297f..00000000 --- a/src/components/Map/FcsMap/FcsFoodSecurityAccordion.tsx +++ /dev/null @@ -1,7 +0,0 @@ -import FcsAccordionProps from '@/domain/props/FcsAccordionProps'; -import { getFcsFoodSecurityAccordionItems } from '@/operations/map/FcsFoodSecurityOperations'; - -export default function FoodSecurityAccordion({ countryData, countryIso3Data }: FcsAccordionProps) { - const FcsFoodSecurityAccordion = getFcsFoodSecurityAccordionItems(countryData, countryIso3Data); - return FcsFoodSecurityAccordion; -} diff --git a/src/components/Map/FcsMap/FcsMacroEconomicAccordion.tsx b/src/components/Map/FcsMap/FcsMacroEconomicAccordion.tsx deleted file mode 100644 index 253855ef..00000000 --- a/src/components/Map/FcsMap/FcsMacroEconomicAccordion.tsx +++ /dev/null @@ -1,7 +0,0 @@ -import FcsAccordionProps from '@/domain/props/FcsAccordionProps'; -import { getMacroEconomicAccordionOperations } from '@/operations/map/FcsMacroEconomicOperations'; - -export default function MacroEconomicAccordion({ countryData, countryIso3Data }: FcsAccordionProps) { - const FcsMacroEconomicAccordion = getMacroEconomicAccordionOperations(countryData, countryIso3Data); - return FcsMacroEconomicAccordion; -} diff --git a/src/components/Map/IpcMap/IpcAccordion.tsx b/src/components/Map/IpcMap/IpcAccordion.tsx index 62fdbb8e..eb4d4def 100644 --- a/src/components/Map/IpcMap/IpcAccordion.tsx +++ b/src/components/Map/IpcMap/IpcAccordion.tsx @@ -1,20 +1,18 @@ import AccordionContainer from '@/components/Accordions/AccordionContainer'; import IpcAccordionProps from '@/domain/props/IpcAccordionProps'; +import { IpcFoodSecurityAccordionOperations } from '@/operations/map/IpcFoodSecurityOperations'; import { useMediaQuery } from '@/utils/resolution.ts'; -import IpcFoodSecurityAccordion from './IpcFoodSecurityAccordion'; -import IpcNutritionAccordion from './IpcNutritionAccordion'; - export default function IpcAccordion({ countryData, countryName, countryIso3Data }: IpcAccordionProps) { const deltaOneMonth = countryData?.fcsMinus1 ? countryData.fcs - countryData.fcsMinus1 : null; const deltaThreeMonth = countryData?.fcsMinus3 ? countryData.fcs - countryData.fcsMinus3 : null; - const ipcFoodSecurityAccordion = IpcFoodSecurityAccordion({ + const ipcFoodSecurityAccordion = IpcFoodSecurityAccordionOperations.getFoodSecurityAccordionItems( countryData, deltaOneMonth, - deltaThreeMonth, - }); - const ipcNutrititonAccordion = IpcNutritionAccordion({ countryIso3Data }); + deltaThreeMonth + ); + const ipcNutrititonAccordion = IpcFoodSecurityAccordionOperations.getNutritionAccordion(countryIso3Data); const isMobile = useMediaQuery('(max-width: 700px)'); return ( diff --git a/src/components/Map/IpcMap/IpcFoodSecurityAccordion.tsx b/src/components/Map/IpcMap/IpcFoodSecurityAccordion.tsx deleted file mode 100644 index 2185b65a..00000000 --- a/src/components/Map/IpcMap/IpcFoodSecurityAccordion.tsx +++ /dev/null @@ -1,15 +0,0 @@ -import IpcFoodSecurityAccordionProps from '@/domain/props/IpcFoodSecurityAccordionProps'; -import { IpcFoodSecurityAccordionOperations } from '@/operations/map/IpcFoodSecurityOperations'; - -export default function IpcFoodSecurityAccordion({ - countryData, - deltaOneMonth, - deltaThreeMonth, -}: IpcFoodSecurityAccordionProps) { - const foodSecurityAccordion = IpcFoodSecurityAccordionOperations.getFoodSecurityAccordionItems( - countryData, - deltaOneMonth, - deltaThreeMonth - ); - return foodSecurityAccordion; -} diff --git a/src/components/Map/IpcMap/IpcNutritionAccordion.tsx b/src/components/Map/IpcMap/IpcNutritionAccordion.tsx deleted file mode 100644 index 7efa4e2d..00000000 --- a/src/components/Map/IpcMap/IpcNutritionAccordion.tsx +++ /dev/null @@ -1,7 +0,0 @@ -import IpcNutritionAccordionProps from '@/domain/props/IpcNutritionAccordionProps'; -import { IpcFoodSecurityAccordionOperations } from '@/operations/map/IpcFoodSecurityOperations'; - -export default function IpcNutritionAccordion({ countryIso3Data }: IpcNutritionAccordionProps) { - const nutritionAccordion = IpcFoodSecurityAccordionOperations.getNutritionAccordion(countryIso3Data); - return nutritionAccordion; -} diff --git a/src/operations/map/FcsFoodSecurityOperations.tsx b/src/operations/map/FcsFoodSecurityOperations.tsx index b55f64b1..9dd8241b 100644 --- a/src/operations/map/FcsFoodSecurityOperations.tsx +++ b/src/operations/map/FcsFoodSecurityOperations.tsx @@ -96,7 +96,7 @@ export function getFcsFoodSecurityAccordionItems( title="Chronic Nutrition" content={[ { - svgIcon: , + svgIcon: , text: ( , + svgIcon: , text: ( Date: Thu, 19 Dec 2024 13:42:17 +0100 Subject: [PATCH 09/18] fix: remove unwanted props file --- src/domain/props/IpcFoodSecurityAccordionProps.tsx | 7 ------- src/domain/props/IpcNutritionAccordionProps.tsx | 5 ----- 2 files changed, 12 deletions(-) delete mode 100644 src/domain/props/IpcFoodSecurityAccordionProps.tsx delete mode 100644 src/domain/props/IpcNutritionAccordionProps.tsx diff --git a/src/domain/props/IpcFoodSecurityAccordionProps.tsx b/src/domain/props/IpcFoodSecurityAccordionProps.tsx deleted file mode 100644 index debee2c0..00000000 --- a/src/domain/props/IpcFoodSecurityAccordionProps.tsx +++ /dev/null @@ -1,7 +0,0 @@ -import { CountryData } from '../entities/country/CountryData'; - -export default interface IpcFoodSecurityAccordionProps { - countryData: CountryData | undefined; - deltaOneMonth: number | null; - deltaThreeMonth: number | null; -} diff --git a/src/domain/props/IpcNutritionAccordionProps.tsx b/src/domain/props/IpcNutritionAccordionProps.tsx deleted file mode 100644 index a3febeae..00000000 --- a/src/domain/props/IpcNutritionAccordionProps.tsx +++ /dev/null @@ -1,5 +0,0 @@ -import { CountryIso3Data } from '../entities/country/CountryIso3Data'; - -export default interface IpcFoodSecurityAccordionProps { - countryIso3Data: CountryIso3Data | undefined; -} From 4698e216073116e75ac6b110e350caca526c10c7 Mon Sep 17 00:00:00 2001 From: Armanpreet Ghotra Date: Thu, 19 Dec 2024 16:35:06 +0100 Subject: [PATCH 10/18] fix: fix accordion operations of fcs and ipc --- src/components/Map/FcsMap/FcsAccordion.tsx | 42 +-- src/components/Map/IpcMap/IpcAccordion.tsx | 2 +- .../map/FcsFoodSecurityOperations.tsx | 252 +++++++++--------- .../map/FcsMacroEconomicOperations.tsx | 149 ++++++----- .../map/IpcFoodSecurityOperations.tsx | 118 ++++---- 5 files changed, 292 insertions(+), 271 deletions(-) diff --git a/src/components/Map/FcsMap/FcsAccordion.tsx b/src/components/Map/FcsMap/FcsAccordion.tsx index 37cd601e..22a3b1ff 100644 --- a/src/components/Map/FcsMap/FcsAccordion.tsx +++ b/src/components/Map/FcsMap/FcsAccordion.tsx @@ -1,29 +1,24 @@ import FcsAccordionProps from '@/domain/props/FcsAccordionProps'; -import { getFcsFoodSecurityAccordionItems } from '@/operations/map/FcsFoodSecurityOperations'; -import { getMacroEconomicAccordionOperations } from '@/operations/map/FcsMacroEconomicOperations'; +import { FcsFoodSecurityOperations } from '@/operations/map/FcsFoodSecurityOperations'; +import { FcsMacroEconomicOperations } from '@/operations/map/FcsMacroEconomicOperations'; import { useMediaQuery } from '@/utils/resolution.ts'; import AccordionContainer from '../../Accordions/AccordionContainer'; export default function FcsAccordion({ countryData, loading, countryIso3Data, countryName }: FcsAccordionProps) { const isMobile = useMediaQuery('(max-width: 700px)'); - const foodSecurityAccordion = getFcsFoodSecurityAccordionItems(countryData, countryIso3Data); - const macroEconomicAccordion = getMacroEconomicAccordionOperations(countryData, countryIso3Data); + const foodSecurityAccordion = FcsFoodSecurityOperations.getFcsFoodSecurityAccordionItems( + countryData, + countryIso3Data + ); + const macroEconomicAccordion = FcsMacroEconomicOperations.getMacroEconomicAccordionOperations( + countryData, + countryIso3Data + ); return ( <> - {!isMobile ? ( -
- -
- ) : ( + {isMobile && (
- )} + )}{' '} + : ( +
+ +
+ ) {!isMobile && (
diff --git a/src/components/Map/IpcMap/IpcAccordion.tsx b/src/components/Map/IpcMap/IpcAccordion.tsx index eb4d4def..f440d688 100644 --- a/src/components/Map/IpcMap/IpcAccordion.tsx +++ b/src/components/Map/IpcMap/IpcAccordion.tsx @@ -18,7 +18,7 @@ export default function IpcAccordion({ countryData, countryName, countryIso3Data return (
, - popoverInfo: FcsAccordionOperations.getFoodSecutriyPopoverInfo(), - content: ( -
- , - text: countryData?.population ? `${countryData.population.toFixed(2)} M` : 'N/A', - altText: 'Population Icon', - textClass: 'text-base', - }, - ]} - /> - , - text: 'Population with insufficient food consumption', - value: countryData?.fcs ? `${countryData.fcs.toFixed(2)} M` : 'N/A', - textClass: 'text-xs', - changeValues: [ - { - imageSrc: deltaOneMonth && deltaOneMonth > 0 ? '/Images/ArrowUp.svg' : '/Images/ArrowDown.svg', - text: deltaOneMonth ? `${deltaOneMonth.toFixed(2)} M` : 'N/A', - timeText: '1 Month ago', - altText: 'Delta Icon', - }, - { - imageSrc: deltaThreeMonth && deltaThreeMonth > 0 ? '/Images/ArrowUp.svg' : '/Images/ArrowDown.svg', - text: deltaThreeMonth ? `${deltaThreeMonth.toFixed(2)} M` : 'N/A', - timeText: '3 Months ago', - altText: 'Delta Icon', - }, - ], - }, - ]} - /> -
- ), - }, - { - title: 'Nutrition', - infoIcon: , - popoverInfo: FcsAccordionOperations.getFoodSecutriyPopoverInfo(), - content: - nutritionData && (nutritionData.Acute != null || nutritionData.Chronic != null) ? ( +export class FcsFoodSecurityOperations { + static getFcsFoodSecurityAccordionItems( + countryData: CountryData | undefined, + countryIso3Data: CountryIso3Data | undefined + ) { + const deltaOneMonth = countryData?.fcsMinus1 ? countryData.fcs - countryData.fcsMinus1 : null; + const deltaThreeMonth = countryData?.fcsMinus3 ? countryData.fcs - countryData.fcsMinus3 : null; + const fcsChartData = FcsAccordionOperations.getFcsChartData(countryData); + const rcsiChartData = FcsAccordionOperations.getRcsiChartData(countryData); + const nutritionData = FcsAccordionOperations.getNutritionData(countryIso3Data); + return [ + { + title: 'Food Security', + infoIcon: , + popoverInfo: FcsAccordionOperations.getFoodSecutriyPopoverInfo(), + content: (
- {nutritionData.Acute != null && ( - , - text: ( - - ), - }, - ]} + , + text: countryData?.population ? `${countryData.population.toFixed(2)} M` : 'N/A', + altText: 'Population Icon', + textClass: 'text-base', + }, + ]} + /> + , + text: 'Population with insufficient food consumption', + value: countryData?.fcs ? `${countryData.fcs.toFixed(2)} M` : 'N/A', + textClass: 'text-xs', + changeValues: [ + { + imageSrc: deltaOneMonth && deltaOneMonth > 0 ? '/Images/ArrowUp.svg' : '/Images/ArrowDown.svg', + text: deltaOneMonth ? `${deltaOneMonth.toFixed(2)} M` : 'N/A', + timeText: '1 Month ago', + altText: 'Delta Icon', + }, + { + imageSrc: + deltaThreeMonth && deltaThreeMonth > 0 ? '/Images/ArrowUp.svg' : '/Images/ArrowDown.svg', + text: deltaThreeMonth ? `${deltaThreeMonth.toFixed(2)} M` : 'N/A', + timeText: '3 Months ago', + altText: 'Delta Icon', + }, + ], + }, + ]} + /> +
+ ), + }, + { + title: 'Nutrition', + infoIcon: , + popoverInfo: FcsAccordionOperations.getFoodSecutriyPopoverInfo(), + content: + nutritionData && (nutritionData.Acute != null || nutritionData.Chronic != null) ? ( +
+ {nutritionData.Acute != null && ( + , + text: ( + + ), + }, + ]} + /> + )} + {nutritionData.Chronic != null && ( + , + text: ( + + ), + }, + ]} + /> + )} +
+ ) : ( +

No data about Nutrition is available

+ ), + }, + { + title: 'Food Security Trends', + infoIcon: , + popoverInfo: FcsAccordionOperations.getFoodSecutriyTrendsPopoverInfo(), + content: ( +
+ {fcsChartData ? ( + + ) : ( +

No data about insufficient food consumption

)} - {nutritionData.Chronic != null && ( - , - text: ( - - ), - }, - ]} + + {rcsiChartData ? ( + + ) : ( +

No data about crisis or above crisis food-based coping

)}
- ) : ( -

No data about Nutrition is available

), - }, - { - title: 'Food Security Trends', - infoIcon: , - popoverInfo: FcsAccordionOperations.getFoodSecutriyTrendsPopoverInfo(), - content: ( -
- {fcsChartData ? ( - - ) : ( -

No data about insufficient food consumption

- )} - - {rcsiChartData ? ( - - ) : ( -

No data about crisis or above crisis food-based coping

- )} -
- ), - }, - ]; + }, + ]; + } } diff --git a/src/operations/map/FcsMacroEconomicOperations.tsx b/src/operations/map/FcsMacroEconomicOperations.tsx index d246268e..ac92b7a5 100644 --- a/src/operations/map/FcsMacroEconomicOperations.tsx +++ b/src/operations/map/FcsMacroEconomicOperations.tsx @@ -1,4 +1,3 @@ -// FcsAccordionOperations.js import CustomCard from '@/components/Cards/Card'; import { LineChart } from '@/components/Charts/LineChart'; import CustomInfoCircle from '@/components/CustomInfoCircle/CustomInfoCircle'; @@ -9,77 +8,81 @@ import { cardsWrapperClass } from '@/utils/primitives'; import { ReactComponent as Import } from '../../../public/Images/Import.svg'; import { FcsAccordionOperations } from './FcsAccordionOperations'; -export function getMacroEconomicAccordionOperations( - countryData: CountryData | undefined, - countryIso3Data: CountryIso3Data | undefined -) { - const currencyExchangeChartData = FcsAccordionOperations.getCurrencyExchangeChartData(countryIso3Data); - const balanceOfTradeChartData = FcsAccordionOperations.getBalanceOfTradeChartData(countryIso3Data); - const headlineAndFoodInflationChartData = - FcsAccordionOperations.getHeadlineAndFoodInflationChartData(countryIso3Data); +export class FcsMacroEconomicOperations { + static getMacroEconomicAccordionOperations( + countryData: CountryData | undefined, + countryIso3Data: CountryIso3Data | undefined + ) { + const currencyExchangeChartData = FcsAccordionOperations.getCurrencyExchangeChartData(countryIso3Data); + const balanceOfTradeChartData = FcsAccordionOperations.getBalanceOfTradeChartData(countryIso3Data); + const headlineAndFoodInflationChartData = + FcsAccordionOperations.getHeadlineAndFoodInflationChartData(countryIso3Data); - return [ - { - title: 'Macroeconomic', - infoIcon: , - popoverInfo: FcsAccordionOperations.getMacroEconomicPopoverInfo(), - content: ( -
- , - text: countryData?.importDependency ? `${countryData.importDependency.toFixed(1)}% of Cereals` : 'N/A', - altText: 'Import Dependency Icon', - textClass: 'text-base', - }, - ]} - /> -
- ), - }, - { - title: 'Currency Exchange', - infoIcon: , - popoverInfo: FcsAccordionOperations.getCurrencyExchangePopoverInfo(), - content: ( -
- {currencyExchangeChartData ? ( - - ) : ( -

No data about currency exchange

- )} -
- ), - }, - { - title: 'Balance of Trade', - infoIcon: , - popoverInfo: FcsAccordionOperations.getBalanceOfTradePopoverInfo(), - content: ( -
- {balanceOfTradeChartData ? ( - - ) : ( -

No data about balance of trade

- )} -
- ), - }, - { - title: 'Headline and food inflation', - infoIcon: , - popoverInfo: FcsAccordionOperations.getHeadlineAndFoodInflationPopoverInfo(), - content: ( -
- {headlineAndFoodInflationChartData ? ( - - ) : ( -

No data about headline and food inflation

- )} -
- ), - }, - ]; + return [ + { + title: 'Macroeconomic', + infoIcon: , + popoverInfo: FcsAccordionOperations.getMacroEconomicPopoverInfo(), + content: ( +
+ , + text: countryData?.importDependency + ? `${countryData.importDependency.toFixed(1)}% of Cereals` + : 'N/A', + altText: 'Import Dependency Icon', + textClass: 'text-base', + }, + ]} + /> +
+ ), + }, + { + title: 'Currency Exchange', + infoIcon: , + popoverInfo: FcsAccordionOperations.getCurrencyExchangePopoverInfo(), + content: ( +
+ {currencyExchangeChartData ? ( + + ) : ( +

No data about currency exchange

+ )} +
+ ), + }, + { + title: 'Balance of Trade', + infoIcon: , + popoverInfo: FcsAccordionOperations.getBalanceOfTradePopoverInfo(), + content: ( +
+ {balanceOfTradeChartData ? ( + + ) : ( +

No data about balance of trade

+ )} +
+ ), + }, + { + title: 'Headline and food inflation', + infoIcon: , + popoverInfo: FcsAccordionOperations.getHeadlineAndFoodInflationPopoverInfo(), + content: ( +
+ {headlineAndFoodInflationChartData ? ( + + ) : ( +

No data about headline and food inflation

+ )} +
+ ), + }, + ]; + } } diff --git a/src/operations/map/IpcFoodSecurityOperations.tsx b/src/operations/map/IpcFoodSecurityOperations.tsx index 152c56f2..2a6d072f 100644 --- a/src/operations/map/IpcFoodSecurityOperations.tsx +++ b/src/operations/map/IpcFoodSecurityOperations.tsx @@ -12,40 +12,47 @@ import { ReactComponent as Population } from '../../../public/Images/Population. import { FcsAccordionOperations } from './FcsAccordionOperations'; import NutritionAccordionText from './NutritionAccordionText'; -export const IpcFoodSecurityAccordionOperations = { - getFoodSecurityAccordionItems: ( +export class IpcFoodSecurityAccordionOperations { + static getFoodSecurityAccordionItems( countryData: CountryData | undefined, deltaOneMonth: number | null, deltaThreeMonth: number | null - ) => { - const hasNoData: boolean = - !countryData || !countryData.population || !countryData.fcs || !deltaOneMonth || !deltaThreeMonth; + ) { + const hasNoData = + !countryData || !countryData.population || !countryData.fcs || deltaOneMonth === null || deltaThreeMonth === null; + + if (hasNoData) { + return { + title: 'Food Security', + infoIcon: , + popoverInfo: FcsAccordionOperations.getFoodSecutriyPopoverInfo(), + content:

No data about food security

, + }; + } return { title: 'Food Security', infoIcon: , popoverInfo: FcsAccordionOperations.getFoodSecutriyPopoverInfo(), - content: !hasNoData ? ( + content: (
- {/* Population Card */} , - text: countryData?.population ? `${countryData?.population.toFixed(2)} M` : 'N/A', + text: countryData.population ? `${countryData.population.toFixed(2)} M` : 'N/A', altText: 'Population Icon', textClass: 'text-base', }, ]} /> - {/* Food Consumption Card */} , text: 'Population with insufficient food consumption', - value: countryData?.fcs ? `${countryData?.fcs.toFixed(2)} M` : 'N/A', + value: countryData.fcs ? `${countryData.fcs.toFixed(2)} M` : 'N/A', textClass: 'text-xs', changeValues: [ { @@ -65,56 +72,57 @@ export const IpcFoodSecurityAccordionOperations = { ]} />
- ) : ( -

No data about food security

), }; - }, - getNutritionAccordion: (countryIso3Data: CountryIso3Data | undefined) => { + } + + static getNutritionAccordion(countryIso3Data: CountryIso3Data | undefined) { const nutritionData = FcsAccordionOperations.getNutritionData(countryIso3Data); + if (!nutritionData || (nutritionData.Acute == null && nutritionData.Chronic == null)) { + return { + title: 'Nutrition', + infoIcon: , + content:

No data about Nutrition is available

, + }; + } + return { title: 'Nutrition', infoIcon: , - content: - nutritionData && (nutritionData.Acute != null || nutritionData.Chronic != null) ? ( -
- {nutritionData.Acute != null && ( - , - text: ( - - ), - }, - ]} - /> - )} - {nutritionData.Chronic != null && ( - , - text: ( - - ), - }, - ]} - /> - )} -
- ) : ( -

No data about Nutrition is available

- ), + content: ( +
+ {nutritionData.Acute != null && ( + , + text: ( + + ), + }, + ]} + /> + )} + {nutritionData.Chronic != null && ( + , + text: ( + + ), + }, + ]} + /> + )} +
+ ), }; - }, -}; + } +} From 5b0d741819ed2bb44049ec26b967cb9280bf5ab6 Mon Sep 17 00:00:00 2001 From: Armanpreet Ghotra Date: Thu, 19 Dec 2024 17:31:43 +0100 Subject: [PATCH 11/18] fix: remove null and add multiple selection mode to accordions --- src/components/Map/FcsMap/FcsAccordion.tsx | 4 ++-- src/components/Map/IpcMap/IpcAccordion.tsx | 1 + src/operations/map/FcsAccordionOperations.tsx | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/components/Map/FcsMap/FcsAccordion.tsx b/src/components/Map/FcsMap/FcsAccordion.tsx index 22a3b1ff..5a4f374b 100644 --- a/src/components/Map/FcsMap/FcsAccordion.tsx +++ b/src/components/Map/FcsMap/FcsAccordion.tsx @@ -22,13 +22,13 @@ export default function FcsAccordion({ countryData, loading, countryIso3Data, co
- )}{' '} + )} : (
diff --git a/src/operations/map/FcsAccordionOperations.tsx b/src/operations/map/FcsAccordionOperations.tsx index fb5c837d..2acf5392 100644 --- a/src/operations/map/FcsAccordionOperations.tsx +++ b/src/operations/map/FcsAccordionOperations.tsx @@ -111,8 +111,8 @@ export class FcsAccordionOperations { const { wasting, stunting } = countryIso3Data.nutrition; return { - Acute: wasting || null, - Chronic: stunting || null, + Acute: wasting, + Chronic: stunting, }; } From 49ab8a97b4764c37ede358c99d6e781a8729cce8 Mon Sep 17 00:00:00 2001 From: Armanpreet Ghotra Date: Thu, 19 Dec 2024 18:00:15 +0100 Subject: [PATCH 12/18] fix: rename methods of fcs and ipc --- src/components/Map/FcsMap/FcsAccordion.tsx | 2 +- src/components/Map/IpcMap/IpcAccordion.tsx | 2 +- src/operations/map/FcsMacroEconomicOperations.tsx | 2 +- src/operations/map/IpcFoodSecurityOperations.tsx | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/Map/FcsMap/FcsAccordion.tsx b/src/components/Map/FcsMap/FcsAccordion.tsx index 5a4f374b..aa91dc54 100644 --- a/src/components/Map/FcsMap/FcsAccordion.tsx +++ b/src/components/Map/FcsMap/FcsAccordion.tsx @@ -11,7 +11,7 @@ export default function FcsAccordion({ countryData, loading, countryIso3Data, co countryData, countryIso3Data ); - const macroEconomicAccordion = FcsMacroEconomicOperations.getMacroEconomicAccordionOperations( + const macroEconomicAccordion = FcsMacroEconomicOperations.getMacroEconomicAccordionItems( countryData, countryIso3Data ); diff --git a/src/components/Map/IpcMap/IpcAccordion.tsx b/src/components/Map/IpcMap/IpcAccordion.tsx index d2c6b227..2dc0da52 100644 --- a/src/components/Map/IpcMap/IpcAccordion.tsx +++ b/src/components/Map/IpcMap/IpcAccordion.tsx @@ -12,7 +12,7 @@ export default function IpcAccordion({ countryData, countryName, countryIso3Data deltaOneMonth, deltaThreeMonth ); - const ipcNutrititonAccordion = IpcFoodSecurityAccordionOperations.getNutritionAccordion(countryIso3Data); + const ipcNutrititonAccordion = IpcFoodSecurityAccordionOperations.getNutritionAccordionItems(countryIso3Data); const isMobile = useMediaQuery('(max-width: 700px)'); return ( diff --git a/src/operations/map/FcsMacroEconomicOperations.tsx b/src/operations/map/FcsMacroEconomicOperations.tsx index ac92b7a5..bd4bc438 100644 --- a/src/operations/map/FcsMacroEconomicOperations.tsx +++ b/src/operations/map/FcsMacroEconomicOperations.tsx @@ -9,7 +9,7 @@ import { ReactComponent as Import } from '../../../public/Images/Import.svg'; import { FcsAccordionOperations } from './FcsAccordionOperations'; export class FcsMacroEconomicOperations { - static getMacroEconomicAccordionOperations( + static getMacroEconomicAccordionItems( countryData: CountryData | undefined, countryIso3Data: CountryIso3Data | undefined ) { diff --git a/src/operations/map/IpcFoodSecurityOperations.tsx b/src/operations/map/IpcFoodSecurityOperations.tsx index 2a6d072f..066b5aa0 100644 --- a/src/operations/map/IpcFoodSecurityOperations.tsx +++ b/src/operations/map/IpcFoodSecurityOperations.tsx @@ -76,7 +76,7 @@ export class IpcFoodSecurityAccordionOperations { }; } - static getNutritionAccordion(countryIso3Data: CountryIso3Data | undefined) { + static getNutritionAccordionItems(countryIso3Data: CountryIso3Data | undefined) { const nutritionData = FcsAccordionOperations.getNutritionData(countryIso3Data); if (!nutritionData || (nutritionData.Acute == null && nutritionData.Chronic == null)) { From a37249bacc7e6904af2be24700a94e79aa8b2562 Mon Sep 17 00:00:00 2001 From: Armanpreet Ghotra Date: Thu, 19 Dec 2024 18:27:55 +0100 Subject: [PATCH 13/18] fix: fix scrollbar --- src/components/Map/FcsMap/FcsAccordion.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Map/FcsMap/FcsAccordion.tsx b/src/components/Map/FcsMap/FcsAccordion.tsx index aa91dc54..24bde0b8 100644 --- a/src/components/Map/FcsMap/FcsAccordion.tsx +++ b/src/components/Map/FcsMap/FcsAccordion.tsx @@ -30,7 +30,7 @@ export default function FcsAccordion({ countryData, loading, countryIso3Data, co
)} : ( -
+
Date: Thu, 19 Dec 2024 19:19:04 +0100 Subject: [PATCH 14/18] fix: fix width of ofcs because of the scrollbar --- src/components/Map/FcsMap/FcsAccordion.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Map/FcsMap/FcsAccordion.tsx b/src/components/Map/FcsMap/FcsAccordion.tsx index 24bde0b8..8736def6 100644 --- a/src/components/Map/FcsMap/FcsAccordion.tsx +++ b/src/components/Map/FcsMap/FcsAccordion.tsx @@ -30,7 +30,7 @@ export default function FcsAccordion({ countryData, loading, countryIso3Data, co
)} : ( -
+
Date: Thu, 19 Dec 2024 21:36:33 +0100 Subject: [PATCH 15/18] fix: fix mobile version of fcs --- src/components/Map/FcsMap/FcsAccordion.tsx | 33 +++++++++------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/src/components/Map/FcsMap/FcsAccordion.tsx b/src/components/Map/FcsMap/FcsAccordion.tsx index 8736def6..79227ae0 100644 --- a/src/components/Map/FcsMap/FcsAccordion.tsx +++ b/src/components/Map/FcsMap/FcsAccordion.tsx @@ -16,20 +16,18 @@ export default function FcsAccordion({ countryData, loading, countryIso3Data, co countryIso3Data ); - return ( + return isMobile ? ( +
+ +
+ ) : ( <> - {isMobile && ( -
- -
- )} - : (
- ) - {!isMobile && ( -
- -
- )} +
+ +
); } From c70a61e13f4448ce459059704f5b0f9cc5570e97 Mon Sep 17 00:00:00 2001 From: Armanpreet Ghotra Date: Fri, 20 Dec 2024 13:40:13 +0100 Subject: [PATCH 16/18] fix: rename foodAccordion, nutritionAccordion, macroEconomicAccoridon --- src/components/Map/FcsMap/FcsAccordion.tsx | 10 +++++----- src/components/Map/IpcMap/IpcAccordion.tsx | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/components/Map/FcsMap/FcsAccordion.tsx b/src/components/Map/FcsMap/FcsAccordion.tsx index 79227ae0..f19db817 100644 --- a/src/components/Map/FcsMap/FcsAccordion.tsx +++ b/src/components/Map/FcsMap/FcsAccordion.tsx @@ -7,11 +7,11 @@ import AccordionContainer from '../../Accordions/AccordionContainer'; export default function FcsAccordion({ countryData, loading, countryIso3Data, countryName }: FcsAccordionProps) { const isMobile = useMediaQuery('(max-width: 700px)'); - const foodSecurityAccordion = FcsFoodSecurityOperations.getFcsFoodSecurityAccordionItems( + const foodSecurityAccordionItems = FcsFoodSecurityOperations.getFcsFoodSecurityAccordionItems( countryData, countryIso3Data ); - const macroEconomicAccordion = FcsMacroEconomicOperations.getMacroEconomicAccordionItems( + const macroEconomicAccordionItems = FcsMacroEconomicOperations.getMacroEconomicAccordionItems( countryData, countryIso3Data ); @@ -23,7 +23,7 @@ export default function FcsAccordion({ countryData, loading, countryIso3Data, co title={countryName} accordionModalActive maxWidth={600} - items={[...foodSecurityAccordion, ...macroEconomicAccordion]} + items={[...foodSecurityAccordionItems, ...macroEconomicAccordionItems]} />
) : ( @@ -35,12 +35,12 @@ export default function FcsAccordion({ countryData, loading, countryIso3Data, co multipleSelectionMode accordionModalActive maxWidth={600} - items={foodSecurityAccordion} + items={foodSecurityAccordionItems} expandAll />
- +
); diff --git a/src/components/Map/IpcMap/IpcAccordion.tsx b/src/components/Map/IpcMap/IpcAccordion.tsx index 2dc0da52..07b66843 100644 --- a/src/components/Map/IpcMap/IpcAccordion.tsx +++ b/src/components/Map/IpcMap/IpcAccordion.tsx @@ -7,12 +7,12 @@ export default function IpcAccordion({ countryData, countryName, countryIso3Data const deltaOneMonth = countryData?.fcsMinus1 ? countryData.fcs - countryData.fcsMinus1 : null; const deltaThreeMonth = countryData?.fcsMinus3 ? countryData.fcs - countryData.fcsMinus3 : null; - const ipcFoodSecurityAccordion = IpcFoodSecurityAccordionOperations.getFoodSecurityAccordionItems( + const foodSecurityAccordionItems = IpcFoodSecurityAccordionOperations.getFoodSecurityAccordionItems( countryData, deltaOneMonth, deltaThreeMonth ); - const ipcNutrititonAccordion = IpcFoodSecurityAccordionOperations.getNutritionAccordionItems(countryIso3Data); + const nutrititonAccordionItems = IpcFoodSecurityAccordionOperations.getNutritionAccordionItems(countryIso3Data); const isMobile = useMediaQuery('(max-width: 700px)'); return ( @@ -21,7 +21,7 @@ export default function IpcAccordion({ countryData, countryName, countryIso3Data title={countryName} accordionModalActive maxWidth={600} - items={[ipcFoodSecurityAccordion, ipcNutrititonAccordion]} + items={[foodSecurityAccordionItems, nutrititonAccordionItems]} multipleSelectionMode={!isMobile} expandAll={!isMobile} /> From 7a6e314d89dcdddfc2f8db22bea569d914939c8e Mon Sep 17 00:00:00 2001 From: Armanpreet Ghotra Date: Fri, 20 Dec 2024 14:15:55 +0100 Subject: [PATCH 17/18] fix: change the width of accordions and text size of nutrition accordion --- src/components/Map/FcsMap/FcsAccordion.tsx | 4 ++-- src/components/Map/IpcMap/IpcAccordion.tsx | 2 +- src/operations/map/NutritionAccordionText.tsx | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/components/Map/FcsMap/FcsAccordion.tsx b/src/components/Map/FcsMap/FcsAccordion.tsx index f19db817..42fe945b 100644 --- a/src/components/Map/FcsMap/FcsAccordion.tsx +++ b/src/components/Map/FcsMap/FcsAccordion.tsx @@ -28,7 +28,7 @@ export default function FcsAccordion({ countryData, loading, countryIso3Data, co
) : ( <> -
+
-
+
diff --git a/src/components/Map/IpcMap/IpcAccordion.tsx b/src/components/Map/IpcMap/IpcAccordion.tsx index 07b66843..f1e8a121 100644 --- a/src/components/Map/IpcMap/IpcAccordion.tsx +++ b/src/components/Map/IpcMap/IpcAccordion.tsx @@ -16,7 +16,7 @@ export default function IpcAccordion({ countryData, countryName, countryIso3Data const isMobile = useMediaQuery('(max-width: 700px)'); return ( -
+
- {nutritionValue} - {text} + {nutritionValue} + {text} ); } From 0901ddbb8bcf8cfb8e0c267ec14e2efa21b78581 Mon Sep 17 00:00:00 2001 From: Armanpreet Ghotra Date: Fri, 20 Dec 2024 14:19:39 +0100 Subject: [PATCH 18/18] fix: fix fcs food security width --- src/components/Map/FcsMap/FcsAccordion.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Map/FcsMap/FcsAccordion.tsx b/src/components/Map/FcsMap/FcsAccordion.tsx index 42fe945b..a36cfce5 100644 --- a/src/components/Map/FcsMap/FcsAccordion.tsx +++ b/src/components/Map/FcsMap/FcsAccordion.tsx @@ -28,7 +28,7 @@ export default function FcsAccordion({ countryData, loading, countryIso3Data, co
) : ( <> -
+