From: Matteo Mara Date: Thu, 22 Sep 2022 10:41:42 +0000 (+0200) Subject: SONAR-17116 migrate regulatory report trigger to /api/features/list X-Git-Tag: 9.7.0.61563~177 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=fab17558cadecd381e2c4ece16cef6ac688e98ee;p=sonarqube.git SONAR-17116 migrate regulatory report trigger to /api/features/list --- diff --git a/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/ProjectInformationRenderer.tsx b/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/ProjectInformationRenderer.tsx index 3d61193be3d..8402bd8e277 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/ProjectInformationRenderer.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/ProjectInformationRenderer.tsx @@ -18,12 +18,17 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import * as React from 'react'; +import PrivacyBadgeContainer from '../../../../../components/common/PrivacyBadgeContainer'; import { ButtonLink } from '../../../../../components/controls/buttons'; import ModalButton from '../../../../../components/controls/ModalButton'; -import PrivacyBadgeContainer from '../../../../../components/common/PrivacyBadgeContainer'; import { translate } from '../../../../../helpers/l10n'; +import { BranchLike } from '../../../../../types/branch-like'; import { ComponentQualifier } from '../../../../../types/component'; +import { Feature } from '../../../../../types/features'; import { Component, Measure } from '../../../../../types/types'; +import withAvailableFeatures, { + WithAvailableFeaturesProps +} from '../../../available-features/withAvailableFeatures'; import DrawerLink from './DrawerLink'; import MetaKey from './meta/MetaKey'; import MetaLinks from './meta/MetaLinks'; @@ -33,12 +38,8 @@ import MetaSize from './meta/MetaSize'; import MetaTags from './meta/MetaTags'; import { ProjectInformationPages } from './ProjectInformationPages'; import RegulatoryReportModal from './projectRegulatoryReport/RegulatoryReportModal'; -import withAppStateContext from '../../../app-state/withAppStateContext'; -import { AppState } from '../../../../../types/appstate'; -import { BranchLike } from '../../../../../types/branch-like'; -export interface ProjectInformationRendererProps { - appState: AppState; +export interface ProjectInformationRendererProps extends WithAvailableFeaturesProps { canConfigureNotifications: boolean; canUseBadges: boolean; component: Component; @@ -49,14 +50,7 @@ export interface ProjectInformationRendererProps { } export function ProjectInformationRenderer(props: ProjectInformationRendererProps) { - const { - canConfigureNotifications, - canUseBadges, - component, - measures = [], - appState, - branchLike - } = props; + const { canConfigureNotifications, canUseBadges, component, measures = [], branchLike } = props; const heading = React.useRef(null); const isApp = component.qualifier === ComponentQualifier.Application; @@ -68,6 +62,8 @@ export function ProjectInformationRenderer(props: ProjectInformationRendererProp } }, [heading]); + const regulatoryReportFeatureEnabled = props.hasFeature(Feature.RegulatoryReport); + return ( <>
@@ -139,27 +135,26 @@ export function ProjectInformationRenderer(props: ProjectInformationRendererProp /> )} - {component.qualifier === ComponentQualifier.Project && - appState.regulatoryReportFeatureEnabled && ( -
  • - ( - - )}> - {({ onClick }) => ( - {translate('regulatory_report.page')} - )} - -
  • - )} + {component.qualifier === ComponentQualifier.Project && regulatoryReportFeatureEnabled && ( +
  • + ( + + )}> + {({ onClick }) => ( + {translate('regulatory_report.page')} + )} + +
  • + )}
    ); } -export default withAppStateContext(React.memo(ProjectInformationRenderer)); +export default withAvailableFeatures(React.memo(ProjectInformationRenderer)); diff --git a/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/__tests__/ProjectInformationRenderer-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/__tests__/ProjectInformationRenderer-test.tsx index 0aa6ee2acbf..bec0684abee 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/__tests__/ProjectInformationRenderer-test.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/__tests__/ProjectInformationRenderer-test.tsx @@ -20,7 +20,6 @@ import { shallow } from 'enzyme'; import * as React from 'react'; import { mockComponent } from '../../../../../../helpers/mocks/component'; -import { mockAppState } from '../../../../../../helpers/testMocks'; import { ProjectInformationRenderer, ProjectInformationRendererProps @@ -65,12 +64,10 @@ it('should handle missing quality profiles and quality gates', () => { ).toMatchSnapshot(); }); -it('should render app correctly when regulatoryReportFeatureEnabled is false', () => { +it('should render app correctly when regulatoryReport feature is not enabled', () => { expect( shallowRender({ - appState: mockAppState({ - regulatoryReportFeatureEnabled: false - }) + hasFeature: jest.fn().mockReturnValue(false) }) ).toMatchSnapshot(); }); @@ -87,9 +84,7 @@ it('should set focus on the heading when rendered', () => { function shallowRender(props: Partial = {}) { return shallow( - - - - `; -exports[`should render app correctly when regulatoryReportFeatureEnabled is false 1`] = ` +exports[`should render app correctly when regulatoryReport feature is not enabled 1`] = `

    systemSettingValuesByKey; @@ -143,7 +141,6 @@ public class GlobalAction implements NavigationWsAction, Startable { writeInstanceUsesDefaultAdminCredentials(json); writeMultipleAlmEnabled(json); writeProjectImportFeature(json); - writeRegulatoryReportFeature(json); editionProvider.get().ifPresent(e -> json.prop("edition", e.name().toLowerCase(Locale.ENGLISH))); writeNeedIssueSync(json); json.prop("standalone", webServer.isStandalone()); @@ -226,12 +223,6 @@ public class GlobalAction implements NavigationWsAction, Startable { webAnalyticsLoader.getUrlPathToJs().ifPresent(p -> json.prop("webAnalyticsJsPath", p)); } - private void writeRegulatoryReportFeature(JsonWriter json) { - Edition edition = editionProvider.get().orElse(null); - boolean isEnabled = isEditionEEorDCE(edition); - json.prop(REGULATORY_REPORT_FEATURE_ENABLED_FLAG, isEnabled); - } - private static boolean isEditionEEorDCE(@Nullable Edition edition) { return Arrays.asList(ENTERPRISE, DATACENTER).contains(edition); } diff --git a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/ui/ws/global-example.json b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/ui/ws/global-example.json index a9779b55d41..7a110f13d78 100644 --- a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/ui/ws/global-example.json +++ b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/ui/ws/global-example.json @@ -27,7 +27,6 @@ "productionDatabase": true, "branchesEnabled": false, "projectImportFeatureEnabled": false, - "regulatoryReportFeatureEnabled": false, "canAdmin": false, "standalone": true, "edition": "community" diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/GlobalActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/GlobalActionTest.java index 1d8d40662f0..b37184ad49b 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/GlobalActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/GlobalActionTest.java @@ -272,29 +272,6 @@ public class GlobalActionTest { assertJson(call()).isSimilarTo("{\"needIssueSync\": false}"); } - @Test - public void regulatory_report_feature_enabled_ee_dce() { - init(); - when(editionProvider.get()).thenReturn(Optional.of(ENTERPRISE)); - assertJson(call()).isSimilarTo("{\"regulatoryReportFeatureEnabled\":true}"); - - when(editionProvider.get()).thenReturn(Optional.of(DATACENTER)); - assertJson(call()).isSimilarTo("{\"regulatoryReportFeatureEnabled\":true}"); - } - - @Test - public void regulatory_report_feature_disabled_ce_de() { - init(); - when(editionProvider.get()).thenReturn(Optional.of(COMMUNITY)); - assertJson(call()).isSimilarTo("{\"regulatoryReportFeatureEnabled\":false}"); - - when(editionProvider.get()).thenReturn(Optional.of(DEVELOPER)); - assertJson(call()).isSimilarTo("{\"regulatoryReportFeatureEnabled\":false}"); - - when(editionProvider.get()).thenReturn(Optional.empty()); - assertJson(call()).isSimilarTo("{\"regulatoryReportFeatureEnabled\":false}"); - } - @Test public void instance_uses_default_admin_credentials() { init();