utils.tsx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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, my_teams, none]',
  7. UNRESOLVED = 'is:unresolved',
  8. IGNORED = 'is:ignored',
  9. NEW = 'is:new',
  10. ARCHIVED = 'is:archived',
  11. ESCALATING = 'is:escalating',
  12. REGRESSED = 'is:regressed',
  13. REPROCESSING = 'is:reprocessing',
  14. }
  15. export const CUSTOM_TAB_VALUE = '__custom__';
  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. hidden?: boolean;
  31. /**
  32. * Tooltip text to be hoverable when text has links
  33. */
  34. tooltipHoverable?: boolean;
  35. /**
  36. * Tooltip text for each tab
  37. */
  38. tooltipTitle?: React.ReactNode;
  39. };
  40. /**
  41. * Get a list of currently active tabs
  42. */
  43. export function getTabs(organization: Organization) {
  44. const hasEscalatingIssuesUi = organization.features.includes('escalating-issues');
  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. Query.FOR_REVIEW,
  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.REGRESSED,
  73. {
  74. name: t('Regressed'),
  75. analyticsName: 'regressed',
  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.ARCHIVED,
  91. {
  92. name: t('Archived'),
  93. analyticsName: 'archived',
  94. count: true,
  95. enabled: hasEscalatingIssuesUi,
  96. },
  97. ],
  98. [
  99. Query.IGNORED,
  100. {
  101. name: t('Ignored'),
  102. analyticsName: 'ignored',
  103. count: true,
  104. enabled: !hasEscalatingIssuesUi,
  105. tooltipTitle: t(`Ignored issues don’t trigger alerts. When their ignore
  106. conditions are met they become Unresolved and are flagged for review.`),
  107. },
  108. ],
  109. [
  110. Query.REPROCESSING,
  111. {
  112. name: t('Reprocessing'),
  113. analyticsName: 'reprocessing',
  114. count: true,
  115. enabled: organization.features.includes('reprocessing-v2'),
  116. tooltipTitle: tct(
  117. `These [link:reprocessing issues] will take some time to complete.
  118. Any new issues that are created during reprocessing will be flagged for review.`,
  119. {
  120. link: (
  121. <ExternalLink href="https://docs.sentry.io/product/error-monitoring/reprocessing/" />
  122. ),
  123. }
  124. ),
  125. tooltipHoverable: true,
  126. },
  127. ],
  128. [
  129. // Hidden tab to account for custom queries that don't match any of the queries
  130. // above. It's necessary because if Tabs's value doesn't match that of any tab item
  131. // then Tabs will fall back to a default value, causing unexpected behaviors.
  132. CUSTOM_TAB_VALUE,
  133. {
  134. name: t('Custom'),
  135. analyticsName: 'custom',
  136. hidden: true,
  137. count: false,
  138. enabled: true,
  139. },
  140. ],
  141. ];
  142. return tabs.filter(([_query, tab]) => tab.enabled);
  143. }
  144. /**
  145. * @returns queries that should have counts fetched
  146. */
  147. export function getTabsWithCounts(organization: Organization) {
  148. const tabs = getTabs(organization);
  149. return tabs.filter(([_query, tab]) => tab.count).map(([query]) => query);
  150. }
  151. export function isForReviewQuery(query: string | undefined) {
  152. return !!query && /\bis:for_review\b/.test(query);
  153. }
  154. // the tab counts will look like 99+
  155. export const TAB_MAX_COUNT = 99;
  156. type QueryCount = {
  157. count: number;
  158. hasMore: boolean;
  159. };
  160. export type QueryCounts = Partial<Record<Query, QueryCount>>;
  161. export enum IssueSortOptions {
  162. DATE = 'date',
  163. NEW = 'new',
  164. PRIORITY = 'priority',
  165. FREQ = 'freq',
  166. USER = 'user',
  167. INBOX = 'inbox',
  168. }
  169. export const DEFAULT_ISSUE_STREAM_SORT = IssueSortOptions.DATE;
  170. export function isDefaultIssueStreamSearch({query, sort}: {query: string; sort: string}) {
  171. return query === DEFAULT_QUERY && sort === DEFAULT_ISSUE_STREAM_SORT;
  172. }
  173. export function getSortLabel(key: string) {
  174. switch (key) {
  175. case IssueSortOptions.NEW:
  176. return t('First Seen');
  177. case IssueSortOptions.PRIORITY:
  178. return t('Priority');
  179. case IssueSortOptions.FREQ:
  180. return t('Events');
  181. case IssueSortOptions.USER:
  182. return t('Users');
  183. case IssueSortOptions.INBOX:
  184. return t('Date Added');
  185. case IssueSortOptions.DATE:
  186. default:
  187. return t('Last Seen');
  188. }
  189. }
  190. export const DISCOVER_EXCLUSION_FIELDS: string[] = [
  191. 'query',
  192. 'status',
  193. 'bookmarked_by',
  194. 'assigned',
  195. 'assigned_to',
  196. 'unassigned',
  197. 'subscribed_by',
  198. 'active_at',
  199. 'first_release',
  200. 'first_seen',
  201. 'is',
  202. '__text',
  203. ];
  204. export const FOR_REVIEW_QUERIES: string[] = [Query.FOR_REVIEW];
  205. export const SAVED_SEARCHES_SIDEBAR_OPEN_LOCALSTORAGE_KEY =
  206. 'issue-stream-saved-searches-sidebar-open';