From 85768e71c00084f9f5d3852c6a930bc62b67b0ce Mon Sep 17 00:00:00 2001 From: Vijayan Balasubramanian Date: Fri, 30 Dec 2022 16:19:33 -0800 Subject: [PATCH] Include layer name as property (#151) * Push layer name as field Include layer name as one of the properties for every feature to identify from where the feature is be coming from. Signed-off-by: Vijayan Balasubramanian --- .../components/tooltip/tooltipContainer.tsx | 6 ++-- .../components/tooltip/tooltipTable.tsx | 30 ++++++++++++++----- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/maps_dashboards/public/components/tooltip/tooltipContainer.tsx b/maps_dashboards/public/components/tooltip/tooltipContainer.tsx index d985f051..9c558d97 100644 --- a/maps_dashboards/public/components/tooltip/tooltipContainer.tsx +++ b/maps_dashboards/public/components/tooltip/tooltipContainer.tsx @@ -42,7 +42,7 @@ function toTable(featureGroupItem: FeatureGroupItem) { table.push(featureToTableRow(feature.properties)); } } - return { table, layer: featureGroupItem.layer }; + return { table, layer: featureGroupItem.layer.name }; } function createTableData(featureGroups: FeatureGroupItem[]) { @@ -64,10 +64,10 @@ export function TooltipContainer({ return 'All layers'; } if (selectedLayerIndexes.length === 1) { - return tables[selectedLayerIndexes[0]].layer.name; + return tables[selectedLayerIndexes[0]].layer; } if (selectedLayerIndexes.length > 1) { - return `${tables[selectedLayerIndexes[0]].layer.name}, +${tables.length - 1}`; + return `${tables[selectedLayerIndexes[0]].layer}, +${tables.length - 1}`; } return ''; }, [selectedLayerIndexes, tables]); diff --git a/maps_dashboards/public/components/tooltip/tooltipTable.tsx b/maps_dashboards/public/components/tooltip/tooltipTable.tsx index e0dee8af..969c0583 100644 --- a/maps_dashboards/public/components/tooltip/tooltipTable.tsx +++ b/maps_dashboards/public/components/tooltip/tooltipTable.tsx @@ -14,7 +14,6 @@ import { EuiText, } from '@elastic/eui'; import React, { useState, Fragment, useCallback, useEffect, useMemo } from 'react'; -import { DocumentLayerSpecification } from '../../model/mapLayerType'; export type RowData = { key: string; @@ -22,7 +21,7 @@ export type RowData = { }; export type PageData = RowData[]; export type TableData = PageData[]; -type Table = { table: TableData; layer: DocumentLayerSpecification }; +type Table = { table: TableData; layer: string }; export const ALL_LAYERS = -1; @@ -37,12 +36,27 @@ function mergeTables(tables: Table[], selectedIndex: number[]) { const merged: TableData = []; const allSelected = selectedIndex.includes(ALL_LAYERS); - for (let i = 0; i < tables.length; i++) { - if (allSelected || selectedIndex.includes(i)) { - merged.push(...tables[i].table); + if (!allSelected) { + for (const index of selectedIndex) { + merged.push(...tables[index].table); } + return merged; + } + const features: PageData[] = []; + for (let i = 0; i < tables.length; i++) { + tables[i].table.map((feature) => { + // Add layer name to every feature as first field + features.push( + [ + { + key: 'Layer name', + value: tables[i].layer, + }, + ].concat(feature.slice(0)) + ); + }); + merged.push(...features); } - return merged; } @@ -54,7 +68,7 @@ const TooltipTable = ({ }: Props) => { const [selectedLayers, setSelectedLayers] = useState[]>([ { - label: tables[0]?.layer.name ?? '', + label: tables[0]?.layer ?? '', value: 0, key: '0', }, @@ -110,7 +124,7 @@ const TooltipTable = ({ layerOptions.push({ label: 'All layers', value: ALL_LAYERS, key: '-1' }); } tables.forEach(({ layer }, i) => { - layerOptions.push({ label: layer.name, value: i, key: `${i}` }); + layerOptions.push({ label: layer, value: i, key: `${i}` }); }); return layerOptions; }, [tables]);