2021-09-02 12:01:08 -05:00
|
|
|
import { PanelPlugin } from '@grafana/data';
|
|
|
|
|
2021-10-06 14:41:42 -05:00
|
|
|
import { CanvasPanel, InstanceState } from './CanvasPanel';
|
|
|
|
import { PanelOptions } from './models.gen';
|
|
|
|
import { getElementEditor } from './editor/elementEditor';
|
2021-10-13 15:12:16 -05:00
|
|
|
import { getLayerEditor } from './editor/layerEditor';
|
2021-09-02 12:01:08 -05:00
|
|
|
|
|
|
|
export const plugin = new PanelPlugin<PanelOptions>(CanvasPanel)
|
|
|
|
.setNoPadding() // extend to panel edges
|
|
|
|
.useFieldConfig()
|
2021-10-06 14:41:42 -05:00
|
|
|
.setPanelOptions((builder, context) => {
|
|
|
|
const state: InstanceState = context.instanceState;
|
|
|
|
|
|
|
|
builder.addBooleanSwitch({
|
|
|
|
path: 'inlineEditing',
|
|
|
|
name: 'Inline editing',
|
|
|
|
description: 'Enable editing while the panel is in dashboard mode',
|
|
|
|
defaultValue: true,
|
2021-09-02 12:01:08 -05:00
|
|
|
});
|
2021-10-06 14:41:42 -05:00
|
|
|
|
2021-10-13 15:12:16 -05:00
|
|
|
if (state) {
|
|
|
|
const selection = state.selected;
|
|
|
|
if (selection?.length === 1) {
|
|
|
|
builder.addNestedOptions(
|
|
|
|
getElementEditor({
|
|
|
|
category: [`Selected element (id: ${selection[0].UID})`], // changing the ID forces are reload
|
|
|
|
element: selection[0],
|
|
|
|
scene: state.scene,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
console.log('NO Single seleciton', selection?.length);
|
|
|
|
}
|
|
|
|
|
|
|
|
builder.addNestedOptions(getLayerEditor(state));
|
2021-10-06 14:41:42 -05:00
|
|
|
}
|
2021-09-02 12:01:08 -05:00
|
|
|
});
|