getLibraryPanelOptions.tsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import React from 'react';
  2. import { Input } from '@grafana/ui';
  3. import { LibraryPanelInformation } from 'app/features/library-panels/components/LibraryPanelInfo/LibraryPanelInfo';
  4. import { isPanelModelLibraryPanel } from '../../../library-panels/guard';
  5. import { OptionsPaneCategoryDescriptor } from './OptionsPaneCategoryDescriptor';
  6. import { OptionsPaneItemDescriptor } from './OptionsPaneItemDescriptor';
  7. import { OptionPaneRenderProps } from './types';
  8. export function getLibraryPanelOptionsCategory(props: OptionPaneRenderProps): OptionsPaneCategoryDescriptor {
  9. const { panel, onPanelConfigChange, dashboard } = props;
  10. const descriptor = new OptionsPaneCategoryDescriptor({
  11. title: 'Library panel options',
  12. id: 'Library panel options',
  13. isOpenDefault: true,
  14. });
  15. if (isPanelModelLibraryPanel(panel)) {
  16. descriptor
  17. .addItem(
  18. new OptionsPaneItemDescriptor({
  19. title: 'Name',
  20. value: panel.libraryPanel.name,
  21. popularRank: 1,
  22. render: function renderName() {
  23. return (
  24. <Input
  25. id="LibraryPanelFrameName"
  26. defaultValue={panel.libraryPanel.name}
  27. onBlur={(e) =>
  28. onPanelConfigChange('libraryPanel', { ...panel.libraryPanel, name: e.currentTarget.value })
  29. }
  30. />
  31. );
  32. },
  33. })
  34. )
  35. .addItem(
  36. new OptionsPaneItemDescriptor({
  37. title: 'Information',
  38. render: function renderLibraryPanelInformation() {
  39. return <LibraryPanelInformation panel={panel} formatDate={dashboard.formatDate} />;
  40. },
  41. })
  42. );
  43. }
  44. return descriptor;
  45. }