]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-20667 Display an event (in project activity tab) for the first analysis since...
authorAmbroise C <ambroise.christea@sonarsource.com>
Tue, 10 Oct 2023 12:24:22 +0000 (14:24 +0200)
committersonartech <sonartech@sonarsource.com>
Fri, 13 Oct 2023 20:02:54 +0000 (20:02 +0000)
server/sonar-web/src/main/js/apps/overview/branches/Event.tsx
server/sonar-web/src/main/js/apps/projectActivity/components/Events.tsx
server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityPageFilters.tsx
server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/ProjectActivityApp-it.tsx
server/sonar-web/src/main/js/components/activity-graph/EventInner.tsx
server/sonar-web/src/main/js/components/activity-graph/SqUpgradeActivityEventMessage.tsx [new file with mode: 0644]
server/sonar-web/src/main/js/components/activity-graph/__tests__/EventInner-it.tsx
sonar-core/src/main/resources/org/sonar/l10n/core.properties

index 6bca7ea5d14865ac53d3a7f5669034608192b676..baba62bdd5a09a64b032795e87a275e34bc2e13c 100644 (file)
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
-import { Badge, FlagMessage, QualityGateIndicator } from 'design-system';
+import { Badge, QualityGateIndicator } from 'design-system';
 import * as React from 'react';
 import { FormattedMessage } from 'react-intl';
 import { isDefinitionChangeEvent } from '../../../components/activity-graph/DefinitionChangeEventInner';
 import { isRichQualityGateEvent } from '../../../components/activity-graph/RichQualityGateEventInner';
+import { SqUpgradeActivityEventMessage } from '../../../components/activity-graph/SqUpgradeActivityEventMessage';
 import { translate } from '../../../helpers/l10n';
 import { AnalysisEvent, ProjectAnalysisEventCategory } from '../../../types/project-activity';
 
@@ -41,16 +42,7 @@ export function Event({ event }: Props) {
   }
 
   if (event.category === ProjectAnalysisEventCategory.SqUpgrade) {
-    return (
-      <FlagMessage className="sw-my-1" id={event.key} variant="info">
-        <FormattedMessage
-          id="event.sqUpgrade"
-          values={{
-            sqVersion: event.name,
-          }}
-        />
-      </FlagMessage>
-    );
+    return <SqUpgradeActivityEventMessage event={event} />;
   }
 
   const eventCategory = translate('event.category', event.category);
index 7cbc39b72ad1b4beb1ee723b9ae34edec54962fc..20ca14583fc529a1c9ac051513c4767a610b1855 100644 (file)
@@ -36,9 +36,19 @@ function Events(props: EventsProps) {
 
   const sortedEvents = sortBy(
     events,
-    // versions last
-    (event) => (event.category === ProjectAnalysisEventCategory.Version ? 1 : 0),
-    // then the rest sorted by category
+    (event) => {
+      switch (event.category) {
+        case ProjectAnalysisEventCategory.SqUpgrade:
+          // SQ Upgrade first
+          return 0;
+        case ProjectAnalysisEventCategory.Version:
+          // versions last
+          return 2;
+        default:
+          // then the rest in between, sorted by category
+          return 1;
+      }
+    },
     'category',
   );
 
index eb3c15e6e47a55d0ee4a56aa30a8f55744b87cf7..e1878af8ab28867f0d7736236d81d1f6bf4db8c2 100644 (file)
@@ -65,7 +65,7 @@ export default function ProjectActivityPageFilters(props: ProjectActivityPageFil
           onChange={(data: LabelValueSelectOption<string>) => handleCategoryChange(data)}
           options={options}
           placeholder={translate('project_activity.filter_events')}
-          size="small"
+          size="full"
           value={options.find((o) => o.value === category)}
           classNames={{
             menu: () => 'sw-z-dropdown-menu-page',
index 3202be860fbe4d05d43622ebebe9cbb4fd364c4a..11b9882ae3648de212bd0f3a2593663d3ee2b274 100644 (file)
@@ -361,6 +361,18 @@ describe('filtering', () => {
         key: `analysis-4`,
         events: [mockAnalysisEvent({ key: '3', category: ProjectAnalysisEventCategory.Version })],
       }),
+      mockAnalysis({
+        key: `analysis-5`,
+        events: [mockAnalysisEvent({ key: '4', category: ProjectAnalysisEventCategory.SqUpgrade })],
+      }),
+      mockAnalysis({
+        key: `analysis-6`,
+        events: [mockAnalysisEvent({ key: '5', category: ProjectAnalysisEventCategory.Version })],
+      }),
+      mockAnalysis({
+        key: `analysis-7`,
+        events: [mockAnalysisEvent({ key: '6', category: ProjectAnalysisEventCategory.SqUpgrade })],
+      }),
     ]);
 
     const { ui } = getPageObject();
@@ -368,10 +380,13 @@ describe('filtering', () => {
     await ui.appLoaded();
 
     await ui.filterByCategory(ProjectAnalysisEventCategory.Version);
-    expect(ui.activityItem.getAll().length).toBe(2);
+    expect(ui.activityItem.getAll().length).toBe(3);
 
     await ui.filterByCategory(ProjectAnalysisEventCategory.QualityGate);
     expect(ui.activityItem.getAll().length).toBe(1);
+
+    await ui.filterByCategory(ProjectAnalysisEventCategory.SqUpgrade);
+    expect(ui.activityItem.getAll().length).toBe(2);
   });
 
   it('should correctly filter by date range', async () => {
index 0c127643f6d4a450a88a5fc3b123b23e77236474..306ef35873a535d03c428fcc4158faa228483a1e 100644 (file)
@@ -22,10 +22,11 @@ import * as React from 'react';
 import { ComponentContext } from '../../app/components/componentContext/ComponentContext';
 import { translate } from '../../helpers/l10n';
 import { useBranchesQuery } from '../../queries/branch';
-import { AnalysisEvent } from '../../types/project-activity';
+import { AnalysisEvent, ProjectAnalysisEventCategory } from '../../types/project-activity';
 import Tooltip from '../controls/Tooltip';
 import { DefinitionChangeEventInner, isDefinitionChangeEvent } from './DefinitionChangeEventInner';
 import { RichQualityGateEventInner, isRichQualityGateEvent } from './RichQualityGateEventInner';
+import { SqUpgradeActivityEventMessage } from './SqUpgradeActivityEventMessage';
 
 export interface EventInnerProps {
   event: AnalysisEvent;
@@ -39,6 +40,8 @@ export default function EventInner({ event, readonly }: EventInnerProps) {
     return <RichQualityGateEventInner event={event} readonly={readonly} />;
   } else if (isDefinitionChangeEvent(event)) {
     return <DefinitionChangeEventInner branchLike={branchLike} event={event} readonly={readonly} />;
+  } else if (event.category === ProjectAnalysisEventCategory.SqUpgrade) {
+    return <SqUpgradeActivityEventMessage event={event} />;
   }
 
   const tooltipContent =
diff --git a/server/sonar-web/src/main/js/components/activity-graph/SqUpgradeActivityEventMessage.tsx b/server/sonar-web/src/main/js/components/activity-graph/SqUpgradeActivityEventMessage.tsx
new file mode 100644 (file)
index 0000000..7b1b962
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+import { FlagMessage } from 'design-system';
+import React from 'react';
+import { FormattedMessage } from 'react-intl';
+import { AnalysisEvent } from '../../types/project-activity';
+
+interface SqUpgradeActivityEventMessageProps {
+  event: AnalysisEvent;
+}
+
+export function SqUpgradeActivityEventMessage({
+  event,
+}: Readonly<SqUpgradeActivityEventMessageProps>) {
+  return (
+    <FlagMessage className="sw-my-1" id={event.key} variant="info">
+      <FormattedMessage
+        id="event.sqUpgrade"
+        values={{
+          sqVersion: event.name,
+        }}
+      />
+    </FlagMessage>
+  );
+}
index 3fe3361a4784d7ab2659cc85b5aa095abf5341aa..b0d2ed1eae9e02e1bd7e22690c3717356b7b99a3 100644 (file)
@@ -55,6 +55,8 @@ const ui = {
   stillFailingTxt: byText('event.quality_gate.still_x'),
 
   versionLabel: byText('event.category.VERSION', { exact: false }),
+
+  sqUpgradeLabel: (sqVersion: string) => byText(`event.sqUpgrade${sqVersion}`),
 };
 
 const handler = new BranchesServiceMock();
@@ -236,6 +238,19 @@ describe('VERSION events', () => {
   });
 });
 
+describe('SQ_UPGRADE events', () => {
+  it('should render correctly', () => {
+    renderEventInner({
+      event: mockAnalysisEvent({
+        category: ProjectAnalysisEventCategory.SqUpgrade,
+        name: '10.0',
+      }),
+    });
+
+    expect(ui.sqUpgradeLabel('10.0').get()).toBeInTheDocument();
+  });
+});
+
 function renderEventInner(props: Partial<EventInnerProps> = {}, params?: string) {
   return renderAppWithComponentContext(
     '/',
index 004c97ef0d9fe122d4abbf5ea96a7fd50787898c..cd7686dcd0b5590cd922c8886fc12d2729546d16 100644 (file)
@@ -520,6 +520,7 @@ event.category.All=All
 event.category.VERSION=Version
 event.category.QUALITY_GATE=Quality Gate
 event.category.QUALITY_PROFILE=Quality Profile
+event.category.SQ_UPGRADE=SonarQube upgrade
 event.category.DEFINITION_CHANGE=Definition Change
 event.category.ISSUE_DETECTION=Issue Detection
 event.category.OTHER=Other