123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- import Alert from 'sentry/components/alert';
- import {t} from 'sentry/locale';
- import {EventGroupingConfig, Project} from 'sentry/types';
- export function getGroupingChanges(
- project: Project,
- groupingConfigs: EventGroupingConfig[]
- ): {
- latestGroupingConfig: EventGroupingConfig | null;
- riskLevel: number;
- updateNotes: string;
- } {
- const byId: Record<string, EventGroupingConfig> = {};
- let updateNotes: string = '';
- let riskLevel: number = 0;
- let latestGroupingConfig: EventGroupingConfig | null = null;
- groupingConfigs.forEach(cfg => {
- byId[cfg.id] = cfg;
- if (cfg.latest && project.groupingConfig !== cfg.id) {
- updateNotes = cfg.changelog;
- latestGroupingConfig = cfg;
- riskLevel = cfg.risk;
- }
- });
- if (latestGroupingConfig) {
- let next = (latestGroupingConfig as EventGroupingConfig).base ?? '';
- while (next !== project.groupingConfig) {
- const cfg = byId[next];
- if (!cfg) {
- break;
- }
- riskLevel = Math.max(riskLevel, cfg.risk);
- updateNotes = cfg.changelog + '\n' + updateNotes;
- next = cfg.base ?? '';
- }
- }
- return {updateNotes, riskLevel, latestGroupingConfig};
- }
- export function getGroupingRisk(riskLevel: number): {
- alertType: React.ComponentProps<typeof Alert>['type'];
- riskNote: React.ReactNode;
- } {
- switch (riskLevel) {
- case 0:
- return {
- riskNote: t('This upgrade has the chance to create some new issues.'),
- alertType: 'info',
- };
- case 1:
- return {
- riskNote: t('This upgrade will create some new issues.'),
- alertType: 'warning',
- };
- case 2:
- return {
- riskNote: (
- <strong>
- {t(
- 'The new grouping strategy is incompatible with the current and will create entirely new issues.'
- )}
- </strong>
- ),
- alertType: 'error',
- };
- default:
- return {riskNote: undefined, alertType: undefined};
- }
- }
|