getPanelFrameOptions.tsx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import React from 'react';
  2. import { DataLinksInlineEditor, Input, RadioButtonGroup, Select, Switch, TextArea } from '@grafana/ui';
  3. import { getPanelLinksVariableSuggestions } from 'app/features/panel/panellinks/link_srv';
  4. import { RepeatRowSelect } from '../RepeatRowSelect/RepeatRowSelect';
  5. import { OptionsPaneCategoryDescriptor } from './OptionsPaneCategoryDescriptor';
  6. import { OptionsPaneItemDescriptor } from './OptionsPaneItemDescriptor';
  7. import { OptionPaneRenderProps } from './types';
  8. export function getPanelFrameCategory(props: OptionPaneRenderProps): OptionsPaneCategoryDescriptor {
  9. const { panel, onPanelConfigChange } = props;
  10. const descriptor = new OptionsPaneCategoryDescriptor({
  11. title: 'Panel options',
  12. id: 'Panel options',
  13. isOpenDefault: true,
  14. });
  15. return descriptor
  16. .addItem(
  17. new OptionsPaneItemDescriptor({
  18. title: 'Title',
  19. value: panel.title,
  20. popularRank: 1,
  21. render: function renderTitle() {
  22. return (
  23. <Input
  24. id="PanelFrameTitle"
  25. defaultValue={panel.title}
  26. onBlur={(e) => onPanelConfigChange('title', e.currentTarget.value)}
  27. />
  28. );
  29. },
  30. })
  31. )
  32. .addItem(
  33. new OptionsPaneItemDescriptor({
  34. title: 'Description',
  35. description: panel.description,
  36. value: panel.description,
  37. render: function renderDescription() {
  38. return (
  39. <TextArea
  40. id="description-text-area"
  41. defaultValue={panel.description}
  42. onBlur={(e) => onPanelConfigChange('description', e.currentTarget.value)}
  43. />
  44. );
  45. },
  46. })
  47. )
  48. .addItem(
  49. new OptionsPaneItemDescriptor({
  50. title: 'Transparent background',
  51. render: function renderTransparent() {
  52. return (
  53. <Switch
  54. value={panel.transparent}
  55. id="transparent-background"
  56. onChange={(e) => onPanelConfigChange('transparent', e.currentTarget.checked)}
  57. />
  58. );
  59. },
  60. })
  61. )
  62. .addCategory(
  63. new OptionsPaneCategoryDescriptor({
  64. title: 'Panel links',
  65. id: 'Panel links',
  66. isOpenDefault: false,
  67. itemsCount: panel.links?.length,
  68. }).addItem(
  69. new OptionsPaneItemDescriptor({
  70. title: 'Panel links',
  71. render: function renderLinks() {
  72. return (
  73. <DataLinksInlineEditor
  74. links={panel.links}
  75. onChange={(links) => onPanelConfigChange('links', links)}
  76. getSuggestions={getPanelLinksVariableSuggestions}
  77. data={[]}
  78. />
  79. );
  80. },
  81. })
  82. )
  83. )
  84. .addCategory(
  85. new OptionsPaneCategoryDescriptor({
  86. title: 'Repeat options',
  87. id: 'Repeat options',
  88. isOpenDefault: false,
  89. })
  90. .addItem(
  91. new OptionsPaneItemDescriptor({
  92. title: 'Repeat by variable',
  93. description:
  94. 'Repeat this panel for each value in the selected variable. This is not visible while in edit mode. You need to go back to dashboard and then update the variable or reload the dashboard.',
  95. render: function renderRepeatOptions() {
  96. return (
  97. <RepeatRowSelect
  98. id="repeat-by-variable-select"
  99. repeat={panel.repeat}
  100. onChange={(value?: string | null) => {
  101. onPanelConfigChange('repeat', value);
  102. }}
  103. />
  104. );
  105. },
  106. })
  107. )
  108. .addItem(
  109. new OptionsPaneItemDescriptor({
  110. title: 'Repeat direction',
  111. showIf: () => !!panel.repeat,
  112. render: function renderRepeatOptions() {
  113. const directionOptions = [
  114. { label: 'Horizontal', value: 'h' },
  115. { label: 'Vertical', value: 'v' },
  116. ];
  117. return (
  118. <RadioButtonGroup
  119. options={directionOptions}
  120. value={panel.repeatDirection || 'h'}
  121. onChange={(value) => onPanelConfigChange('repeatDirection', value)}
  122. />
  123. );
  124. },
  125. })
  126. )
  127. .addItem(
  128. new OptionsPaneItemDescriptor({
  129. title: 'Max per row',
  130. showIf: () => Boolean(panel.repeat && panel.repeatDirection === 'h'),
  131. render: function renderOption() {
  132. const maxPerRowOptions = [2, 3, 4, 6, 8, 12].map((value) => ({ label: value.toString(), value }));
  133. return (
  134. <Select
  135. options={maxPerRowOptions}
  136. value={panel.maxPerRow}
  137. onChange={(value) => onPanelConfigChange('maxPerRow', value.value)}
  138. />
  139. );
  140. },
  141. })
  142. )
  143. );
  144. }