2021-09-02 12:01:08 -05:00
|
|
|
import { PanelPlugin } from '@grafana/data';
|
2022-05-04 00:58:00 -05:00
|
|
|
import { FrameState } from 'app/features/canvas/runtime/frame';
|
2021-09-02 12:01:08 -05:00
|
|
|
|
2021-10-06 14:41:42 -05:00
|
|
|
import { CanvasPanel, InstanceState } from './CanvasPanel';
|
|
|
|
import { getElementEditor } from './editor/elementEditor';
|
2021-10-13 15:12:16 -05:00
|
|
|
import { getLayerEditor } from './editor/layerEditor';
|
2022-04-22 08:33:13 -05:00
|
|
|
import { PanelOptions } from './models.gen';
|
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',
|
2021-10-20 16:52:53 -05:00
|
|
|
description: 'Enable editing the panel directly',
|
2021-10-06 14:41:42 -05:00
|
|
|
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) {
|
2021-11-16 12:10:09 -06:00
|
|
|
builder.addNestedOptions(getLayerEditor(state));
|
|
|
|
|
2021-10-13 15:12:16 -05:00
|
|
|
const selection = state.selected;
|
|
|
|
if (selection?.length === 1) {
|
2021-11-16 12:10:09 -06:00
|
|
|
const element = selection[0];
|
2022-05-04 00:58:00 -05:00
|
|
|
if (!(element instanceof FrameState)) {
|
2021-11-16 12:10:09 -06:00
|
|
|
builder.addNestedOptions(
|
|
|
|
getElementEditor({
|
2021-12-06 23:04:58 -06:00
|
|
|
category: [`Selected element (${element.options.name})`],
|
2021-11-16 12:10:09 -06:00
|
|
|
element,
|
|
|
|
scene: state.scene,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2021-10-13 15:12:16 -05:00
|
|
|
}
|
2021-10-06 14:41:42 -05:00
|
|
|
}
|
2021-09-02 12:01:08 -05:00
|
|
|
});
|