utils.tsx 2.0 KB

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