2022-11-23 06:39:19 +08:00
|
|
|
import { FieldConfigProperty, PanelOptionsEditorBuilder, PanelPlugin } from '@grafana/data';
|
2024-01-03 03:52:21 +08:00
|
|
|
import { config } from '@grafana/runtime';
|
2022-05-04 13:58:00 +08:00
|
|
|
import { FrameState } from 'app/features/canvas/runtime/frame';
|
2021-09-03 01:01:08 +08:00
|
|
|
|
2021-10-07 03:41:42 +08:00
|
|
|
import { CanvasPanel, InstanceState } from './CanvasPanel';
|
2023-04-26 01:31:45 +08:00
|
|
|
import { getConnectionEditor } from './editor/connectionEditor';
|
2023-05-25 00:32:36 +08:00
|
|
|
import { getElementEditor } from './editor/element/elementEditor';
|
|
|
|
|
import { getLayerEditor } from './editor/layer/layerEditor';
|
2024-01-03 03:52:21 +08:00
|
|
|
import { PanZoomHelp } from './editor/panZoomHelp';
|
2022-10-01 01:44:47 +08:00
|
|
|
import { canvasMigrationHandler } from './migrations';
|
2023-06-17 10:56:23 +08:00
|
|
|
import { Options } from './panelcfg.gen';
|
2021-09-03 01:01:08 +08:00
|
|
|
|
2023-05-16 11:07:54 +08:00
|
|
|
export const addStandardCanvasEditorOptions = (builder: PanelOptionsEditorBuilder<Options>) => {
|
2022-10-01 00:52:30 +08:00
|
|
|
builder.addBooleanSwitch({
|
|
|
|
|
path: 'inlineEditing',
|
|
|
|
|
name: 'Inline editing',
|
|
|
|
|
description: 'Enable editing the panel directly',
|
|
|
|
|
defaultValue: true,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
builder.addBooleanSwitch({
|
|
|
|
|
path: 'showAdvancedTypes',
|
2023-05-31 04:58:51 +08:00
|
|
|
name: 'Experimental element types',
|
|
|
|
|
description: 'Enable selection of experimental element types',
|
|
|
|
|
defaultValue: true,
|
2022-10-01 00:52:30 +08:00
|
|
|
});
|
2024-01-03 03:52:21 +08:00
|
|
|
|
|
|
|
|
builder.addBooleanSwitch({
|
|
|
|
|
path: 'panZoom',
|
|
|
|
|
name: 'Pan and zoom',
|
|
|
|
|
description: 'Enable pan and zoom',
|
|
|
|
|
defaultValue: false,
|
|
|
|
|
showIf: (opts) => config.featureToggles.canvasPanelPanZoom,
|
|
|
|
|
});
|
|
|
|
|
builder.addCustomEditor({
|
|
|
|
|
id: 'panZoomHelp',
|
|
|
|
|
path: 'panZoomHelp',
|
|
|
|
|
name: '',
|
|
|
|
|
editor: PanZoomHelp,
|
|
|
|
|
showIf: (opts) => config.featureToggles.canvasPanelPanZoom && opts.panZoom,
|
|
|
|
|
});
|
2022-10-01 00:52:30 +08:00
|
|
|
};
|
|
|
|
|
|
2023-05-16 11:07:54 +08:00
|
|
|
export const plugin = new PanelPlugin<Options>(CanvasPanel)
|
2021-09-03 01:01:08 +08:00
|
|
|
.setNoPadding() // extend to panel edges
|
2022-11-23 06:39:19 +08:00
|
|
|
.useFieldConfig({
|
|
|
|
|
standardOptions: {
|
|
|
|
|
[FieldConfigProperty.Mappings]: {
|
|
|
|
|
settings: {
|
|
|
|
|
icon: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
})
|
2022-10-01 01:44:47 +08:00
|
|
|
.setMigrationHandler(canvasMigrationHandler)
|
2021-10-07 03:41:42 +08:00
|
|
|
.setPanelOptions((builder, context) => {
|
|
|
|
|
const state: InstanceState = context.instanceState;
|
|
|
|
|
|
2022-10-01 00:52:30 +08:00
|
|
|
addStandardCanvasEditorOptions(builder);
|
2022-08-02 04:34:05 +08:00
|
|
|
|
2021-10-14 04:12:16 +08:00
|
|
|
if (state) {
|
2021-11-17 02:10:09 +08:00
|
|
|
builder.addNestedOptions(getLayerEditor(state));
|
|
|
|
|
|
2021-10-14 04:12:16 +08:00
|
|
|
const selection = state.selected;
|
2023-04-26 01:31:45 +08:00
|
|
|
const connectionSelection = state.selectedConnection;
|
|
|
|
|
|
2021-10-14 04:12:16 +08:00
|
|
|
if (selection?.length === 1) {
|
2021-11-17 02:10:09 +08:00
|
|
|
const element = selection[0];
|
2022-05-04 13:58:00 +08:00
|
|
|
if (!(element instanceof FrameState)) {
|
2021-11-17 02:10:09 +08:00
|
|
|
builder.addNestedOptions(
|
|
|
|
|
getElementEditor({
|
2021-12-07 13:04:58 +08:00
|
|
|
category: [`Selected element (${element.options.name})`],
|
2021-11-17 02:10:09 +08:00
|
|
|
element,
|
|
|
|
|
scene: state.scene,
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
}
|
2021-10-14 04:12:16 +08:00
|
|
|
}
|
2023-04-26 01:31:45 +08:00
|
|
|
|
|
|
|
|
if (connectionSelection) {
|
|
|
|
|
builder.addNestedOptions(
|
|
|
|
|
getConnectionEditor({
|
|
|
|
|
category: ['Selected connection'],
|
|
|
|
|
connection: connectionSelection,
|
|
|
|
|
scene: state.scene,
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
}
|
2021-10-07 03:41:42 +08:00
|
|
|
}
|
2021-09-03 01:01:08 +08:00
|
|
|
});
|