import React from 'react'; import { DropResult } from 'react-beautiful-dnd'; import { StandardEditorProps } from '@grafana/data'; import { Container } from '@grafana/ui'; import { AddLayerButton } from 'app/core/components/Layers/AddLayerButton'; import { LayerDragDropList } from 'app/core/components/Layers/LayerDragDropList'; import { GeomapInstanceState } from '../GeomapPanel'; import { getLayersOptions } from '../layers/registry'; import { GeomapPanelOptions, MapLayerState } from '../types'; type LayersEditorProps = StandardEditorProps; export const LayersEditor = (props: LayersEditorProps) => { const { layers, selected, actions } = props.context.instanceState ?? {}; if (!layers || !actions) { return
No layers?
; } const onDragEnd = (result: DropResult) => { if (!result.destination) { return; } const { layers, actions } = props.context.instanceState ?? {}; if (!layers || !actions) { return; } // account for the reverse order and offset (0 is baselayer) const count = layers.length - 1; const src = (result.source.index - count) * -1; const dst = (result.destination.index - count) * -1; actions.reorder(src, dst); }; const onSelect = (element: MapLayerState) => { actions.selectLayer(element.options.name); }; const onDelete = (element: MapLayerState) => { actions.deleteLayer(element.options.name); }; const getLayerInfo = (element: MapLayerState) => { return element.options.type; }; const onNameChange = (element: MapLayerState, name: string) => { element.onChange({ ...element.options, name }); }; const selection = selected ? [layers[selected]?.getName()] : []; return ( <> actions.addlayer(v.value!)} options={getLayersOptions(false).options} label={'Add layer'} />
layers.length > 2} // 2 because base layer is not counted! getLayerInfo={getLayerInfo} onDragEnd={onDragEnd} onSelect={onSelect} onDelete={onDelete} selection={selection} excludeBaseLayer onNameChange={onNameChange} verifyLayerNameUniqueness={actions.canRename} /> ); };