module.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import React from 'react';
  2. import { PanelModel, PanelPlugin } from '@grafana/data';
  3. import { config } from '@grafana/runtime';
  4. import { TagsInput } from '@grafana/ui';
  5. import {
  6. ALL_FOLDER,
  7. GENERAL_FOLDER,
  8. ReadonlyFolderPicker,
  9. } from '../../../core/components/Select/ReadonlyFolderPicker/ReadonlyFolderPicker';
  10. import { DashList } from './DashList';
  11. import { defaultPanelOptions, PanelLayout, PanelOptions } from './models.gen';
  12. export const plugin = new PanelPlugin<PanelOptions>(DashList)
  13. .setPanelOptions((builder) => {
  14. if (config.featureToggles.dashboardPreviews) {
  15. builder.addRadio({
  16. path: 'layout',
  17. name: 'Layout',
  18. defaultValue: PanelLayout.List,
  19. settings: {
  20. options: [
  21. { value: PanelLayout.List, label: 'List' },
  22. { value: PanelLayout.Previews, label: 'Preview' },
  23. ],
  24. },
  25. });
  26. }
  27. builder
  28. .addBooleanSwitch({
  29. path: 'showStarred',
  30. name: 'Starred',
  31. defaultValue: defaultPanelOptions.showStarred,
  32. })
  33. .addBooleanSwitch({
  34. path: 'showRecentlyViewed',
  35. name: 'Recently viewed',
  36. defaultValue: defaultPanelOptions.showRecentlyViewed,
  37. })
  38. .addBooleanSwitch({
  39. path: 'showSearch',
  40. name: 'Search',
  41. defaultValue: defaultPanelOptions.showSearch,
  42. })
  43. .addBooleanSwitch({
  44. path: 'showHeadings',
  45. name: 'Show headings',
  46. defaultValue: defaultPanelOptions.showHeadings,
  47. })
  48. .addNumberInput({
  49. path: 'maxItems',
  50. name: 'Max items',
  51. defaultValue: defaultPanelOptions.maxItems,
  52. })
  53. .addTextInput({
  54. path: 'query',
  55. name: 'Query',
  56. defaultValue: defaultPanelOptions.query,
  57. })
  58. .addCustomEditor({
  59. path: 'folderId',
  60. name: 'Folder',
  61. id: 'folderId',
  62. defaultValue: undefined,
  63. editor: function RenderFolderPicker({ value, onChange }) {
  64. return (
  65. <ReadonlyFolderPicker
  66. initialFolderId={value}
  67. onChange={(folder) => onChange(folder?.id)}
  68. extraFolders={[ALL_FOLDER, GENERAL_FOLDER]}
  69. />
  70. );
  71. },
  72. })
  73. .addCustomEditor({
  74. id: 'tags',
  75. path: 'tags',
  76. name: 'Tags',
  77. description: '',
  78. defaultValue: defaultPanelOptions.tags,
  79. editor(props) {
  80. return <TagsInput tags={props.value} onChange={props.onChange} />;
  81. },
  82. });
  83. })
  84. .setMigrationHandler((panel: PanelModel<PanelOptions> & Record<string, any>) => {
  85. const newOptions = {
  86. showStarred: panel.options.showStarred ?? panel.starred,
  87. showRecentlyViewed: panel.options.showRecentlyViewed ?? panel.recent,
  88. showSearch: panel.options.showSearch ?? panel.search,
  89. showHeadings: panel.options.showHeadings ?? panel.headings,
  90. maxItems: panel.options.maxItems ?? panel.limit,
  91. query: panel.options.query ?? panel.query,
  92. folderId: panel.options.folderId ?? panel.folderId,
  93. tags: panel.options.tags ?? panel.tags,
  94. };
  95. const previousVersion = parseFloat(panel.pluginVersion || '6.1');
  96. if (previousVersion < 6.3) {
  97. const oldProps = ['starred', 'recent', 'search', 'headings', 'limit', 'query', 'folderId'];
  98. oldProps.forEach((prop) => delete panel[prop]);
  99. }
  100. return newOptions;
  101. });