utils.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. import {Fragment} from 'react';
  2. import {Alert} from 'sentry/components/alert';
  3. import ExternalLink from 'sentry/components/links/externalLink';
  4. import {t, tct, tn} from 'sentry/locale';
  5. import type {IgnoredStatusDetails} from 'sentry/types';
  6. import {capitalize} from 'sentry/utils/string/capitalize';
  7. import ExtraDescription from './extraDescription';
  8. export const BULK_LIMIT = 1000;
  9. export const BULK_LIMIT_STR = BULK_LIMIT.toLocaleString();
  10. export enum ConfirmAction {
  11. RESOLVE = 'resolve',
  12. UNRESOLVE = 'unresolve',
  13. ARCHIVE = 'archive',
  14. BOOKMARK = 'bookmark',
  15. UNBOOKMARK = 'unbookmark',
  16. MERGE = 'merge',
  17. DELETE = 'delete',
  18. }
  19. function getBulkConfirmMessage(action: string, queryCount: number) {
  20. if (queryCount > BULK_LIMIT) {
  21. return tct(
  22. 'Are you sure you want to [action] the first [bulkNumber] issues that match the search?',
  23. {
  24. action,
  25. bulkNumber: BULK_LIMIT_STR,
  26. }
  27. );
  28. }
  29. return tct(
  30. 'Are you sure you want to [action] all [bulkNumber] issues that match the search?',
  31. {
  32. action,
  33. bulkNumber: queryCount,
  34. }
  35. );
  36. }
  37. function PerformanceIssueAlert({
  38. allInQuerySelected,
  39. children,
  40. }: {
  41. allInQuerySelected: boolean;
  42. children: string;
  43. }) {
  44. if (!allInQuerySelected) {
  45. return null;
  46. }
  47. return (
  48. <Alert type="info" showIcon>
  49. {children}
  50. </Alert>
  51. );
  52. }
  53. export function getConfirm({
  54. numIssues,
  55. allInQuerySelected,
  56. query,
  57. queryCount,
  58. }: {
  59. allInQuerySelected: boolean;
  60. numIssues: number;
  61. query: string;
  62. queryCount: number;
  63. }) {
  64. return function ({
  65. action,
  66. canBeUndone,
  67. append = '',
  68. }: {
  69. action: ConfirmAction;
  70. canBeUndone: boolean;
  71. append?: string;
  72. }) {
  73. const question = allInQuerySelected
  74. ? getBulkConfirmMessage(`${action}${append}`, queryCount)
  75. : tn(
  76. // Use sprintf argument swapping since the number value must come
  77. // first. See https://github.com/alexei/sprintf.js#argument-swapping
  78. `Are you sure you want to %2$s this %s issue%3$s?`,
  79. `Are you sure you want to %2$s these %s issues%3$s?`,
  80. numIssues,
  81. action,
  82. append
  83. );
  84. let message: React.ReactNode;
  85. switch (action) {
  86. case ConfirmAction.DELETE:
  87. message = (
  88. <Fragment>
  89. <p>
  90. {tct(
  91. 'Bulk deletion is only recommended for junk data. To clear your stream, consider resolving or ignoring. [link:When should I delete events?]',
  92. {
  93. link: (
  94. <ExternalLink href="https://help.sentry.io/account/billing/when-should-i-delete-events/" />
  95. ),
  96. }
  97. )}
  98. </p>
  99. <PerformanceIssueAlert allInQuerySelected={allInQuerySelected}>
  100. {t('Deleting performance issues is not yet supported and will be skipped.')}
  101. </PerformanceIssueAlert>
  102. </Fragment>
  103. );
  104. break;
  105. case ConfirmAction.MERGE:
  106. message = (
  107. <Fragment>
  108. <p>{t('Note that unmerging is currently an experimental feature.')}</p>
  109. <PerformanceIssueAlert allInQuerySelected={allInQuerySelected}>
  110. {t('Merging performance issues is not yet supported and will be skipped.')}
  111. </PerformanceIssueAlert>
  112. </Fragment>
  113. );
  114. break;
  115. default:
  116. message = !canBeUndone ? <p>{t('This action cannot be undone.')}</p> : null;
  117. }
  118. return (
  119. <div>
  120. <p style={{marginBottom: '20px'}}>
  121. <strong>{question}</strong>
  122. </p>
  123. <ExtraDescription
  124. all={allInQuerySelected}
  125. query={query}
  126. queryCount={queryCount}
  127. />
  128. {message}
  129. </div>
  130. );
  131. };
  132. }
  133. export function getLabel(numIssues: number, allInQuerySelected: boolean) {
  134. return function (action: string, append = '') {
  135. const capitalized = capitalize(action);
  136. const text = allInQuerySelected
  137. ? t('Bulk %s issues', action)
  138. : // Use sprintf argument swapping to put the capitalized string first. See
  139. // https://github.com/alexei/sprintf.js#argument-swapping
  140. tn(`%2$s %s selected issue`, `%2$s %s selected issues`, numIssues, capitalized);
  141. return text + append;
  142. };
  143. }
  144. export function performanceIssuesSupportsIgnoreAction(
  145. statusDetails: IgnoredStatusDetails
  146. ) {
  147. return !(statusDetails.ignoreWindow || statusDetails.ignoreUserWindow);
  148. }