module.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { PanelPlugin } from '@grafana/data';
  2. import { FrameState } from 'app/features/canvas/runtime/frame';
  3. import { CanvasPanel, InstanceState } from './CanvasPanel';
  4. import { getElementEditor } from './editor/elementEditor';
  5. import { getLayerEditor } from './editor/layerEditor';
  6. import { PanelOptions } from './models.gen';
  7. export const plugin = new PanelPlugin<PanelOptions>(CanvasPanel)
  8. .setNoPadding() // extend to panel edges
  9. .useFieldConfig()
  10. .setPanelOptions((builder, context) => {
  11. const state: InstanceState = context.instanceState;
  12. builder.addBooleanSwitch({
  13. path: 'inlineEditing',
  14. name: 'Inline editing',
  15. description: 'Enable editing the panel directly',
  16. defaultValue: true,
  17. });
  18. if (state) {
  19. builder.addNestedOptions(getLayerEditor(state));
  20. const selection = state.selected;
  21. if (selection?.length === 1) {
  22. const element = selection[0];
  23. if (!(element instanceof FrameState)) {
  24. builder.addNestedOptions(
  25. getElementEditor({
  26. category: [`Selected element (${element.options.name})`],
  27. element,
  28. scene: state.scene,
  29. })
  30. );
  31. }
  32. }
  33. }
  34. });