From 7bd02054f6c7dbad6a17ed1270bb74606dee0313 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Prod=27homme?= Date: Fri, 11 Oct 2024 09:58:56 +0200 Subject: [PATCH] Only show relevant layers in the legend --- .../map/layers-toolbox/legend/index.tsx | 36 +++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/frontend/src/containers/map/content/map/layers-toolbox/legend/index.tsx b/frontend/src/containers/map/content/map/layers-toolbox/legend/index.tsx index 652e1fb9..8165f716 100644 --- a/frontend/src/containers/map/content/map/layers-toolbox/legend/index.tsx +++ b/frontend/src/containers/map/content/map/layers-toolbox/legend/index.tsx @@ -13,6 +13,7 @@ import { useSyncMapLayerSettings, useSyncMapLayers, } from '@/containers/map/content/map/sync-settings'; +import { useSyncMapContentSettings } from '@/containers/map/sync-settings'; import { cn } from '@/lib/classnames'; import ArrowDownIcon from '@/styles/icons/arrow-down.svg'; import ArrowTopIcon from '@/styles/icons/arrow-top.svg'; @@ -20,7 +21,10 @@ import CloseIcon from '@/styles/icons/close.svg'; import OpacityIcon from '@/styles/icons/opacity.svg'; import { FCWithMessages } from '@/types'; import { useGetLayers } from '@/types/generated/layer'; -import { LayerResponseDataObject } from '@/types/generated/strapi.schemas'; +import { + LayerListResponseDataItem, + LayerResponseDataObject, +} from '@/types/generated/strapi.schemas'; import { LayerTyped } from '@/types/layers'; import LegendItem from './item'; @@ -31,12 +35,38 @@ const Legend: FCWithMessages = () => { const [activeLayers, setMapLayers] = useSyncMapLayers(); const [layerSettings, setLayerSettings] = useSyncMapLayerSettings(); + const [{ tab }] = useSyncMapContentSettings(); - const layersQuery = useGetLayers( + const layersQuery = useGetLayers( { locale, sort: 'title:asc', - populate: 'legend_config,legend_config.items', + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + fields: ['title'], + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + populate: { + legend_config: { + populate: { + items: true, + }, + }, + environment: { + fields: ['slug'], + }, + }, + filters: { + ...(tab !== 'summary' + ? { + environment: { + slug: { + $in: tab, + }, + }, + } + : {}), + }, }, { query: {