]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-22017 Active version is also based on current EOL
authorIsmail Cherri <ismail.cherri@sonarsource.com>
Tue, 9 Apr 2024 07:04:23 +0000 (09:04 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 10 Apr 2024 20:02:56 +0000 (20:02 +0000)
server/sonar-web/src/main/js/app/components/__tests__/GlobalFooter-test.tsx
server/sonar-web/src/main/js/app/components/app-state/AppStateContext.tsx
server/sonar-web/src/main/js/components/shared/AppVersionStatus.tsx
server/sonar-web/src/main/js/helpers/system.ts
server/sonar-web/src/main/js/helpers/testMocks.ts
server/sonar-web/src/main/js/types/appstate.ts

index 4c0503d5c2d79981ab67aac2a9a2604a0279fef9..cc174d6ee814950d5018c6a81fb71fb528e046bf 100644 (file)
@@ -17,6 +17,7 @@
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
+import { addDays, subDays } from 'date-fns';
 import * as React from 'react';
 import SystemServiceMock from '../../../api/mocks/SystemServiceMock';
 import { mockAppState } from '../../../helpers/testMocks';
@@ -54,12 +55,24 @@ it('should render the inactive version and cleanup build number', async () => {
   expect(await ui.ltaDocumentationLinkInactive.find()).toBeInTheDocument();
 });
 
-it('should active status if undefined', () => {
+it('should show active status if offline and did not reach EOL', async () => {
   systemMock.setSystemUpgrades({ installedVersionActive: undefined });
-  renderGlobalFooter({}, { version: '4.2 (build 12345)' });
+  renderGlobalFooter(
+    {},
+    { version: '4.2 (build 12345)', installedVersionEOL: addDays(new Date(), 10).toISOString() },
+  );
+
+  expect(await ui.ltaDocumentationLinkActive.find()).toBeInTheDocument();
+});
 
-  expect(ui.ltaDocumentationLinkInactive.query()).not.toBeInTheDocument();
-  expect(ui.ltaDocumentationLinkActive.query()).not.toBeInTheDocument();
+it('should show inactive status if offline and reached EOL', async () => {
+  systemMock.setSystemUpgrades({ installedVersionActive: undefined });
+  renderGlobalFooter(
+    {},
+    { version: '4.2 (build 12345)', installedVersionEOL: subDays(new Date(), 10).toISOString() },
+  );
+
+  expect(await ui.ltaDocumentationLinkInactive.find()).toBeInTheDocument();
 });
 
 it('should not render missing logged-in information', () => {
index a679b8d05acdde1b6fa89dbc3d6769e36eed75eb..bfd1538af22846ef949c7d53b152627b0b207c99 100644 (file)
@@ -21,6 +21,7 @@ import * as React from 'react';
 import { AppState } from '../../../types/appstate';
 
 export const DEFAULT_APP_STATE = {
+  installedVersionEOL: '',
   authenticationError: false,
   authorizationError: false,
   edition: undefined,
index 99a26e972e09f383026a3ca3e98a116aa46aa69c..7fe3277d0e030a932b8a28a5ef7321fcdb055002 100644 (file)
  */
 
 import { LinkHighlight, LinkStandalone } from '@sonarsource/echoes-react';
-import React from 'react';
+import React, { useMemo } from 'react';
 import { FormattedMessage, useIntl } from 'react-intl';
 import { useAppState } from '../../app/components/app-state/withAppStateContext';
 import { useDocUrl } from '../../helpers/docs';
 import { getInstanceVersionNumber } from '../../helpers/strings';
+import { isCurrentVersionEOLActive } from '../../helpers/system';
 import { useSystemUpgrades } from '../../queries/system';
 
 export default function AppVersionStatus() {
   const { data } = useSystemUpgrades();
-  const { version } = useAppState();
+  const { version, installedVersionEOL } = useAppState();
+
+  const isActiveVersion = useMemo(() => {
+    if (data?.installedVersionActive !== undefined) {
+      return data.installedVersionActive;
+    }
+
+    return isCurrentVersionEOLActive(installedVersionEOL);
+  }, [data?.installedVersionActive, installedVersionEOL]);
 
   const docUrl = useDocUrl();
   const intl = useIntl();
@@ -37,20 +46,17 @@ export default function AppVersionStatus() {
     { id: `footer.version` },
     {
       version: getInstanceVersionNumber(version),
-      status:
-        data?.installedVersionActive !== undefined ? (
-          <LinkStandalone
-            className="sw-ml-1"
-            highlight={LinkHighlight.CurrentColor}
-            to={docUrl('/setup-and-upgrade/upgrade-the-server/active-versions/')}
-          >
-            <FormattedMessage
-              id={`footer.version.status.${data.installedVersionActive ? 'active' : 'inactive'}`}
-            />
-          </LinkStandalone>
-        ) : (
-          ''
-        ),
-    },
+      status: (
+        <LinkStandalone
+          className="sw-ml-1"
+          highlight={LinkHighlight.CurrentColor}
+          to={docUrl('/setup-and-upgrade/upgrade-the-server/active-versions/')}
+        >
+          <FormattedMessage
+            id={`footer.version.status.${isActiveVersion ? 'active' : 'inactive'}`}
+          />
+        </LinkStandalone>
+      ),
+    }
   );
 }
index 730beed41cbb8f847f8a255054ac1226e874db01..1503850fe67ce22e979e72546454798c66141aa5 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 { isAfter } from 'date-fns';
 import { AppVariablesElement } from '../types/browser';
 import { getEnhancedWindow } from './browser';
+import { parseDate } from './dates';
 
 export function getBaseUrl() {
   return getEnhancedWindow().baseUrl;
@@ -53,3 +55,7 @@ export function initAppVariables() {
   getEnhancedWindow().instance = appVariablesDiv.dataset.instance;
   getEnhancedWindow().official = Boolean(appVariablesDiv.dataset.official);
 }
+
+export function isCurrentVersionEOLActive(installedVersionEOL: string) {
+  return isAfter(parseDate(installedVersionEOL), new Date());
+}
index 0ef2c641c7c6975a5ada365b58382b7aea680d5e..1ea0bc60e69ec0def05b48ae7585984a78e04272 100644 (file)
@@ -33,6 +33,7 @@ import {
   SoftwareQuality,
 } from '../types/clean-code-taxonomy';
 import { RuleRepository } from '../types/coding-rules';
+import { ComponentQualifier } from '../types/component';
 import { EditionKey } from '../types/editions';
 import {
   IssueDeprecatedStatus,
@@ -90,10 +91,11 @@ export function mockAppState(overrides: Partial<AppState> = {}): AppState {
   return {
     edition: EditionKey.community,
     productionDatabase: true,
-    qualifiers: ['TRK'],
+    qualifiers: [ComponentQualifier.Project],
     settings: {},
     version: '1.0',
     documentationUrl: 'https://docs.sonarsource.com/sonarqube/10.0',
+    installedVersionEOL: '2024-01-01T00:00:00Z',
     ...overrides,
   };
 }
index 00e5c67e082e34713c524ae5dc4d9a19a1fa45e2..f9bac3f35fddd456e3ce25927ef33b78afdcd863 100644 (file)
@@ -28,6 +28,7 @@ export interface AppState {
   edition?: EditionKey;
   globalPages?: Extension[];
   instanceUsesDefaultAdminCredentials?: boolean;
+  installedVersionEOL: string;
   needIssueSync?: boolean;
   productionDatabase: boolean;
   qualifiers: string[];