From: Mathieu Suen Date: Tue, 16 Nov 2021 11:05:12 +0000 (+0100) Subject: SONAR-15627 Make the system update prompt same as globle prompt X-Git-Tag: 9.2.0.49834~17 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f0adb953f003e974de835114c9e5c4391719cd2c;p=sonarqube.git SONAR-15627 Make the system update prompt same as globle prompt --- diff --git a/server/sonar-web/src/main/js/app/components/GlobalContainer.tsx b/server/sonar-web/src/main/js/app/components/GlobalContainer.tsx index 3ecf5816e69..485a716449d 100644 --- a/server/sonar-web/src/main/js/app/components/GlobalContainer.tsx +++ b/server/sonar-web/src/main/js/app/components/GlobalContainer.tsx @@ -27,8 +27,8 @@ import GlobalMessagesContainer from './GlobalMessagesContainer'; import IndexationContextProvider from './indexation/IndexationContextProvider'; import IndexationNotification from './indexation/IndexationNotification'; import GlobalNav from './nav/global/GlobalNav'; -import StartupModal from './StartupModal'; import PromotionNotification from './promotion-notification/PromotionNotification'; +import StartupModal from './StartupModal'; import UpdateNotification from './update-notification/UpdateNotification'; export interface Props { @@ -54,7 +54,7 @@ export default function GlobalContainer(props: Props) { - + {props.children} diff --git a/server/sonar-web/src/main/js/app/components/__tests__/__snapshots__/GlobalContainer-test.tsx.snap b/server/sonar-web/src/main/js/app/components/__tests__/__snapshots__/GlobalContainer-test.tsx.snap index 5f47fc1d4a2..107d16e2a17 100644 --- a/server/sonar-web/src/main/js/app/components/__tests__/__snapshots__/GlobalContainer-test.tsx.snap +++ b/server/sonar-web/src/main/js/app/components/__tests__/__snapshots__/GlobalContainer-test.tsx.snap @@ -32,7 +32,9 @@ exports[`should render correctly 1`] = ` /> - + diff --git a/server/sonar-web/src/main/js/app/components/update-notification/UpdateNotification.tsx b/server/sonar-web/src/main/js/app/components/update-notification/UpdateNotification.tsx index f7b188dcc85..e80c06fd3a2 100644 --- a/server/sonar-web/src/main/js/app/components/update-notification/UpdateNotification.tsx +++ b/server/sonar-web/src/main/js/app/components/update-notification/UpdateNotification.tsx @@ -23,7 +23,7 @@ import * as React from 'react'; import { getSystemUpgrades } from '../../../api/system'; import { withAppState } from '../../../components/hoc/withAppState'; import { withCurrentUser } from '../../../components/hoc/withCurrentUser'; -import { AlertVariant } from '../../../components/ui/Alert'; +import { Alert, AlertVariant } from '../../../components/ui/Alert'; import DismissableAlert from '../../../components/ui/DismissableAlert'; import SystemUpgradeButton from '../../../components/upgrade/SystemUpgradeButton'; import { sortUpgrades, UpdateUseCase } from '../../../components/upgrade/utils'; @@ -47,6 +47,7 @@ const MAP_VARIANT: T.Dict = { }; interface Props { + dismissable: boolean; appState: Pick; currentUser: T.CurrentUser; } @@ -218,11 +219,12 @@ export class UpdateNotification extends React.PureComponent { } render() { + const { dismissable } = this.props; const { latestLTS, systemUpgrades, canSeeNotification, useCase, dismissKey } = this.state; if (!canSeeNotification) { return null; } - return ( + return dismissable ? ( { latestLTS={latestLTS} /> + ) : ( + + {translate('admin_notification.update', useCase)} + + ); } } diff --git a/server/sonar-web/src/main/js/app/components/update-notification/__tests__/UpdateNotification-test.tsx b/server/sonar-web/src/main/js/app/components/update-notification/__tests__/UpdateNotification-test.tsx index e6f9a7b7404..b99a923dd6b 100644 --- a/server/sonar-web/src/main/js/app/components/update-notification/__tests__/UpdateNotification-test.tsx +++ b/server/sonar-web/src/main/js/app/components/update-notification/__tests__/UpdateNotification-test.tsx @@ -20,6 +20,7 @@ import { shallow } from 'enzyme'; import * as React from 'react'; import { getSystemUpgrades } from '../../../../api/system'; +import { Alert } from '../../../../components/ui/Alert'; import DismissableAlert from '../../../../components/ui/DismissableAlert'; import { mockUpgrades } from '../../../../helpers/mocks/system-upgrades'; import { mockAppState, mockCurrentUser, mockLoggedInUser } from '../../../../helpers/testMocks'; @@ -158,8 +159,32 @@ it('should show prompt when lts upgrade is more than 6 month', async () => { expect(wrapper.contains('admin_notification.update.previous_lts')).toBe(true); }); +it('should show correct alert when not dismissable', async () => { + (getSystemUpgrades as jest.Mock).mockResolvedValueOnce({ + upgrades: [ + mockUpgrades({ version: '8.9', releaseDate: formatDate(new Date(Date.now())) }), + mockUpgrades({ version: '9.2' }), + mockUpgrades({ version: '9.1.1' }) + ], + latestLTS: '8.9' + }); + const wrapper = shallowRender({ + appState: mockAppState({ version: '8.8' }), + currentUser: mockLoggedInUser({ permissions: { global: [Permissions.Admin] } }) + }); + await waitAndUpdate(wrapper); + expect(wrapper.find(DismissableAlert).type).toBeDefined(); + wrapper.setProps({ dismissable: false }); + expect(wrapper.find(Alert).type).toBeDefined(); +}); + function shallowRender(props: Partial = {}) { return shallow( - + ); } diff --git a/server/sonar-web/src/main/js/apps/system/components/App.tsx b/server/sonar-web/src/main/js/apps/system/components/App.tsx index 6df2047788c..7e5cdc02608 100644 --- a/server/sonar-web/src/main/js/apps/system/components/App.tsx +++ b/server/sonar-web/src/main/js/apps/system/components/App.tsx @@ -22,6 +22,7 @@ import { Helmet } from 'react-helmet-async'; import { withRouter, WithRouterProps } from 'react-router'; import { getSystemInfo } from '../../../api/system'; import Suggestions from '../../../app/components/embed-docs-modal/Suggestions'; +import UpdateNotification from '../../../app/components/update-notification/UpdateNotification'; import { translate } from '../../../helpers/l10n'; import '../styles.css'; import { @@ -37,7 +38,6 @@ import { import ClusterSysInfos from './ClusterSysInfos'; import PageHeader from './PageHeader'; import StandaloneSysInfos from './StandaloneSysInfos'; -import SystemUpgradeNotif from './system-upgrade/SystemUpgradeNotif'; type Props = WithRouterProps; @@ -122,7 +122,9 @@ export class App extends React.PureComponent {
- +
+ +
{sysInfoData && ( - +
+ +
- +
+ +
`; @@ -214,7 +226,13 @@ exports[`should render correctly: stand-alone sysinfo 1`] = ` encodeSpecialCharacters={true} title="system_info.page" /> - +
+ +
{ - mounted = false; - state: State = { systemUpgrades: [], latestLTS: '' }; - - componentDidMount() { - this.mounted = true; - this.fetchSystemUpgrade(); - } - - componentWillUnmount() { - this.mounted = false; - } - - fetchSystemUpgrade = () => - getSystemUpgrades().then( - ({ upgrades, latestLTS }) => { - if (this.mounted) { - this.setState({ latestLTS, systemUpgrades: upgrades }); - } - }, - () => {} - ); - - render() { - const { systemUpgrades, latestLTS } = this.state; - - if (systemUpgrades.length <= 0) { - return null; - } - - return ( -
- - {translate('system.new_version_available')} - - -
- ); - } -} diff --git a/server/sonar-web/src/main/js/apps/system/components/system-upgrade/__tests__/SystemUpgradeNotif-test.tsx b/server/sonar-web/src/main/js/apps/system/components/system-upgrade/__tests__/SystemUpgradeNotif-test.tsx deleted file mode 100644 index 61673af52a2..00000000000 --- a/server/sonar-web/src/main/js/apps/system/components/system-upgrade/__tests__/SystemUpgradeNotif-test.tsx +++ /dev/null @@ -1,100 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2021 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 { shallow } from 'enzyme'; -import * as React from 'react'; -import { getSystemUpgrades } from '../../../../../api/system'; -import { waitAndUpdate } from '../../../../../helpers/testUtils'; -import SystemUpgradeNotif from '../SystemUpgradeNotif'; - -jest.mock('../../../../../api/system', () => ({ - getSystemUpgrades: jest.fn(() => - Promise.resolve({ - updateCenterRefresh: '', - upgrades: [ - { - version: '5.6.7', - description: 'Version 5.6.7 description', - releaseDate: '2017-03-01', - changeLogUrl: 'changelogurl', - downloadUrl: 'downloadurl', - plugins: {} - }, - { - version: '5.6.5', - description: 'Version 5.6.5 description', - releaseDate: '2017-03-01', - changeLogUrl: 'changelogurl', - downloadUrl: 'downloadurl', - plugins: {} - }, - { - version: '6.3', - description: 'Version 6.3 description', - releaseDate: '2017-05-02', - changeLogUrl: 'changelogurl', - downloadUrl: 'downloadurl', - plugins: {} - }, - { - version: '5.6.6', - description: 'Version 5.6.6 description', - releaseDate: '2017-04-02', - changeLogUrl: 'changelogurl', - downloadUrl: 'downloadurl', - plugins: {} - }, - { - version: '6.4', - description: 'Version 6.4 description', - releaseDate: '2017-06-02', - changeLogUrl: 'changelogurl', - downloadUrl: 'downloadurl', - plugins: {} - } - ] - }) - ) -})); - -beforeEach(() => { - jest.clearAllMocks(); -}); - -it('should render correctly', async () => { - const wrapper = shallowRender(); - await waitAndUpdate(wrapper); - expect(getSystemUpgrades).toHaveBeenCalled(); - - expect(wrapper).toMatchSnapshot(); -}); - -it('should display nothing', async () => { - (getSystemUpgrades as jest.Mock).mockImplementationOnce(() => { - return Promise.resolve({ updateCenterRefresh: '', upgrades: [] }); - }); - const wrapper = shallowRender(); - await waitAndUpdate(wrapper); - - expect(wrapper.type()).toBeNull(); -}); - -function shallowRender() { - return shallow(); -} diff --git a/server/sonar-web/src/main/js/apps/system/components/system-upgrade/__tests__/__snapshots__/SystemUpgradeNotif-test.tsx.snap b/server/sonar-web/src/main/js/apps/system/components/system-upgrade/__tests__/__snapshots__/SystemUpgradeNotif-test.tsx.snap deleted file mode 100644 index 3e3d05a2f7b..00000000000 --- a/server/sonar-web/src/main/js/apps/system/components/system-upgrade/__tests__/__snapshots__/SystemUpgradeNotif-test.tsx.snap +++ /dev/null @@ -1,59 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly 1`] = ` -
- - system.new_version_available - - -
-`;