utils.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import type {AlertProps} from 'sentry/components/alert';
  2. import {t} from 'sentry/locale';
  3. import {EventGroupingConfig, Project} from 'sentry/types';
  4. export function getGroupingChanges(
  5. project: Project,
  6. groupingConfigs: EventGroupingConfig[]
  7. ): {
  8. latestGroupingConfig: EventGroupingConfig | null;
  9. riskLevel: number;
  10. updateNotes: string;
  11. } {
  12. const byId: Record<string, EventGroupingConfig> = {};
  13. let updateNotes: string = '';
  14. let riskLevel: number = 0;
  15. let latestGroupingConfig: EventGroupingConfig | null = null;
  16. groupingConfigs.forEach(cfg => {
  17. byId[cfg.id] = cfg;
  18. if (cfg.latest && project.groupingConfig !== cfg.id) {
  19. updateNotes = cfg.changelog;
  20. latestGroupingConfig = cfg;
  21. riskLevel = cfg.risk;
  22. }
  23. });
  24. if (latestGroupingConfig) {
  25. let next = (latestGroupingConfig as EventGroupingConfig).base ?? '';
  26. while (next !== project.groupingConfig) {
  27. const cfg = byId[next];
  28. if (!cfg) {
  29. break;
  30. }
  31. riskLevel = Math.max(riskLevel, cfg.risk);
  32. updateNotes = cfg.changelog + '\n' + updateNotes;
  33. next = cfg.base ?? '';
  34. }
  35. }
  36. return {updateNotes, riskLevel, latestGroupingConfig};
  37. }
  38. export function getGroupingRisk(riskLevel: number): {
  39. alertType: AlertProps['type'];
  40. riskNote: React.ReactNode;
  41. } {
  42. switch (riskLevel) {
  43. case 0:
  44. return {
  45. riskNote: t('This upgrade has the chance to create some new issues.'),
  46. alertType: 'info',
  47. };
  48. case 1:
  49. return {
  50. riskNote: t('This upgrade will create some new issues.'),
  51. alertType: 'warning',
  52. };
  53. case 2:
  54. return {
  55. riskNote: (
  56. <strong>
  57. {t(
  58. 'The new grouping strategy is incompatible with the current and will create entirely new issues.'
  59. )}
  60. </strong>
  61. ),
  62. alertType: 'error',
  63. };
  64. default:
  65. return {riskNote: undefined, alertType: undefined};
  66. }
  67. }