From 841c48a2d4a016f9ac02c65a247c9d17511710f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Prod=27homme?= Date: Thu, 10 Oct 2024 15:37:04 +0200 Subject: [PATCH] Fix runtime error due to missing key --- .../charts/horizontal-bar-chart/index.tsx | 20 ++++++------- .../src/components/tooltip-button/index.tsx | 29 +++++++++---------- .../widgets/fishing-protection/index.tsx | 3 +- .../panels/details/widgets/habitat/index.tsx | 15 ++++++---- .../widgets/marine-conservation/index.tsx | 3 +- .../widgets/protection-types/index.tsx | 3 +- .../terrestrial-conservation/index.tsx | 3 +- 7 files changed, 39 insertions(+), 37 deletions(-) diff --git a/frontend/src/components/charts/horizontal-bar-chart/index.tsx b/frontend/src/components/charts/horizontal-bar-chart/index.tsx index 75b03cdf..7ae9a8b9 100644 --- a/frontend/src/components/charts/horizontal-bar-chart/index.tsx +++ b/frontend/src/components/charts/horizontal-bar-chart/index.tsx @@ -10,7 +10,13 @@ import { FCWithMessages } from '@/types'; const DEFAULT_MAX_PERCENTAGE = 100; const PROTECTION_TARGET = 30; -type HorizontalBarChartProps = { +interface Source { + id: number; + title: string; + url: string; +} + +interface HorizontalBarChartProps { className: string; data: { background: string; @@ -18,19 +24,11 @@ type HorizontalBarChartProps = { totalArea: number; protectedArea: number; info?: string; - sources?: - | { - title: string; - url: string; - } - | { - title: string; - url: string; - }[]; + sources?: Source | Source[]; }; showLegend?: boolean; showTarget?: boolean; -}; +} const HorizontalBarChart: FCWithMessages = ({ className, diff --git a/frontend/src/components/tooltip-button/index.tsx b/frontend/src/components/tooltip-button/index.tsx index c2664320..fa02b8b1 100644 --- a/frontend/src/components/tooltip-button/index.tsx +++ b/frontend/src/components/tooltip-button/index.tsx @@ -1,4 +1,4 @@ -import { useState } from 'react'; +import { Fragment, useState } from 'react'; import Linkify from 'react-linkify'; @@ -10,19 +10,17 @@ import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover import { cn } from '@/lib/classnames'; import { FCWithMessages } from '@/types'; -type TooltipButtonProps = { +interface Source { + id: number; + title: string; + url: string; +} + +interface TooltipButtonProps { className?: string; text: string; - sources?: - | { - title: string; - url: string; - } - | { - title: string; - url: string; - }[]; -}; + sources?: Source | Source[]; +} const TooltipButton: FCWithMessages = ({ className, text, sources }) => { const t = useTranslations('components.tooltip-button'); @@ -68,10 +66,9 @@ const TooltipButton: FCWithMessages = ({ className, text, so {Array.isArray(sources) && (
Data sources: - {sources.map(({ title, url }, index) => ( - <> + {sources.map(({ id, title, url }, index) => ( + = ({ className, text, so {title} {index < sources.length - 1 && , } - + ))}
)} diff --git a/frontend/src/containers/map/sidebar/main-panel/panels/details/widgets/fishing-protection/index.tsx b/frontend/src/containers/map/sidebar/main-panel/panels/details/widgets/fishing-protection/index.tsx index c17ac63c..5a5f11ef 100644 --- a/frontend/src/containers/map/sidebar/main-panel/panels/details/widgets/fishing-protection/index.tsx +++ b/frontend/src/containers/map/sidebar/main-panel/panels/details/widgets/fishing-protection/index.tsx @@ -68,7 +68,8 @@ const FishingProtectionWidget: FCWithMessages = ({ ? { info: data[0]?.attributes?.content, sources: data[0]?.attributes?.data_sources?.data?.map( - ({ attributes: { title, url } }) => ({ + ({ id, attributes: { title, url } }) => ({ + id, title, url, }) diff --git a/frontend/src/containers/map/sidebar/main-panel/panels/details/widgets/habitat/index.tsx b/frontend/src/containers/map/sidebar/main-panel/panels/details/widgets/habitat/index.tsx index d2019cae..1eb1c73f 100644 --- a/frontend/src/containers/map/sidebar/main-panel/panels/details/widgets/habitat/index.tsx +++ b/frontend/src/containers/map/sidebar/main-panel/panels/details/widgets/habitat/index.tsx @@ -23,7 +23,7 @@ const HabitatWidget: FCWithMessages = ({ location }) => { const [{ tab }] = useSyncMapContentSettings(); const { data: habitatMetadatas } = useGetDataInfos< - { slug: string; info: string; sources?: { title: string; url: string }[] }[] + { slug: string; info: string; sources?: { id: number; title: string; url: string }[] }[] >( { locale, @@ -45,10 +45,13 @@ const HabitatWidget: FCWithMessages = ({ location }) => { data?.map((item) => ({ slug: item.attributes.slug, info: item.attributes.content, - sources: item.attributes.data_sources?.data?.map(({ attributes: { title, url } }) => ({ - title, - url, - })), + sources: item.attributes.data_sources?.data?.map( + ({ id, attributes: { title, url } }) => ({ + id, + title, + url, + }) + ), })) ?? [], }, } @@ -62,7 +65,7 @@ const HabitatWidget: FCWithMessages = ({ location }) => { totalArea: number; protectedArea: number; info?: string; - sources?: { title: string; url: string }[]; + sources?: { id: number; title: string; url: string }[]; updatedAt: string; }[] >( diff --git a/frontend/src/containers/map/sidebar/main-panel/panels/details/widgets/marine-conservation/index.tsx b/frontend/src/containers/map/sidebar/main-panel/panels/details/widgets/marine-conservation/index.tsx index 3cd0461f..a43e3627 100644 --- a/frontend/src/containers/map/sidebar/main-panel/panels/details/widgets/marine-conservation/index.tsx +++ b/frontend/src/containers/map/sidebar/main-panel/panels/details/widgets/marine-conservation/index.tsx @@ -100,7 +100,8 @@ const MarineConservationWidget: FCWithMessages = ? { info: data[0].attributes.content, sources: data[0].attributes?.data_sources?.data?.map( - ({ attributes: { title, url } }) => ({ + ({ id, attributes: { title, url } }) => ({ + id, title, url, }) diff --git a/frontend/src/containers/map/sidebar/main-panel/panels/details/widgets/protection-types/index.tsx b/frontend/src/containers/map/sidebar/main-panel/panels/details/widgets/protection-types/index.tsx index f74019bf..55cb6020 100644 --- a/frontend/src/containers/map/sidebar/main-panel/panels/details/widgets/protection-types/index.tsx +++ b/frontend/src/containers/map/sidebar/main-panel/panels/details/widgets/protection-types/index.tsx @@ -61,7 +61,8 @@ const ProtectionTypesWidget: FCWithMessages = ({ loc ? { info: data[0]?.attributes?.content, sources: data[0]?.attributes?.data_sources?.data?.map( - ({ attributes: { title, url } }) => ({ + ({ id, attributes: { title, url } }) => ({ + id, title, url, }) diff --git a/frontend/src/containers/map/sidebar/main-panel/panels/details/widgets/terrestrial-conservation/index.tsx b/frontend/src/containers/map/sidebar/main-panel/panels/details/widgets/terrestrial-conservation/index.tsx index aab79b79..22176ceb 100644 --- a/frontend/src/containers/map/sidebar/main-panel/panels/details/widgets/terrestrial-conservation/index.tsx +++ b/frontend/src/containers/map/sidebar/main-panel/panels/details/widgets/terrestrial-conservation/index.tsx @@ -102,7 +102,8 @@ const TerrestrialConservationWidget: FCWithMessages ({ + ({ id, attributes: { title, url } }) => ({ + id, title, url, })