types.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import type {Layout} from 'react-grid-layout';
  2. import type {User} from 'sentry/types/user';
  3. import type {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(metrics): rename RELEASE to 'release', and METRICS to 'metrics'
  22. METRICS = 'custom-metrics',
  23. }
  24. // These only pertain to on-demand warnings at this point in time
  25. // Since they are the only soft-validation we do.
  26. export type WidgetWarning = Record<string, OnDemandExtractionState>;
  27. export type WidgetQueryWarning = null | OnDemandExtractionState;
  28. export interface ValidateWidgetResponse {
  29. warnings: {
  30. columns: WidgetWarning;
  31. queries: WidgetQueryWarning[]; // Ordered, matching queries passed via the widget.
  32. };
  33. }
  34. export enum OnDemandExtractionState {
  35. DISABLED_NOT_APPLICABLE = 'disabled:not-applicable',
  36. DISABLED_PREROLLOUT = 'disabled:pre-rollout',
  37. DISABLED_MANUAL = 'disabled:manual',
  38. DISABLED_SPEC_LIMIT = 'disabled:spec-limit',
  39. DISABLED_HIGH_CARDINALITY = 'disabled:high-cardinality',
  40. ENABLED_ENROLLED = 'enabled:enrolled',
  41. ENABLED_MANUAL = 'enabled:manual',
  42. ENABLED_CREATION = 'enabled:creation',
  43. }
  44. interface WidgetQueryOnDemand {
  45. enabled: boolean;
  46. extractionState: OnDemandExtractionState;
  47. }
  48. export type WidgetQuery = {
  49. aggregates: string[];
  50. columns: string[];
  51. conditions: string;
  52. name: string;
  53. orderby: string;
  54. // Table column alias.
  55. // We may want to have alias for y-axis in the future too
  56. fieldAliases?: string[];
  57. // Fields is replaced with aggregates + columns. It
  58. // is currently used to track column order on table
  59. // widgets.
  60. fields?: string[];
  61. isHidden?: boolean | null;
  62. // Contains the on-demand entries for the widget query.
  63. onDemand?: WidgetQueryOnDemand[];
  64. };
  65. export type Widget = {
  66. displayType: DisplayType;
  67. interval: string;
  68. queries: WidgetQuery[];
  69. title: string;
  70. description?: string;
  71. id?: string;
  72. layout?: WidgetLayout | null;
  73. // Used to define 'topEvents' when fetching time-series data for a widget
  74. limit?: number;
  75. tempId?: string;
  76. thresholds?: ThresholdsConfig | null;
  77. widgetType?: WidgetType;
  78. };
  79. // We store an explicit set of keys in the backend now
  80. export type WidgetLayout = Pick<Layout, 'h' | 'w' | 'x' | 'y'> & {
  81. minH: number;
  82. };
  83. export type WidgetPreview = {
  84. displayType: DisplayType;
  85. layout: WidgetLayout | null;
  86. };
  87. /**
  88. * The response shape from dashboard list endpoint
  89. */
  90. export type DashboardListItem = {
  91. id: string;
  92. title: string;
  93. widgetDisplay: DisplayType[];
  94. widgetPreview: WidgetPreview[];
  95. createdBy?: User;
  96. dateCreated?: string;
  97. };
  98. export enum DashboardFilterKeys {
  99. RELEASE = 'release',
  100. }
  101. export type DashboardFilters = {
  102. [DashboardFilterKeys.RELEASE]?: string[];
  103. };
  104. /**
  105. * Saved dashboard with widgets
  106. */
  107. export type DashboardDetails = {
  108. dateCreated: string;
  109. filters: DashboardFilters;
  110. id: string;
  111. projects: undefined | number[];
  112. title: string;
  113. widgets: Widget[];
  114. createdBy?: User;
  115. end?: string;
  116. environment?: string[];
  117. period?: string;
  118. start?: string;
  119. utc?: boolean;
  120. };
  121. export enum DashboardState {
  122. VIEW = 'view',
  123. EDIT = 'edit',
  124. INLINE_EDIT = 'inline_edit',
  125. CREATE = 'create',
  126. PENDING_DELETE = 'pending_delete',
  127. PREVIEW = 'preview',
  128. }
  129. // where we launch the dashboard widget from
  130. export enum DashboardWidgetSource {
  131. DISCOVERV2 = 'discoverv2',
  132. DASHBOARDS = 'dashboards',
  133. LIBRARY = 'library',
  134. ISSUE_DETAILS = 'issueDetail',
  135. }