diff options
author | Mathieu Suen <mathieu.suen@sonarsource.com> | 2022-09-23 15:01:32 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-09-28 20:04:08 +0000 |
commit | e5af59abec703dc1ba1049c7a0d33399a2bbd46f (patch) | |
tree | ee25331c3b9e11868fbe2a333760018d5100166e /server/sonar-web | |
parent | 98aa88962583e2e8f59a5dd110aaa980282e6fe5 (diff) | |
download | sonarqube-e5af59abec703dc1ba1049c7a0d33399a2bbd46f.tar.gz sonarqube-e5af59abec703dc1ba1049c7a0d33399a2bbd46f.zip |
SONAR-17096 Improve announcement order and description
Diffstat (limited to 'server/sonar-web')
4 files changed, 36 insertions, 19 deletions
diff --git a/server/sonar-web/src/main/js/app/components/SystemAnnouncement.tsx b/server/sonar-web/src/main/js/app/components/SystemAnnouncement.tsx index dd0abf833ea..89e23b08ce6 100644 --- a/server/sonar-web/src/main/js/app/components/SystemAnnouncement.tsx +++ b/server/sonar-web/src/main/js/app/components/SystemAnnouncement.tsx @@ -22,7 +22,11 @@ import { isEmpty, keyBy } from 'lodash'; import * as React from 'react'; import { getValues } from '../../api/settings'; import { Alert } from '../../components/ui/Alert'; +import { Feature } from '../../types/features'; import { GlobalSettingKeys, SettingValue } from '../../types/settings'; +import withAvailableFeatures, { + WithAvailableFeaturesProps +} from './available-features/withAvailableFeatures'; import './SystemAnnouncement.css'; interface State { @@ -30,29 +34,33 @@ interface State { message: string; } -export default class SystemAnnouncement extends React.PureComponent<{}, State> { +export class SystemAnnouncement extends React.PureComponent<WithAvailableFeaturesProps, State> { state: State = { displayMessage: false, message: '' }; componentDidMount() { - this.getSettings(); - document.addEventListener('visibilitychange', this.handleVisibilityChange); + if (this.props.hasFeature(Feature.Announcement)) { + this.getSettings(); + document.addEventListener('visibilitychange', this.handleVisibilityChange); + } } componentWillUnmount() { - document.removeEventListener('visibilitychange', this.handleVisibilityChange); + if (this.props.hasFeature(Feature.Announcement)) { + document.removeEventListener('visibilitychange', this.handleVisibilityChange); + } } getSettings = async () => { const values: SettingValue[] = await getValues({ - keys: [GlobalSettingKeys.DisplaySystemMessage, GlobalSettingKeys.SystemMessage] + keys: [GlobalSettingKeys.DisplayAnnouncementMessage, GlobalSettingKeys.AnnouncementMessage] }); const settings = keyBy(values, 'key'); this.setState({ - displayMessage: settings[GlobalSettingKeys.DisplaySystemMessage].value === 'true', + displayMessage: settings[GlobalSettingKeys.DisplayAnnouncementMessage].value === 'true', message: - (settings[GlobalSettingKeys.SystemMessage] && - settings[GlobalSettingKeys.SystemMessage].value) || + (settings[GlobalSettingKeys.AnnouncementMessage] && + settings[GlobalSettingKeys.AnnouncementMessage].value) || '' }); }; @@ -82,3 +90,5 @@ export default class SystemAnnouncement extends React.PureComponent<{}, State> { ); } } + +export default withAvailableFeatures(SystemAnnouncement); diff --git a/server/sonar-web/src/main/js/app/components/__tests__/SystemAnnouncement-test.tsx b/server/sonar-web/src/main/js/app/components/__tests__/SystemAnnouncement-test.tsx index cc837ef72d0..1b44b1a34bb 100644 --- a/server/sonar-web/src/main/js/app/components/__tests__/SystemAnnouncement-test.tsx +++ b/server/sonar-web/src/main/js/app/components/__tests__/SystemAnnouncement-test.tsx @@ -21,6 +21,8 @@ import { fireEvent, screen } from '@testing-library/dom'; import * as React from 'react'; import { getValues } from '../../../api/settings'; import { renderComponent } from '../../../helpers/testReactTestingUtils'; +import { Feature } from '../../../types/features'; +import { AvailableFeaturesContext } from '../available-features/AvailableFeaturesContext'; import SystemAnnouncement from '../SystemAnnouncement'; jest.mock('../../../api/settings', () => ({ @@ -31,41 +33,41 @@ it('should display system announcement', async () => { (getValues as jest.Mock) .mockResolvedValueOnce([ { - key: 'sonar.systemAnnouncement.displayMessage', + key: 'sonar.announcement.displayMessage', value: 'false', inherited: true } ]) .mockResolvedValueOnce([ { - key: 'sonar.systemAnnouncement.displayMessage', + key: 'sonar.announcement.displayMessage', value: 'false', inherited: true } ]) .mockResolvedValueOnce([ { - key: 'sonar.systemAnnouncement.displayMessage', + key: 'sonar.announcement.displayMessage', value: 'true' } ]) .mockResolvedValueOnce([ { - key: 'sonar.systemAnnouncement.displayMessage', + key: 'sonar.announcement.displayMessage', value: 'true' }, { - key: 'sonar.systemAnnouncement.message', + key: 'sonar.announcement.message', value: '' } ]) .mockResolvedValueOnce([ { - key: 'sonar.systemAnnouncement.displayMessage', + key: 'sonar.announcement.displayMessage', value: 'true' }, { - key: 'sonar.systemAnnouncement.message', + key: 'sonar.announcement.message', value: 'Foo' } ]); @@ -85,5 +87,9 @@ it('should display system announcement', async () => { }); function renderSystemAnnouncement() { - return renderComponent(<SystemAnnouncement />); + return renderComponent( + <AvailableFeaturesContext.Provider value={[Feature.Announcement]}> + <SystemAnnouncement /> + </AvailableFeaturesContext.Provider> + ); } diff --git a/server/sonar-web/src/main/js/types/features.ts b/server/sonar-web/src/main/js/types/features.ts index 768e51e41ca..10efdac37de 100644 --- a/server/sonar-web/src/main/js/types/features.ts +++ b/server/sonar-web/src/main/js/types/features.ts @@ -22,5 +22,6 @@ export enum Feature { MonoRepositoryPullRequestDecoration = 'monorepo', RegulatoryReport = 'regulatory-reports', ProjectImport = 'project-import', - MultipleAlm = 'multiple-alm' + MultipleAlm = 'multiple-alm', + Announcement = 'announcement' } diff --git a/server/sonar-web/src/main/js/types/settings.ts b/server/sonar-web/src/main/js/types/settings.ts index 079c23e8b6c..9e9a3946ef6 100644 --- a/server/sonar-web/src/main/js/types/settings.ts +++ b/server/sonar-web/src/main/js/types/settings.ts @@ -37,8 +37,8 @@ export enum GlobalSettingKeys { RatingGrid = 'sonar.technicalDebt.ratingGrid', DeveloperAggregatedInfoDisabled = 'sonar.developerAggregatedInfo.disabled', UpdatecenterActivated = 'sonar.updatecenter.activate', - DisplaySystemMessage = 'sonar.systemAnnouncement.displayMessage', - SystemMessage = 'sonar.systemAnnouncement.message' + DisplayAnnouncementMessage = 'sonar.announcement.displayMessage', + AnnouncementMessage = 'sonar.announcement.message' } export type SettingDefinitionAndValue = { |