utils.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import capitalize from 'lodash/capitalize';
  2. import ExternalLink from 'sentry/components/links/externalLink';
  3. import {t, tct, tn} from 'sentry/locale';
  4. import ExtraDescription from './extraDescription';
  5. export const BULK_LIMIT = 1000;
  6. export const BULK_LIMIT_STR = BULK_LIMIT.toLocaleString();
  7. export enum ConfirmAction {
  8. RESOLVE = 'resolve',
  9. UNRESOLVE = 'unresolve',
  10. IGNORE = 'ignore',
  11. BOOKMARK = 'bookmark',
  12. UNBOOKMARK = 'unbookmark',
  13. MERGE = 'merge',
  14. DELETE = 'delete',
  15. }
  16. function getBulkConfirmMessage(action: string, queryCount: number) {
  17. if (queryCount > BULK_LIMIT) {
  18. return tct(
  19. 'Are you sure you want to [action] the first [bulkNumber] issues that match the search?',
  20. {
  21. action,
  22. bulkNumber: BULK_LIMIT_STR,
  23. }
  24. );
  25. }
  26. return tct(
  27. 'Are you sure you want to [action] all [bulkNumber] issues that match the search?',
  28. {
  29. action,
  30. bulkNumber: queryCount,
  31. }
  32. );
  33. }
  34. export function getConfirm(
  35. numIssues: number,
  36. allInQuerySelected: boolean,
  37. query: string,
  38. queryCount: number
  39. ) {
  40. return function (action: ConfirmAction | string, canBeUndone: boolean, append = '') {
  41. const question = allInQuerySelected
  42. ? getBulkConfirmMessage(`${action}${append}`, queryCount)
  43. : tn(
  44. `Are you sure you want to ${action} this %s issue${append}?`,
  45. `Are you sure you want to ${action} these %s issues${append}?`,
  46. numIssues
  47. );
  48. let message;
  49. switch (action) {
  50. case ConfirmAction.DELETE:
  51. message = tct(
  52. 'Bulk deletion is only recommended for junk data. To clear your stream, consider resolving or ignoring. [link:When should I delete events?]',
  53. {
  54. link: (
  55. <ExternalLink href="https://help.sentry.io/account/billing/when-should-i-delete-events/" />
  56. ),
  57. }
  58. );
  59. break;
  60. case ConfirmAction.MERGE:
  61. message = t('Note that unmerging is currently an experimental feature.');
  62. break;
  63. default:
  64. message = t('This action cannot be undone.');
  65. }
  66. return (
  67. <div>
  68. <p style={{marginBottom: '20px'}}>
  69. <strong>{question}</strong>
  70. </p>
  71. <ExtraDescription
  72. all={allInQuerySelected}
  73. query={query}
  74. queryCount={queryCount}
  75. />
  76. {!canBeUndone && <p>{message}</p>}
  77. </div>
  78. );
  79. };
  80. }
  81. export function getLabel(numIssues: number, allInQuerySelected: boolean) {
  82. return function (action: string, append = '') {
  83. const capitalized = capitalize(action);
  84. const text = allInQuerySelected
  85. ? t(`Bulk ${action} issues`)
  86. : tn(
  87. `${capitalized} %s selected issue`,
  88. `${capitalized} %s selected issues`,
  89. numIssues
  90. );
  91. return text + append;
  92. };
  93. }