types.tsx 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import {EChartOption} from 'echarts';
  2. /**
  3. * Defines the keys which may be passed into the chartcuterie chart rendering
  4. * service.
  5. *
  6. * When adding or removing from this list, please also update the
  7. * sentry/charts/types.py file
  8. */
  9. export enum ChartType {
  10. SLACK_DISCOVER_TOTAL_PERIOD = 'slack:discover.totalPeriod',
  11. SLACK_DISCOVER_TOTAL_DAILY = 'slack:discover.totalDaily',
  12. SLACK_DISCOVER_TOP5_PERIOD = 'slack:discover.top5Period',
  13. SLACK_DISCOVER_TOP5_DAILY = 'slack:discover.top5Daily',
  14. }
  15. /**
  16. * XXX(epurkhiser): These are copied directly over from chartucterie to avoid
  17. * installing the package, which has some system-level dependencies we would
  18. * prefer not to install with sentry.
  19. */
  20. export type RenderOption = Omit<EChartOption, 'animation' | 'tooltip' | 'toolbox'>;
  21. /**
  22. * Describes configuration for a renderable chart style
  23. */
  24. export type RenderDescriptor<D extends string = string> = {
  25. key: D;
  26. /**
  27. * Height of the produced image in pixels
  28. */
  29. height: number;
  30. /**
  31. * Width of the produced image in pixels
  32. */
  33. width: number;
  34. /**
  35. * Produce the echart option config for rendering the charts series. It is up
  36. * to the implementation to declare what data it should receive, as long as
  37. * it produces a valid ECharts Option config.
  38. */
  39. getOption: (data: any) => RenderOption;
  40. };
  41. /**
  42. * Maps style keys to style descriptor configuration
  43. */
  44. export type RenderConfig<D extends string = string> = Map<D, RenderDescriptor<D>>;
  45. /**
  46. * The data given to the service to render a chart
  47. */
  48. export type RenderData = {
  49. /**
  50. * Globally unique render ID.
  51. */
  52. requestId: string;
  53. /**
  54. * The style config key
  55. */
  56. style: string;
  57. /**
  58. * Arbitrary series data. The RenderDescriptor.getOption should transform this
  59. * into a valid echarts series.
  60. */
  61. data: any;
  62. };
  63. /**
  64. * The configuration object type expected to be provided to the service
  65. */
  66. export type ChartcuterieConfig = {
  67. renderConfig: RenderConfig;
  68. /**
  69. * A string version identifier for the configuration. This may be useful for
  70. * validating that a chart is being rendered using a specific known
  71. * configuration.
  72. */
  73. version: string;
  74. };
  75. /**
  76. * Configuration to specify how often to poll for configuration changes
  77. */
  78. export type PollingConfig = {
  79. /**
  80. * The number of seconds between each polling attempt when the application boots
  81. * and has yet to load a configuration.
  82. */
  83. bootInterval: number;
  84. /**
  85. * The number of seconds between each polling attempt after the application
  86. * has already loaded a valid configuration file
  87. */
  88. idleInterval: number;
  89. };