From: Ismail Cherri Date: Tue, 9 Apr 2024 07:04:23 +0000 (+0200) Subject: SONAR-22017 Active version is also based on current EOL X-Git-Tag: 10.5.0.89998~15 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0072c50e15384396032de42e12f95d7449c35c22;p=sonarqube.git SONAR-22017 Active version is also based on current EOL --- diff --git a/server/sonar-web/src/main/js/app/components/__tests__/GlobalFooter-test.tsx b/server/sonar-web/src/main/js/app/components/__tests__/GlobalFooter-test.tsx index 4c0503d5c2d..cc174d6ee81 100644 --- a/server/sonar-web/src/main/js/app/components/__tests__/GlobalFooter-test.tsx +++ b/server/sonar-web/src/main/js/app/components/__tests__/GlobalFooter-test.tsx @@ -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', () => { diff --git a/server/sonar-web/src/main/js/app/components/app-state/AppStateContext.tsx b/server/sonar-web/src/main/js/app/components/app-state/AppStateContext.tsx index a679b8d05ac..bfd1538af22 100644 --- a/server/sonar-web/src/main/js/app/components/app-state/AppStateContext.tsx +++ b/server/sonar-web/src/main/js/app/components/app-state/AppStateContext.tsx @@ -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, diff --git a/server/sonar-web/src/main/js/components/shared/AppVersionStatus.tsx b/server/sonar-web/src/main/js/components/shared/AppVersionStatus.tsx index 99a26e972e0..7fe3277d0e0 100644 --- a/server/sonar-web/src/main/js/components/shared/AppVersionStatus.tsx +++ b/server/sonar-web/src/main/js/components/shared/AppVersionStatus.tsx @@ -19,16 +19,25 @@ */ 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 ? ( - - - - ) : ( - '' - ), - }, + status: ( + + + + ), + } ); } diff --git a/server/sonar-web/src/main/js/helpers/system.ts b/server/sonar-web/src/main/js/helpers/system.ts index 730beed41cb..1503850fe67 100644 --- a/server/sonar-web/src/main/js/helpers/system.ts +++ b/server/sonar-web/src/main/js/helpers/system.ts @@ -17,8 +17,10 @@ * 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()); +} diff --git a/server/sonar-web/src/main/js/helpers/testMocks.ts b/server/sonar-web/src/main/js/helpers/testMocks.ts index 0ef2c641c7c..1ea0bc60e69 100644 --- a/server/sonar-web/src/main/js/helpers/testMocks.ts +++ b/server/sonar-web/src/main/js/helpers/testMocks.ts @@ -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 { 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, }; } diff --git a/server/sonar-web/src/main/js/types/appstate.ts b/server/sonar-web/src/main/js/types/appstate.ts index 00e5c67e082..f9bac3f35fd 100644 --- a/server/sonar-web/src/main/js/types/appstate.ts +++ b/server/sonar-web/src/main/js/types/appstate.ts @@ -28,6 +28,7 @@ export interface AppState { edition?: EditionKey; globalPages?: Extension[]; instanceUsesDefaultAdminCredentials?: boolean; + installedVersionEOL: string; needIssueSync?: boolean; productionDatabase: boolean; qualifiers: string[];