The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/plugins/panel/geomap/editor/LayersEditor.tsx

81 lines
2.4 KiB

import React from 'react';
import { Container } from '@grafana/ui';
import { StandardEditorProps } from '@grafana/data';
import { DropResult } from 'react-beautiful-dnd';
import { GeomapPanelOptions, MapLayerState } from '../types';
import { GeomapInstanceState } from '../GeomapPanel';
import { geomapLayerRegistry } from '../layers/registry';
import { dataLayerFilter } from './layerEditor';
import { AddLayerButton } from 'app/core/components/Layers/AddLayerButton';
import { LayerDragDropList } from 'app/core/components/Layers/LayerDragDropList';
type LayersEditorProps = StandardEditorProps<any, any, GeomapPanelOptions, GeomapInstanceState>;
export const LayersEditor = (props: LayersEditorProps) => {
const { layers, selected, actions } = props.context.instanceState ?? {};
if (!layers || !actions) {
return <div>No layers?</div>;
}
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<any>) => {
actions.selectLayer(element.options.name);
};
const onDelete = (element: MapLayerState<any>) => {
actions.deleteLayer(element.options.name);
};
const getLayerInfo = (element: MapLayerState<any>) => {
return element.options.type;
};
const onNameChange = (element: MapLayerState<any>, name: string) => {
element.onChange({ ...element.options, name });
};
const selection = selected ? [layers[selected]?.getName()] : [];
return (
<>
<Container>
<AddLayerButton
onChange={(v) => actions.addlayer(v.value!)}
options={geomapLayerRegistry.selectOptions(undefined, dataLayerFilter).options}
label={'Add layer'}
/>
</Container>
<br />
<LayerDragDropList
layers={layers}
getLayerInfo={getLayerInfo}
onDragEnd={onDragEnd}
onSelect={onSelect}
onDelete={onDelete}
selection={selection}
excludeBaseLayer
onNameChange={onNameChange}
verifyLayerNameUniqueness={actions.canRename}
/>
</>
);
};