From f6b48be5e25119e4aba6d12ff36c2e37dd1707d7 Mon Sep 17 00:00:00 2001 From: Vijayan Balasubramanian Date: Fri, 9 Dec 2022 09:37:14 -0800 Subject: [PATCH] Add reorder handle inside layer panel (#116) Added icon to trigger re-order layer inside panel. Increased panel width to accomodate new icon. Signed-off-by: Vijayan Balasubramanian --- .../layer_control_panel.scss | 2 +- .../layer_control_panel.tsx | 174 +++++++++++------- 2 files changed, 113 insertions(+), 63 deletions(-) diff --git a/maps_dashboards/public/components/layer_control_panel/layer_control_panel.scss b/maps_dashboards/public/components/layer_control_panel/layer_control_panel.scss index d3b1da70..b3ad8c0c 100644 --- a/maps_dashboards/public/components/layer_control_panel/layer_control_panel.scss +++ b/maps_dashboards/public/components/layer_control_panel/layer_control_panel.scss @@ -1,6 +1,6 @@ .layerControlPanel--show { pointer-events: auto; - width: $euiSizeL * 10; + width: $euiSizeL * 11; .layerControlPanel__title { padding: $euiSizeM $euiSizeM diff --git a/maps_dashboards/public/components/layer_control_panel/layer_control_panel.tsx b/maps_dashboards/public/components/layer_control_panel/layer_control_panel.tsx index ecc291bd..0f7e4fd0 100644 --- a/maps_dashboards/public/components/layer_control_panel/layer_control_panel.tsx +++ b/maps_dashboards/public/components/layer_control_panel/layer_control_panel.tsx @@ -13,6 +13,10 @@ import { EuiButtonEmpty, EuiHorizontalRule, EuiButtonIcon, + EuiDragDropContext, + EuiDraggable, + EuiDroppable, + euiDragDropReorder, } from '@elastic/eui'; import { I18nProvider } from '@osd/i18n/react'; import { Map as Maplibre } from 'maplibre-gl'; @@ -151,6 +155,14 @@ const LayerControlPanel = memo(({ maplibreRef, setLayers, layers }: Props) => { layerVisibility.set(layer.id, layer.visibility === LAYER_VISIBILITY.VISIBLE); }); + const onDragEnd = ({ source, destination }) => { + if (source && destination) { + const reorderedLayers = euiDragDropReorder(layers, source.index, destination.index); + setLayers(reorderedLayers); + // TODO: Refresh Maplibre layers + } + }; + if (isLayerControlVisible) { return ( @@ -179,68 +191,106 @@ const LayerControlPanel = memo(({ maplibreRef, setLayers, layers }: Props) => { - {layers.map((layer, index) => { - const isLayerSelected = - isLayerConfigVisible && selectedLayerConfig && selectedLayerConfig.id === layer.id; - return ( -
- - - onClickLayerName(layer)} - /> - - - - { - if (layer.visibility === LAYER_VISIBILITY.VISIBLE) { - layer.visibility = LAYER_VISIBILITY.NONE; - setLayerVisibility(new Map(layerVisibility.set(layer.id, false))); - } else { - layer.visibility = LAYER_VISIBILITY.VISIBLE; - setLayerVisibility(new Map(layerVisibility.set(layer.id, true))); - } - layersFunctionMap[layer.type]?.hide(maplibreRef, layer); - }} - aria-label="Hide or show layer" - color="text" - /> - - - { - layersFunctionMap[layer.type]?.remove(maplibreRef, layer); - removeLayer(index); - }} - aria-label="Delete layer" - color="text" - /> - - - - -
- ); - })} + + + {layers.map((layer, index) => { + const isLayerSelected = + isLayerConfigVisible && + selectedLayerConfig && + selectedLayerConfig.id === layer.id; + return ( + + {(provided) => ( +
+ + + onClickLayerName(layer)} + /> + + + + { + if (layer.visibility === LAYER_VISIBILITY.VISIBLE) { + layer.visibility = LAYER_VISIBILITY.NONE; + setLayerVisibility( + new Map(layerVisibility.set(layer.id, false)) + ); + } else { + layer.visibility = LAYER_VISIBILITY.VISIBLE; + setLayerVisibility( + new Map(layerVisibility.set(layer.id, true)) + ); + } + layersFunctionMap[layer.type]?.hide(maplibreRef, layer); + }} + aria-label="Hide or show layer" + color="text" + /> + + + { + layersFunctionMap[layer.type]?.remove(maplibreRef, layer); + removeLayer(index); + }} + aria-label="Delete layer" + color="text" + /> + + + + + + + +
+ )} +
+ ); + })} +
+
{isLayerConfigVisible && selectedLayerConfig && (