From: Mathieu Suen Date: Fri, 23 Sep 2022 13:01:32 +0000 (+0200) Subject: SONAR-17096 Improve announcement order and description X-Git-Tag: 9.7.0.61563~153 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e5af59abec703dc1ba1049c7a0d33399a2bbd46f;p=sonarqube.git SONAR-17096 Improve announcement order and description --- 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 { 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(); + return renderComponent( + + + + ); } 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 = { diff --git a/sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java b/sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java index 397314d3c17..5756ba63d6d 100644 --- a/sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java +++ b/sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java @@ -42,10 +42,6 @@ public class CorePropertyDefinitions { public static final String DISABLE_NOTIFICATION_ON_BUILT_IN_QPROFILES = "sonar.builtInQualityProfiles.disableNotificationOnUpdate"; - public static final String SUB_SYSTEM_ANNOUNCEMENT = "announcement"; - public static final String SYSTEM_ANNOUNCEMENT_MESSAGE = "sonar.systemAnnouncement.message"; - public static final String SYSTEM_ANNOUNCEMENT_DISPLAY_MESSAGE = "sonar.systemAnnouncement.displayMessage"; - public static final String PLUGINS_RISK_CONSENT = "sonar.plugins.risk.consent"; private CorePropertyDefinitions() { @@ -92,22 +88,6 @@ public class CorePropertyDefinitions { .defaultValue(String.valueOf(false)) .hidden() .build(), - PropertyDefinition.builder(SYSTEM_ANNOUNCEMENT_MESSAGE) - .name("System announcement message") - .description("If \"Display system announcement message\" is set to True, this message will be displayed in a warning banner to all SonarQube users." - +" If this field is empty, no message will be displayed, even if \"Display system announcement message\" is set to True.") - .category(CoreProperties.CATEGORY_GENERAL) - .subCategory(SUB_SYSTEM_ANNOUNCEMENT) - .type(TEXT) - .build(), - PropertyDefinition.builder(SYSTEM_ANNOUNCEMENT_DISPLAY_MESSAGE) - .name("Display system announcement message") - .description("If set to True, the \"System announcement message\" will be displayed in a warning banner to all SonarQube users.") - .defaultValue(Boolean.toString(false)) - .subCategory(SUB_SYSTEM_ANNOUNCEMENT) - .category(CoreProperties.CATEGORY_GENERAL) - .type(BOOLEAN) - .build(), PropertyDefinition.builder(DISABLE_NOTIFICATION_ON_BUILT_IN_QPROFILES) .name("Avoid quality profiles notification") .description("Avoid sending email notification on each update of built-in quality profiles to quality profile administrators.") diff --git a/sonar-core/src/test/java/org/sonar/core/config/CorePropertyDefinitionsTest.java b/sonar-core/src/test/java/org/sonar/core/config/CorePropertyDefinitionsTest.java index ed3f949f563..00d1068c7a3 100644 --- a/sonar-core/src/test/java/org/sonar/core/config/CorePropertyDefinitionsTest.java +++ b/sonar-core/src/test/java/org/sonar/core/config/CorePropertyDefinitionsTest.java @@ -30,7 +30,7 @@ public class CorePropertyDefinitionsTest { @Test public void all() { List defs = CorePropertyDefinitions.all(); - assertThat(defs).hasSize(54); + assertThat(defs).hasSize(52); } @Test