From 2af09a894e5c26f7837f8ad48ed599da185e5285 Mon Sep 17 00:00:00 2001 From: David Cho-Lerat Date: Mon, 16 Oct 2023 14:50:04 +0200 Subject: [PATCH] SONAR-20672 Display SonarQube upgrade message in Quality Profile changelog --- .../quality-profiles/changelog/Changelog.tsx | 53 +++++++++++++++---- .../main/js/apps/quality-profiles/types.ts | 1 + .../src/main/js/helpers/testMocks.ts | 1 + .../resources/org/sonar/l10n/core.properties | 1 + 4 files changed, 46 insertions(+), 10 deletions(-) diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/changelog/Changelog.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/changelog/Changelog.tsx index a651a5e413b..47c25b4fd90 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/changelog/Changelog.tsx +++ b/server/sonar-web/src/main/js/apps/quality-profiles/changelog/Changelog.tsx @@ -21,6 +21,7 @@ import { isSameMinute } from 'date-fns'; import { CellComponent, ContentCell, + FlagMessage, Link, Note, Table, @@ -29,7 +30,7 @@ import { } from 'design-system'; import { sortBy } from 'lodash'; import * as React from 'react'; -import { useIntl } from 'react-intl'; +import { FormattedMessage, useIntl } from 'react-intl'; import DateTimeFormatter from '../../../components/intl/DateTimeFormatter'; import { CleanCodeAttributePill } from '../../../components/shared/CleanCodeAttributePill'; import SoftwareImpactPill from '../../../components/shared/SoftwareImpactPill'; @@ -52,19 +53,51 @@ export default function Changelog(props: Props) { (e) => e.action, ); + const isSameEventDate = (thisEvent: ProfileChangelogEvent, otherEvent?: ProfileChangelogEvent) => + otherEvent !== undefined && isSameMinute(parseDate(otherEvent.date), parseDate(thisEvent.date)); + + const isSameEventGroup = (thisEvent: ProfileChangelogEvent, otherEvent?: ProfileChangelogEvent) => + otherEvent !== undefined && + isSameEventDate(thisEvent, otherEvent) && + otherEvent.authorName === thisEvent.authorName && + otherEvent.action === thisEvent.action; + const rows = sortedRows.map((event, index) => { - const prev = index > 0 ? sortedRows[index - 1] : null; - const isSameDate = prev != null && isSameMinute(parseDate(prev.date), parseDate(event.date)); - const isBulkChange = - prev != null && - isSameDate && - prev.authorName === event.authorName && - prev.action === event.action; + const prev = sortedRows[index - 1]; + const isBulkChange = isSameEventGroup(event, prev); + + const nextEventInDifferentGroup = sortedRows + .slice(index + 1) + .find((e) => !isSameEventGroup(event, e)); + + const isNewSonarQubeVersion = + !isBulkChange && + nextEventInDifferentGroup !== undefined && + nextEventInDifferentGroup.sonarQubeVersion !== event.sonarQubeVersion; return ( - - {!isBulkChange && } + + {!isBulkChange && ( +
+ + + + + {isNewSonarQubeVersion && ( +
+ + + +
+ )} +
+ )}
diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/types.ts b/server/sonar-web/src/main/js/apps/quality-profiles/types.ts index 2519b302053..b361587f8ec 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/types.ts +++ b/server/sonar-web/src/main/js/apps/quality-profiles/types.ts @@ -64,6 +64,7 @@ export interface ProfileChangelogEvent { } & Dict; ruleKey: string; ruleName: string; + sonarQubeVersion: string; } export enum ProfileActionModals { diff --git a/server/sonar-web/src/main/js/helpers/testMocks.ts b/server/sonar-web/src/main/js/helpers/testMocks.ts index 53fc466a14a..b353b7baea1 100644 --- a/server/sonar-web/src/main/js/helpers/testMocks.ts +++ b/server/sonar-web/src/main/js/helpers/testMocks.ts @@ -538,6 +538,7 @@ export function mockQualityProfileChangelogEvent( ], ruleKey: 'rule-key', ruleName: 'rule-name', + sonarQubeVersion: '10.3', ...eventOverride, }; } diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties index 465d8a04f79..d7cce749480 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -2023,6 +2023,7 @@ quality_profiles.changelog.cca_only_changed=Clean Code attribute set to {newClea quality_profiles.changelog.impact_changed=Software impact set to {newSoftwareQuality} with severity {newSeverity}, was {oldSoftwareQuality} with severity {oldSeverity} quality_profiles.changelog.impact_added=Software impact {newSoftwareQuality} with severity {newSeverity} was added quality_profiles.changelog.impact_removed=Software impact {oldSoftwareQuality} with severity {oldSeverity} was removed +quality_profiles.changelog.sq_upgrade=Instance upgraded to SonarQube {sqVersion} quality_profiles.deleted_profile=The profile {0} doesn't exist anymore quality_profiles.projects_for_default=Every project not specifically associated with a quality profile will be associated to this one by default. quality_profile.x_rules={count} rule(s) -- 2.39.5