Skip to content

Commit

Permalink
Merge pull request #319 from Vizzuality/SKY30-480-fe-only-display-the…
Browse files Browse the repository at this point in the history
…-layers-matching-the-tab-in-the-legend

Only show relevant layers in the legend
  • Loading branch information
clementprdhomme authored Oct 11, 2024
2 parents 5728788 + 7bd0205 commit 57e0cda
Showing 1 changed file with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@ 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';
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';
Expand All @@ -31,12 +35,38 @@ const Legend: FCWithMessages = () => {

const [activeLayers, setMapLayers] = useSyncMapLayers();
const [layerSettings, setLayerSettings] = useSyncMapLayerSettings();
const [{ tab }] = useSyncMapContentSettings();

const layersQuery = useGetLayers(
const layersQuery = useGetLayers<LayerListResponseDataItem[]>(
{
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: {
Expand Down

0 comments on commit 57e0cda

Please sign in to comment.