utils.tsx 3.9 KB

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