module.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import { truncate } from '@sentry/utils';
  2. import React from 'react';
  3. import { PanelModel, PanelPlugin } from '@grafana/data';
  4. import { TagsInput } from '@grafana/ui';
  5. import { AnnoListPanel } from './AnnoListPanel';
  6. import { AnnoOptions } from './types';
  7. export const plugin = new PanelPlugin<AnnoOptions>(AnnoListPanel)
  8. .setPanelOptions((builder) => {
  9. builder
  10. .addRadio({
  11. category: ['Annotation query'],
  12. path: 'onlyFromThisDashboard',
  13. name: 'Query filter',
  14. defaultValue: false,
  15. settings: {
  16. options: [
  17. { value: false, label: 'All dashboards' },
  18. { value: true, label: 'This dashboard' },
  19. ] as any, // does not like boolean, but works fine!
  20. },
  21. })
  22. .addRadio({
  23. category: ['Annotation query'],
  24. path: 'onlyInTimeRange',
  25. name: 'Time range',
  26. defaultValue: false,
  27. settings: {
  28. options: [
  29. { value: false, label: 'None' },
  30. { value: true, label: 'This dashboard' },
  31. ] as any, // does not like boolean, but works fine!
  32. },
  33. })
  34. .addCustomEditor({
  35. category: ['Annotation query'],
  36. id: 'tags',
  37. path: 'tags',
  38. name: 'Tags',
  39. description: 'Match annotation tags',
  40. editor(props) {
  41. return <TagsInput tags={props.value} onChange={props.onChange} />;
  42. },
  43. })
  44. .addNumberInput({
  45. category: ['Annotation query'],
  46. path: 'limit',
  47. name: 'Limit',
  48. defaultValue: 10,
  49. })
  50. .addBooleanSwitch({
  51. category: ['Display'],
  52. path: 'showUser',
  53. name: 'Show user',
  54. defaultValue: true,
  55. })
  56. .addBooleanSwitch({
  57. category: ['Display'],
  58. path: 'showTime',
  59. name: 'Show time',
  60. defaultValue: true,
  61. })
  62. .addBooleanSwitch({
  63. category: ['Display'],
  64. path: 'showTags',
  65. name: 'Show tags',
  66. defaultValue: true,
  67. })
  68. .addRadio({
  69. category: ['Link behavior'],
  70. path: 'navigateToPanel',
  71. name: 'Link target',
  72. defaultValue: truncate,
  73. settings: {
  74. options: [
  75. { value: true, label: 'Panel' },
  76. { value: false, label: 'Dashboard' },
  77. ] as any, // does not like boolean, but works fine!
  78. },
  79. })
  80. .addTextInput({
  81. category: ['Link behavior'],
  82. path: 'navigateBefore',
  83. name: 'Time before',
  84. defaultValue: '10m',
  85. description: '',
  86. })
  87. .addTextInput({
  88. category: ['Link behavior'],
  89. path: 'navigateAfter',
  90. name: 'Time after',
  91. defaultValue: '10m',
  92. description: '',
  93. });
  94. })
  95. // TODO, we should support this directly in the plugin infrastructure
  96. .setPanelChangeHandler((panel: PanelModel<AnnoOptions>, prevPluginId: string, prevOptions: any) => {
  97. if (prevPluginId === 'ryantxu-annolist-panel') {
  98. return prevOptions as AnnoOptions;
  99. }
  100. return panel.options;
  101. });