From 3b41a59d7e3125daa2069ab8eb03e4c759bc9013 Mon Sep 17 00:00:00 2001 From: kaminderpal Date: Tue, 14 Nov 2023 23:30:48 -0500 Subject: [PATCH] fix(details): layer list of details component #1494 --- .../components/common/layer-list-style.ts | 1 + .../src/core/components/common/layer-list.tsx | 33 ++++--- .../core/components/data-table/data-panel.tsx | 6 +- .../core/components/details/details-panel.tsx | 89 ++++--------------- .../components/icon-stack/icon-stack-style.ts | 2 +- .../time-slider/time-slider-panel.tsx | 13 +-- 6 files changed, 43 insertions(+), 101 deletions(-) diff --git a/packages/geoview-core/src/core/components/common/layer-list-style.ts b/packages/geoview-core/src/core/components/common/layer-list-style.ts index 90ee63a84dc..c801c74b198 100644 --- a/packages/geoview-core/src/core/components/common/layer-list-style.ts +++ b/packages/geoview-core/src/core/components/common/layer-list-style.ts @@ -38,6 +38,7 @@ export const getSxClasses = (theme: Theme) => ({ minWidth: '0', marginTop: '0.5rem', marginBottom: '0.5rem', + marginLeft: '10px', flex: '1 1 auto', display: 'flex', flexDirection: 'column', diff --git a/packages/geoview-core/src/core/components/common/layer-list.tsx b/packages/geoview-core/src/core/components/common/layer-list.tsx index c4491634ad1..d67c175ca11 100644 --- a/packages/geoview-core/src/core/components/common/layer-list.tsx +++ b/packages/geoview-core/src/core/components/common/layer-list.tsx @@ -16,14 +16,22 @@ import { Typography, } from '@/ui'; import { getSxClasses } from './layer-list-style'; +import { IconStack } from '@/app'; + +export interface LayerListEntry { + layerName: string; + numOffeatures: number; + layerId: string; + layerPath: string; +} interface LayerListProps { isEnlargeDataTable: boolean; - layerList: Array<{ layerName: string; numOffeatures: number; layerId: string; layerPath: string }>; + layerList: LayerListEntry[]; selectedLayerIndex: number; - handleListItemClick: (event: React.MouseEvent, index: number) => void; - rowsFiltered: Record | undefined; - mapFiltered: Record | undefined; + handleListItemClick: (layer: LayerListEntry, index: number) => void; + rowsFiltered?: Record | undefined; + mapFiltered?: Record | undefined; } export function LayerList({ @@ -76,28 +84,27 @@ export function LayerList({ return ( - {layerList.map(({ layerPath, layerName }, index) => ( + {layerList.map((layer, index) => ( - + - handleListItemClick(event, index)}> + handleListItemClick(layer, index)}> - + - {layerName} + {layer.layerName} - {getFeaturesOfLayer(layerPath, index)} + {getFeaturesOfLayer(layer.layerPath, index)} - {isMapFilteredSelectedForLayer(layerPath) && } + {isMapFilteredSelectedForLayer(layer.layerPath) && } - , index: number) => { + const handleListItemClick = useCallback((layer: LayerListEntry, index: number) => { setSelectedLayerIndex(index); setIsLoading(true); setIsLayersPanelVisible(false); @@ -128,7 +128,7 @@ export function Datapanel({ layerData, mapId, projectionConfig, language }: Data {!isLoading && layerData.map(({ layerKey, layerId }, index) => ( - + {index === selectedLayerIndex ? ( {layerData[index].features.length ? ( diff --git a/packages/geoview-core/src/core/components/details/details-panel.tsx b/packages/geoview-core/src/core/components/details/details-panel.tsx index 6e3e58c9cf7..84ab91356ff 100644 --- a/packages/geoview-core/src/core/components/details/details-panel.tsx +++ b/packages/geoview-core/src/core/components/details/details-panel.tsx @@ -43,7 +43,7 @@ import { useDetailsStoreLayerDataArray, useDetailsStoreSelectedLayerPath, } from '@/core/stores/store-interface-and-intial-values/details-state'; -import { ResponsiveGrid, CloseButton, EnlargeButton } from '../common'; +import { ResponsiveGrid, CloseButton, EnlargeButton, LayerList } from '../common'; interface DetailsPanelProps { mapId: string; @@ -164,79 +164,24 @@ export function Detailspanel({ mapId }: DetailsPanelProps): JSX.Element { // eslint-disable-next-line react-hooks/exhaustive-deps }, [arrayOfLayerData]); - /** - * Create layer tooltip - * @param {string} layerName en/fr layer name - * @param {number} numOfFeatures number of features for a layer. - * @returns - */ - const getLayerTooltip = (layerName: string, numOfFeatures: number): React.ReactNode => { - return `${layerName ?? t('details.clickOnMap')}, ${numOfFeatures} ${t('details.feature')}${numOfFeatures > 1 ? 's' : ''}`; - }; - const renderLayerList = useCallback(() => { return ( - - {arrayOfLayerData.map((layerData) => { - const isSelectedBorder = layerData.layerPath === layerDataInfo?.layerPath; - const numOfFeatures = layerData.features!.length; - - return ( - - - - - { - setLayerDataInfo(layerData); - setCurrentFeatureIndex(0); - setSelectedLayerPath(layerData.layerPath); - setIsLayersPanelVisible(false); - }} - > - - - - - {layerData.layerName ? layerData.layerName : t('details.clickOnMap')} - - - {`${numOfFeatures} ${t('details.feature')}${numOfFeatures > 1 ? 's' : ''}`} - - - - - - - - - - - - - - ); - })} - + ({ + layerId: layer.layerName, + layerName: layer.layerName ?? '', + layerPath: layer.layerPath, + numOffeatures: layer.features?.length ?? 0, + }))} + isEnlargeDataTable={isEnlargeDataTable} + selectedLayerIndex={arrayOfLayerData.findIndex((layer) => layer.layerPath === layerDataInfo?.layerPath)} + handleListItemClick={(layer, index: number) => { + setLayerDataInfo(arrayOfLayerData[index]); + setCurrentFeatureIndex(0); + setSelectedLayerPath(arrayOfLayerData[index].layerPath); + setIsLayersPanelVisible(false); + }} + /> ); // eslint-disable-next-line react-hooks/exhaustive-deps }, [layerDataInfo, arrayOfLayerData, isEnlargeDataTable]); diff --git a/packages/geoview-core/src/core/components/icon-stack/icon-stack-style.ts b/packages/geoview-core/src/core/components/icon-stack/icon-stack-style.ts index b2e88f2624b..016768550cf 100644 --- a/packages/geoview-core/src/core/components/icon-stack/icon-stack-style.ts +++ b/packages/geoview-core/src/core/components/icon-stack/icon-stack-style.ts @@ -42,7 +42,7 @@ export const getSxClasses = () => ({ }, stackIconsBox: { position: 'relative', - marginLeft: 8, + marginLeft: '0.5rem', '&:focus': { outlineColor: 'grey', }, diff --git a/packages/geoview-core/src/core/components/time-slider/time-slider-panel.tsx b/packages/geoview-core/src/core/components/time-slider/time-slider-panel.tsx index 36c811dce69..8a1167bef7f 100644 --- a/packages/geoview-core/src/core/components/time-slider/time-slider-panel.tsx +++ b/packages/geoview-core/src/core/components/time-slider/time-slider-panel.tsx @@ -2,18 +2,7 @@ import React, { useCallback, useState } from 'react'; import { useTheme } from '@mui/material/styles'; import { t } from 'i18next'; -import { - Box, - ChevronRightIcon, - IconButton, - List, - ListItem, - ListItemButton, - ListItemIcon, - Paper, - Tooltip, - Typography, -} from '@/ui'; +import { Box, ChevronRightIcon, IconButton, List, ListItem, ListItemButton, ListItemIcon, Paper, Tooltip, Typography } from '@/ui'; import { getSxClasses } from './time-slider-style'; import { TimeSlider } from './time-slider'; import { api, getLocalizedValue, IconStack } from '@/app';