utils.tsx 5.1 KB

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