types.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import {Layout} from 'react-grid-layout';
  2. import {User} from 'sentry/types';
  3. import {ThresholdsConfig} from './widgetBuilder/buildSteps/thresholdsStep/thresholdsStep';
  4. // Max widgets per dashboard we are currently willing
  5. // to allow to limit the load on snuba from the
  6. // parallel requests. Somewhat arbitrary
  7. // limit that can be changed if necessary.
  8. export const MAX_WIDGETS = 30;
  9. export const DEFAULT_TABLE_LIMIT = 5;
  10. export enum DisplayType {
  11. AREA = 'area',
  12. BAR = 'bar',
  13. LINE = 'line',
  14. TABLE = 'table',
  15. BIG_NUMBER = 'big_number',
  16. TOP_N = 'top_n',
  17. }
  18. export enum WidgetType {
  19. DISCOVER = 'discover',
  20. ISSUE = 'issue',
  21. RELEASE = 'metrics', // TODO(ddm): rename RELEASE to 'release', and METRICS to 'metrics'
  22. METRICS = 'custom-metrics',
  23. }
  24. export type WidgetQuery = {
  25. aggregates: string[];
  26. columns: string[];
  27. conditions: string;
  28. name: string;
  29. orderby: string;
  30. // Table column alias.
  31. // We may want to have alias for y-axis in the future too
  32. fieldAliases?: string[];
  33. // Fields is replaced with aggregates + columns. It
  34. // is currently used to track column order on table
  35. // widgets.
  36. fields?: string[];
  37. };
  38. export type Widget = {
  39. displayType: DisplayType;
  40. interval: string;
  41. queries: WidgetQuery[];
  42. title: string;
  43. description?: string;
  44. id?: string;
  45. layout?: WidgetLayout | null;
  46. // Used to define 'topEvents' when fetching time-series data for a widget
  47. limit?: number;
  48. tempId?: string;
  49. thresholds?: ThresholdsConfig | null;
  50. widgetType?: WidgetType;
  51. };
  52. // We store an explicit set of keys in the backend now
  53. export type WidgetLayout = Pick<Layout, 'h' | 'w' | 'x' | 'y'> & {
  54. minH: number;
  55. };
  56. export type WidgetPreview = {
  57. displayType: DisplayType;
  58. layout: WidgetLayout | null;
  59. };
  60. /**
  61. * The response shape from dashboard list endpoint
  62. */
  63. export type DashboardListItem = {
  64. id: string;
  65. title: string;
  66. widgetDisplay: DisplayType[];
  67. widgetPreview: WidgetPreview[];
  68. createdBy?: User;
  69. dateCreated?: string;
  70. };
  71. export enum DashboardFilterKeys {
  72. RELEASE = 'release',
  73. }
  74. export type DashboardFilters = {
  75. [DashboardFilterKeys.RELEASE]?: string[];
  76. };
  77. /**
  78. * Saved dashboard with widgets
  79. */
  80. export type DashboardDetails = {
  81. dateCreated: string;
  82. filters: DashboardFilters;
  83. id: string;
  84. projects: undefined | number[];
  85. title: string;
  86. widgets: Widget[];
  87. createdBy?: User;
  88. end?: string;
  89. environment?: string[];
  90. period?: string;
  91. start?: string;
  92. utc?: boolean;
  93. };
  94. export enum DashboardState {
  95. VIEW = 'view',
  96. EDIT = 'edit',
  97. CREATE = 'create',
  98. PENDING_DELETE = 'pending_delete',
  99. PREVIEW = 'preview',
  100. }
  101. // where we launch the dashboard widget from
  102. export enum DashboardWidgetSource {
  103. DISCOVERV2 = 'discoverv2',
  104. DASHBOARDS = 'dashboards',
  105. LIBRARY = 'library',
  106. ISSUE_DETAILS = 'issueDetail',
  107. DDM = 'ddm',
  108. }