2021-09-02 10:01:08 -07:00
|
|
|
import { PanelPlugin } from '@grafana/data';
|
2022-05-03 22:58:00 -07:00
|
|
|
import { FrameState } from 'app/features/canvas/runtime/frame';
|
2021-09-02 10:01:08 -07:00
|
|
|
|
2021-10-06 12:41:42 -07:00
|
|
|
import { CanvasPanel, InstanceState } from './CanvasPanel';
|
|
|
|
|
import { getElementEditor } from './editor/elementEditor';
|
2021-10-13 13:12:16 -07:00
|
|
|
import { getLayerEditor } from './editor/layerEditor';
|
2022-04-22 14:33:13 +01:00
|
|
|
import { PanelOptions } from './models.gen';
|
2021-09-02 10:01:08 -07:00
|
|
|
|
|
|
|
|
export const plugin = new PanelPlugin<PanelOptions>(CanvasPanel)
|
|
|
|
|
.setNoPadding() // extend to panel edges
|
|
|
|
|
.useFieldConfig()
|
2021-10-06 12:41:42 -07:00
|
|
|
.setPanelOptions((builder, context) => {
|
|
|
|
|
const state: InstanceState = context.instanceState;
|
|
|
|
|
|
|
|
|
|
builder.addBooleanSwitch({
|
|
|
|
|
path: 'inlineEditing',
|
|
|
|
|
name: 'Inline editing',
|
2021-10-20 14:52:53 -07:00
|
|
|
description: 'Enable editing the panel directly',
|
2021-10-06 12:41:42 -07:00
|
|
|
defaultValue: true,
|
2021-09-02 10:01:08 -07:00
|
|
|
});
|
2021-10-06 12:41:42 -07:00
|
|
|
|
2021-10-13 13:12:16 -07:00
|
|
|
if (state) {
|
2021-11-16 10:10:09 -08:00
|
|
|
builder.addNestedOptions(getLayerEditor(state));
|
|
|
|
|
|
2021-10-13 13:12:16 -07:00
|
|
|
const selection = state.selected;
|
|
|
|
|
if (selection?.length === 1) {
|
2021-11-16 10:10:09 -08:00
|
|
|
const element = selection[0];
|
2022-05-03 22:58:00 -07:00
|
|
|
if (!(element instanceof FrameState)) {
|
2021-11-16 10:10:09 -08:00
|
|
|
builder.addNestedOptions(
|
|
|
|
|
getElementEditor({
|
2021-12-06 21:04:58 -08:00
|
|
|
category: [`Selected element (${element.options.name})`],
|
2021-11-16 10:10:09 -08:00
|
|
|
element,
|
|
|
|
|
scene: state.scene,
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
}
|
2021-10-13 13:12:16 -07:00
|
|
|
}
|
2021-10-06 12:41:42 -07:00
|
|
|
}
|
2021-09-02 10:01:08 -07:00
|
|
|
});
|