utils.tsx 5.7 KB

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