From b5c24d25e346bb81c718e6204d1c1c1ba4e2adbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1rbara=20Chaves?= Date: Thu, 21 Nov 2024 19:31:45 +0100 Subject: [PATCH] Fix tooltip translations --- .../components/map/legends/header/index.tsx | 2 +- .../map/tooltip/components/rangelands.tsx | 44 ++++++++++++------- client/src/containers/map/legends/index.tsx | 4 +- client/src/containers/map/popups/item.tsx | 2 +- 4 files changed, 34 insertions(+), 18 deletions(-) diff --git a/client/src/components/map/legends/header/index.tsx b/client/src/components/map/legends/header/index.tsx index 495304d..08ff8fe 100644 --- a/client/src/components/map/legends/header/index.tsx +++ b/client/src/components/map/legends/header/index.tsx @@ -31,7 +31,7 @@ const LegendHeader = ({ {!!info && } {subtitle && {subtitle}} diff --git a/client/src/components/map/tooltip/components/rangelands.tsx b/client/src/components/map/tooltip/components/rangelands.tsx index 7c7e23c..84aad9e 100644 --- a/client/src/components/map/tooltip/components/rangelands.tsx +++ b/client/src/components/map/tooltip/components/rangelands.tsx @@ -13,6 +13,8 @@ import { useSyncRangelandType } from "@/store/map"; import { useMemo } from "react"; import { MapTooltipProps } from "../../types"; import { useGetRangelands } from "@/types/generated/rangeland"; +import { useGetLocalizedList } from "@/lib/localized-query"; +import { useGetEcoregions } from "@/types/generated/ecoregion"; type RangelandsTooltipProps = { ecoregion_code?: number; @@ -26,10 +28,13 @@ const RangelandsTooltip = (props: MapTooltipProps) => { const t = useTranslations(); const [rangelandType] = useSyncRangelandType(); - const { data: rangelandsData } = useGetRangelands( + const biomesDataQuery = useGetRangelands( { - populate: "*", + populate: ["translations"], sort: "title:asc", + filters: { + code: `${biome_code}`, + }, }, { query: { @@ -38,6 +43,25 @@ const RangelandsTooltip = (props: MapTooltipProps) => { }, ); + const { data: biomesData } = useGetLocalizedList(biomesDataQuery); + + const ecoregionsDataQuery = useGetEcoregions( + { + populate: ["translations"], + sort: "title:asc", + filters: { + code: `${ecoregion_code}`, + }, + }, + { + query: { + enabled: rangelandType === RANGELAND_ECOREGIONS, + }, + }, + ); + + const { data: ecoregionsData } = useGetLocalizedList(ecoregionsDataQuery); + const content = useMemo(() => { if (rangelandType === RANGELAND_SYSTEM) { return { @@ -46,12 +70,7 @@ const RangelandsTooltip = (props: MapTooltipProps) => { color: RANGELAND_SISTEM_COLOR, }; } - const biome = rangelandsData?.data?.find( - (e) => - e?.attributes?.code && - isFinite(+e?.attributes?.code) && - +e?.attributes?.code === biome_code, - ); + const biome = biomesData?.data?.[0]; if (rangelandType === RANGELAND_BIOMES) { return { comparisonArea: t("Rangeland types"), @@ -60,12 +79,7 @@ const RangelandsTooltip = (props: MapTooltipProps) => { }; } if (rangelandType === RANGELAND_ECOREGIONS) { - const ecoregion = biome?.attributes?.ecoregions?.data?.find( - (e) => - e?.attributes?.code && - isFinite(+e?.attributes?.code) && - +e?.attributes?.code === ecoregion_code, - ); + const ecoregion = ecoregionsData?.data?.[0]; return { comparisonArea: biome?.attributes?.title, title: ecoregion?.attributes?.title, @@ -74,7 +88,7 @@ const RangelandsTooltip = (props: MapTooltipProps) => { }; } return {}; - }, []); + }, [rangelandType, biomesData, ecoregionsData]); return (
diff --git a/client/src/containers/map/legends/index.tsx b/client/src/containers/map/legends/index.tsx index 66acc4b..edd5f08 100644 --- a/client/src/containers/map/legends/index.tsx +++ b/client/src/containers/map/legends/index.tsx @@ -17,6 +17,8 @@ const Legends = () => { const [datasets] = useSyncDatasets(); const [open, setOpen] = useState(true); + const legendItems = Array.from(datasets).reverse(); + return (
@@ -39,7 +41,7 @@ const Legends = () => {
- {datasets?.map((d) => )} + {legendItems?.map((d) => )}
diff --git a/client/src/containers/map/popups/item.tsx b/client/src/containers/map/popups/item.tsx index c931066..857a05f 100644 --- a/client/src/containers/map/popups/item.tsx +++ b/client/src/containers/map/popups/item.tsx @@ -23,7 +23,7 @@ const Item = ({ slug }: PopupItemProps) => { const info = deckInteractiveLayers[slug]; const { data: layerData } = useGetBySlug(`layer/${slug}`, { - populate: "dataset,metadata", + populate: "dataset,metadata,translations", locale, });