From 51aac23822fb5e7cbbc5579dd5ca66790fd6e2b6 Mon Sep 17 00:00:00 2001 From: Alejandro Guzman Date: Thu, 30 Oct 2025 11:05:13 -0500 Subject: [PATCH] 5220 - Add country iso to location label --- src/client/pages/AdminLinks/Locations/Locations.tsx | 2 +- .../Locations/hooks/useGetLocationLabel.ts | 11 +++++++++-- src/meta/cycleData/links/links.ts | 13 +++++++++---- .../controller/cycleData/links/getManyExport.ts | 1 + 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/client/pages/AdminLinks/Locations/Locations.tsx b/src/client/pages/AdminLinks/Locations/Locations.tsx index ad18fbfb0f..bec3325e54 100644 --- a/src/client/pages/AdminLinks/Locations/Locations.tsx +++ b/src/client/pages/AdminLinks/Locations/Locations.tsx @@ -42,7 +42,7 @@ const Locations: React.FC = (props) => { {locations?.map((location, idx) => (
  • - {getLabel(location)} + {getLabel({ countryIso: link.countryIso, location })}
  • ))} diff --git a/src/client/pages/AdminLinks/Locations/hooks/useGetLocationLabel.ts b/src/client/pages/AdminLinks/Locations/hooks/useGetLocationLabel.ts index 7a786e8912..491a1ab932 100644 --- a/src/client/pages/AdminLinks/Locations/hooks/useGetLocationLabel.ts +++ b/src/client/pages/AdminLinks/Locations/hooks/useGetLocationLabel.ts @@ -1,6 +1,7 @@ import { useCallback, useMemo } from 'react' import { useTranslation } from 'react-i18next' +import { CountryIso } from 'meta/area' import { SubSection } from 'meta/assessment/section' import { LinkLocation } from 'meta/cycleData' import { Links } from 'meta/cycleData/links/links' @@ -9,7 +10,12 @@ import { useCycle } from 'client/store/meta/hooks/cycles' import { useSections } from 'client/store/meta/hooks/sections' import { useIsPanEuropeanRoute } from 'client/hooks/routes' -type Returned = (location: LinkLocation) => string +type GetLabelProps = { + countryIso: CountryIso + location: LinkLocation +} + +type Returned = (props: GetLabelProps) => string export const useGetLocationLabel = (): Returned => { const { t } = useTranslation() @@ -23,8 +29,9 @@ export const useGetLocationLabel = (): Returned => { ) return useCallback( - (location) => { + ({ countryIso, location }) => { return Links.getLocationLabel({ + countryIso, cycle, isPanEuropean, location, diff --git a/src/meta/cycleData/links/links.ts b/src/meta/cycleData/links/links.ts index 15e58c7017..3fe2f72f94 100644 --- a/src/meta/cycleData/links/links.ts +++ b/src/meta/cycleData/links/links.ts @@ -1,5 +1,6 @@ import { TFunction } from 'i18next' +import { CountryIso } from 'meta/area' import { Cycle } from 'meta/assessment/cycle' import { Descriptions } from 'meta/assessment/description/descriptions' import { CommentableDescriptionName } from 'meta/assessment/descriptionValue' @@ -15,6 +16,7 @@ const getI18nValidationStatusLabelKey = (code: LinkValidationStatusCode): string } type GetLocationLabelProps = { + countryIso: CountryIso cycle: Cycle isPanEuropean: boolean location: LinkLocation @@ -23,7 +25,7 @@ type GetLocationLabelProps = { } const getLocationLabel = (props: GetLocationLabelProps): string => { - const { cycle, isPanEuropean, location, subSections, t } = props + const { countryIso, cycle, isPanEuropean, location, subSections, t } = props const { sectionName } = location @@ -31,7 +33,8 @@ const getLocationLabel = (props: GetLocationLabelProps): string => { if ('year' in location) { const { odpSection, year } = location const descriptionLabelKey = odpSection === 'description' ? 'dataSource.comments' : 'nationalDataPoint.dataSources' - return `${year} ${t('nationalDataPoint.nationalDataPoint')} - ${t(descriptionLabelKey)}` + const label = `${year} ${t('nationalDataPoint.nationalDataPoint')} - ${t(descriptionLabelKey)}` + return `${countryIso} - ${label}` } const { descriptionName, path } = location @@ -44,11 +47,13 @@ const getLocationLabel = (props: GetLocationLabelProps): string => { }) const subSection = subSections.find((_subSection) => _subSection.props.name === sectionName) - if (!subSection) return '' + if (!subSection) return countryIso const subSectionLabel = Labels.getCycleLabel({ cycle, labels: subSection.props.labels, t }) - return `${subSectionLabel} - ${t(descriptionLabelKey, { cycleName: cycle.name })}` + const label = `${subSectionLabel} - ${t(descriptionLabelKey, { cycleName: cycle.name })}` + + return `${countryIso} - ${label}` } export const Links = { diff --git a/src/server/controller/cycleData/links/getManyExport.ts b/src/server/controller/cycleData/links/getManyExport.ts index a0393d3e5e..94dcc0c73d 100644 --- a/src/server/controller/cycleData/links/getManyExport.ts +++ b/src/server/controller/cycleData/links/getManyExport.ts @@ -44,6 +44,7 @@ export const getManyExport = async (props: Props): Promise => { const formattedLocations = (link.locations ?? []) .map((location, index) => { const label = Links.getLocationLabel({ + countryIso: link.countryIso, cycle, isPanEuropean, location,