utils.tsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. import ExternalLink from 'sentry/components/links/externalLink';
  2. import {t, tct} from 'sentry/locale';
  3. import {Organization} from 'sentry/types';
  4. export enum Query {
  5. FOR_REVIEW = 'is:unresolved is:for_review assigned_or_suggested:[me, none]',
  6. UNRESOLVED = 'is:unresolved',
  7. IGNORED = 'is:ignored',
  8. REPROCESSING = 'is:reprocessing',
  9. }
  10. type OverviewTab = {
  11. /**
  12. * Emitted analytics event tab name
  13. */
  14. analyticsName: string;
  15. /**
  16. * Will fetch a count to display on this tab
  17. */
  18. count: boolean;
  19. /**
  20. * Tabs can be disabled via flag
  21. */
  22. enabled: boolean;
  23. name: string;
  24. /**
  25. * Tooltip text to be hoverable when text has links
  26. */
  27. tooltipHoverable?: boolean;
  28. /**
  29. * Tooltip text for each tab
  30. */
  31. tooltipTitle?: React.ReactNode;
  32. };
  33. /**
  34. * Get a list of currently active tabs
  35. */
  36. export function getTabs(organization: Organization) {
  37. const tabs: Array<[string, OverviewTab]> = [
  38. [
  39. Query.UNRESOLVED,
  40. {
  41. name: t('All Unresolved'),
  42. analyticsName: 'unresolved',
  43. count: true,
  44. enabled: true,
  45. },
  46. ],
  47. [
  48. Query.FOR_REVIEW,
  49. {
  50. name: t('For Review'),
  51. analyticsName: 'needs_review',
  52. count: true,
  53. enabled: true,
  54. tooltipTitle:
  55. t(`Issues are marked for review when they are created, unresolved, or unignored.
  56. Mark an issue reviewed to move it out of this list.
  57. Issues are automatically marked reviewed in 7 days.`),
  58. },
  59. ],
  60. [
  61. Query.IGNORED,
  62. {
  63. name: t('Ignored'),
  64. analyticsName: 'ignored',
  65. count: true,
  66. enabled: true,
  67. tooltipTitle: t(`Ignored issues don’t trigger alerts. When their ignore
  68. conditions are met they become Unresolved and are flagged for review.`),
  69. },
  70. ],
  71. [
  72. Query.REPROCESSING,
  73. {
  74. name: t('Reprocessing'),
  75. analyticsName: 'reprocessing',
  76. count: true,
  77. enabled: organization.features.includes('reprocessing-v2'),
  78. tooltipTitle: tct(
  79. `These [link:reprocessing issues] will take some time to complete.
  80. Any new issues that are created during reprocessing will be flagged for review.`,
  81. {
  82. link: (
  83. <ExternalLink href="https://docs.sentry.io/product/error-monitoring/reprocessing/" />
  84. ),
  85. }
  86. ),
  87. tooltipHoverable: true,
  88. },
  89. ],
  90. ];
  91. return tabs.filter(([_query, tab]) => tab.enabled);
  92. }
  93. /**
  94. * @returns queries that should have counts fetched
  95. */
  96. export function getTabsWithCounts(organization: Organization) {
  97. const tabs = getTabs(organization);
  98. return tabs.filter(([_query, tab]) => tab.count).map(([query]) => query);
  99. }
  100. export function isForReviewQuery(query: string | undefined) {
  101. return !!query && /\bis:for_review\b/.test(query);
  102. }
  103. // the tab counts will look like 99+
  104. export const TAB_MAX_COUNT = 99;
  105. type QueryCount = {
  106. count: number;
  107. hasMore: boolean;
  108. };
  109. export type QueryCounts = Partial<Record<Query, QueryCount>>;
  110. export enum IssueSortOptions {
  111. DATE = 'date',
  112. NEW = 'new',
  113. PRIORITY = 'priority',
  114. FREQ = 'freq',
  115. USER = 'user',
  116. TREND = 'trend',
  117. INBOX = 'inbox',
  118. }
  119. export function getSortLabel(key: string) {
  120. switch (key) {
  121. case IssueSortOptions.NEW:
  122. return t('First Seen');
  123. case IssueSortOptions.PRIORITY:
  124. return t('Priority');
  125. case IssueSortOptions.FREQ:
  126. return t('Events');
  127. case IssueSortOptions.USER:
  128. return t('Users');
  129. case IssueSortOptions.TREND:
  130. return t('Relative Change');
  131. case IssueSortOptions.INBOX:
  132. return t('Date Added');
  133. case IssueSortOptions.DATE:
  134. default:
  135. return t('Last Seen');
  136. }
  137. }
  138. export const DISCOVER_EXCLUSION_FIELDS: string[] = [
  139. 'query',
  140. 'status',
  141. 'bookmarked_by',
  142. 'assigned',
  143. 'assigned_to',
  144. 'unassigned',
  145. 'subscribed_by',
  146. 'active_at',
  147. 'first_release',
  148. 'first_seen',
  149. 'is',
  150. '__text',
  151. ];