From f5dd75ab4b842eb2a5280411cfaceb0c09eea57d Mon Sep 17 00:00:00 2001 From: stanislavh Date: Tue, 9 Apr 2024 11:18:48 +0200 Subject: [PATCH] SONAR-22018 Introduce active version link in footer and system apge --- .../main/js/app/components/GlobalFooter.tsx | 19 +++---- .../__snapshots__/GlobalFooter-test.tsx.snap | 40 +++++++-------- .../components/app-state/AppStateContext.tsx | 1 + .../AppStateContextProvider-test.tsx.snap | 1 + .../app-state/withAppStateContext.tsx | 4 ++ .../__snapshots__/Extension-test.tsx.snap | 2 + .../IndexationContextProvider-test.tsx.snap | 1 + .../js/apps/system/components/PageHeader.tsx | 5 +- .../__snapshots__/PageHeader-test.tsx.snap | 4 +- .../js/components/shared/AppVersionStatus.tsx | 48 ++++++++++++++++++ .../__tests__/AppVersionStatus-test.tsx | 50 +++++++++++++++++++ .../src/main/js/helpers/testMocks.ts | 1 + .../sonar-web/src/main/js/types/appstate.ts | 1 + .../resources/org/sonar/l10n/core.properties | 4 +- 14 files changed, 148 insertions(+), 33 deletions(-) create mode 100644 server/sonar-web/src/main/js/components/shared/AppVersionStatus.tsx create mode 100644 server/sonar-web/src/main/js/components/shared/__tests__/AppVersionStatus-test.tsx diff --git a/server/sonar-web/src/main/js/app/components/GlobalFooter.tsx b/server/sonar-web/src/main/js/app/components/GlobalFooter.tsx index 20c452b06ba..e11b18e6292 100644 --- a/server/sonar-web/src/main/js/app/components/GlobalFooter.tsx +++ b/server/sonar-web/src/main/js/app/components/GlobalFooter.tsx @@ -21,12 +21,13 @@ import * as React from 'react'; import DocLink from '../../components/common/DocLink'; import InstanceMessage from '../../components/common/InstanceMessage'; import Link from '../../components/common/Link'; +import AppVersionStatus from '../../components/shared/AppVersionStatus'; import { Alert } from '../../components/ui/Alert'; import { getEdition } from '../../helpers/editions'; -import { translate, translateWithParameters } from '../../helpers/l10n'; +import { translate } from '../../helpers/l10n'; import { AppState } from '../../types/appstate'; -import withAppStateContext from './app-state/withAppStateContext'; import GlobalFooterBranding from './GlobalFooterBranding'; +import withAppStateContext from './app-state/withAppStateContext'; export interface GlobalFooterProps { hideLoggedInInfo?: boolean; @@ -55,26 +56,26 @@ export function GlobalFooter({ hideLoggedInInfo, appState }: GlobalFooterProps) )} {!hideLoggedInInfo && appState?.version && (
  • - {translateWithParameters('footer.version_x', appState.version)} +
  • )}
  • - {translate('footer.license')} - +
  • - {translate('footer.community')} - +
  • {translate('footer.documentation')} diff --git a/server/sonar-web/src/main/js/app/components/__tests__/__snapshots__/GlobalFooter-test.tsx.snap b/server/sonar-web/src/main/js/app/components/__tests__/__snapshots__/GlobalFooter-test.tsx.snap index 492e71658d2..05208a8b2a1 100644 --- a/server/sonar-web/src/main/js/app/components/__tests__/__snapshots__/GlobalFooter-test.tsx.snap +++ b/server/sonar-web/src/main/js/app/components/__tests__/__snapshots__/GlobalFooter-test.tsx.snap @@ -17,29 +17,29 @@ exports[`should display the sq version 1`] = `
  • - footer.version_x.6.4-SNAPSHOT +
  • - footer.license - +
  • - footer.community - +
  • - footer.license - +
  • - footer.community - +
  • - footer.version_x.1.0 +
  • - footer.license - +
  • - footer.community - +
  • (DEFAULT_APP_STATE); diff --git a/server/sonar-web/src/main/js/app/components/app-state/__tests__/__snapshots__/AppStateContextProvider-test.tsx.snap b/server/sonar-web/src/main/js/app/components/app-state/__tests__/__snapshots__/AppStateContextProvider-test.tsx.snap index dbdc02fa1c4..59a0d40fa40 100644 --- a/server/sonar-web/src/main/js/app/components/app-state/__tests__/__snapshots__/AppStateContextProvider-test.tsx.snap +++ b/server/sonar-web/src/main/js/app/components/app-state/__tests__/__snapshots__/AppStateContextProvider-test.tsx.snap @@ -13,6 +13,7 @@ exports[`should set value correctly 1`] = ` "sonar.lf.logoUrl": "whatevs/", }, "version": "1.0", + "versionEOL": "2022-01-01", } } /> diff --git a/server/sonar-web/src/main/js/app/components/app-state/withAppStateContext.tsx b/server/sonar-web/src/main/js/app/components/app-state/withAppStateContext.tsx index 8b42de90487..5a7be0e1a21 100644 --- a/server/sonar-web/src/main/js/app/components/app-state/withAppStateContext.tsx +++ b/server/sonar-web/src/main/js/app/components/app-state/withAppStateContext.tsx @@ -43,3 +43,7 @@ export default function withAppStateContext

    ( } }; } + +export function useAppState() { + return React.useContext(AppStateContext); +} diff --git a/server/sonar-web/src/main/js/app/components/extensions/__tests__/__snapshots__/Extension-test.tsx.snap b/server/sonar-web/src/main/js/app/components/extensions/__tests__/__snapshots__/Extension-test.tsx.snap index 2aece96de23..32b49f0abe2 100644 --- a/server/sonar-web/src/main/js/app/components/extensions/__tests__/__snapshots__/Extension-test.tsx.snap +++ b/server/sonar-web/src/main/js/app/components/extensions/__tests__/__snapshots__/Extension-test.tsx.snap @@ -11,6 +11,7 @@ exports[`should render React extensions correctly 1`] = ` ], "settings": {}, "version": "1.0", + "versionEOL": "2022-01-01", } } currentUser={ @@ -73,6 +74,7 @@ exports[`should render React extensions correctly 2`] = ` ], "settings": {}, "version": "1.0", + "versionEOL": "2022-01-01", } } currentUser={ diff --git a/server/sonar-web/src/main/js/app/components/indexation/__tests__/__snapshots__/IndexationContextProvider-test.tsx.snap b/server/sonar-web/src/main/js/app/components/indexation/__tests__/__snapshots__/IndexationContextProvider-test.tsx.snap index b2fda45425a..641e0b9a63e 100644 --- a/server/sonar-web/src/main/js/app/components/indexation/__tests__/__snapshots__/IndexationContextProvider-test.tsx.snap +++ b/server/sonar-web/src/main/js/app/components/indexation/__tests__/__snapshots__/IndexationContextProvider-test.tsx.snap @@ -12,6 +12,7 @@ exports[`should render correctly and start polling if issue sync is needed 1`] = ], "settings": {}, "version": "1.0", + "versionEOL": "2022-01-01", } } > diff --git a/server/sonar-web/src/main/js/apps/system/components/PageHeader.tsx b/server/sonar-web/src/main/js/apps/system/components/PageHeader.tsx index e6b768af8e7..4ebabc0abb1 100644 --- a/server/sonar-web/src/main/js/apps/system/components/PageHeader.tsx +++ b/server/sonar-web/src/main/js/apps/system/components/PageHeader.tsx @@ -20,6 +20,7 @@ import * as React from 'react'; import withAppStateContext from '../../../app/components/app-state/withAppStateContext'; import { ClipboardButton } from '../../../components/controls/clipboard'; +import AppVersionStatus from '../../../components/shared/AppVersionStatus'; import { Alert } from '../../../components/ui/Alert'; import { toShortNotSoISOString } from '../../../helpers/dates'; import { translate } from '../../../helpers/l10n'; @@ -79,7 +80,9 @@ export function PageHeader(props: Props) { {translate('system.version')} - {version} + + + diff --git a/server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/PageHeader-test.tsx.snap b/server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/PageHeader-test.tsx.snap index c8ef70f9e61..cad0c680de6 100644 --- a/server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/PageHeader-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/PageHeader-test.tsx.snap @@ -85,7 +85,7 @@ exports[`should render correctly 3`] = ` - 7.7.0.1234 + @@ -160,7 +160,7 @@ exports[`should render correctly: on embedded database 1`] = ` - 7.7.0.1234 + diff --git a/server/sonar-web/src/main/js/components/shared/AppVersionStatus.tsx b/server/sonar-web/src/main/js/components/shared/AppVersionStatus.tsx new file mode 100644 index 00000000000..91e961695e7 --- /dev/null +++ b/server/sonar-web/src/main/js/components/shared/AppVersionStatus.tsx @@ -0,0 +1,48 @@ +/* + * SonarQube + * Copyright (C) 2009-2024 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 * as React from 'react'; +import { FormattedMessage } from 'react-intl'; +import { useAppState } from '../../app/components/app-state/withAppStateContext'; +import { now, parseDate } from '../../helpers/dates'; +import { translate } from '../../helpers/l10n'; +import DocLink from '../common/DocLink'; + +export default function AppVersionStatus() { + const { version, versionEOL } = useAppState(); + const isActive = parseDate(versionEOL) > now(); + + return ( + + {translate(`footer.version.status.${isActive ? 'active' : 'inactive'}`)} + + ), + }} + /> + ); +} diff --git a/server/sonar-web/src/main/js/components/shared/__tests__/AppVersionStatus-test.tsx b/server/sonar-web/src/main/js/components/shared/__tests__/AppVersionStatus-test.tsx new file mode 100644 index 00000000000..f60dba440bb --- /dev/null +++ b/server/sonar-web/src/main/js/components/shared/__tests__/AppVersionStatus-test.tsx @@ -0,0 +1,50 @@ +/* + * SonarQube + * Copyright (C) 2009-2024 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 { screen } from '@testing-library/react'; +import React from 'react'; +import AppStateContextProvider from '../../../app/components/app-state/AppStateContextProvider'; +import AppVersionStatus from '../../../components/shared/AppVersionStatus'; +import { mockAppState } from '../../../helpers/testMocks'; +import { renderComponent } from '../../../helpers/testReactTestingUtils'; + +jest.mock('../../../helpers/dates', () => ({ + ...jest.requireActual('../../../helpers/dates'), + now: () => new Date('2022-01-01'), +})); + +it('should render active version if it has not reached EOL', () => { + renderAppVersionStatus(mockAppState({ versionEOL: '2022-01-02' })); + + expect(screen.getByRole('link', { name: /footer.version.status.active/ })).toBeInTheDocument(); +}); + +it('should render inactive version if it has reached EOL', () => { + renderAppVersionStatus(mockAppState({ versionEOL: '2021-12-30' })); + + expect(screen.getByRole('link', { name: /footer.version.status.inactive/ })).toBeInTheDocument(); +}); + +const renderAppVersionStatus = (appState = mockAppState()) => { + return renderComponent( + + + + ); +}; diff --git a/server/sonar-web/src/main/js/helpers/testMocks.ts b/server/sonar-web/src/main/js/helpers/testMocks.ts index efa1c1602a7..f08cc766963 100644 --- a/server/sonar-web/src/main/js/helpers/testMocks.ts +++ b/server/sonar-web/src/main/js/helpers/testMocks.ts @@ -76,6 +76,7 @@ export function mockAppState(overrides: Partial = {}): AppState { qualifiers: ['TRK'], settings: {}, version: '1.0', + versionEOL: '2022-01-01', ...overrides, }; } diff --git a/server/sonar-web/src/main/js/types/appstate.ts b/server/sonar-web/src/main/js/types/appstate.ts index 6d31f5b09e0..3701a3901a1 100644 --- a/server/sonar-web/src/main/js/types/appstate.ts +++ b/server/sonar-web/src/main/js/types/appstate.ts @@ -35,4 +35,5 @@ export interface AppState { standalone?: boolean; version: string; webAnalyticsJsPath?: string; + versionEOL: string; } 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 fabcfb1630c..30ceba145ea 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -3531,7 +3531,9 @@ footer.security=Security footer.status=Status footer.terms=Terms footer.twitter=Twitter -footer.version_x=Version {0} +footer.version=v{version}{status} +footer.version.status.active=ACTIVE +footer.version.status.inactive=NO LONGER ACTIVE footer.web_api=Web API -- 2.39.5