* 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';
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;
}
export function ProjectInformationRenderer(props: ProjectInformationRendererProps) {
- const {
- canConfigureNotifications,
- canUseBadges,
- component,
- measures = [],
- appState,
- branchLike
- } = props;
+ const { canConfigureNotifications, canUseBadges, component, measures = [], branchLike } = props;
const heading = React.useRef<HTMLHeadingElement>(null);
const isApp = component.qualifier === ComponentQualifier.Application;
}
}, [heading]);
+ const regulatoryReportFeatureEnabled = props.hasFeature(Feature.RegulatoryReport);
+
return (
<>
<div>
/>
</li>
)}
- {component.qualifier === ComponentQualifier.Project &&
- appState.regulatoryReportFeatureEnabled && (
- <li className="big-padded bordered-bottom">
- <ModalButton
- modal={({ onClose }) => (
- <RegulatoryReportModal
- component={component}
- branchLike={branchLike}
- onClose={onClose}
- />
- )}>
- {({ onClick }) => (
- <ButtonLink onClick={onClick}>{translate('regulatory_report.page')}</ButtonLink>
- )}
- </ModalButton>
- </li>
- )}
+ {component.qualifier === ComponentQualifier.Project && regulatoryReportFeatureEnabled && (
+ <li className="big-padded bordered-bottom">
+ <ModalButton
+ modal={({ onClose }) => (
+ <RegulatoryReportModal
+ component={component}
+ branchLike={branchLike}
+ onClose={onClose}
+ />
+ )}>
+ {({ onClick }) => (
+ <ButtonLink onClick={onClick}>{translate('regulatory_report.page')}</ButtonLink>
+ )}
+ </ModalButton>
+ </li>
+ )}
</ul>
</div>
</>
);
}
-export default withAppStateContext(React.memo(ProjectInformationRenderer));
+export default withAvailableFeatures(React.memo(ProjectInformationRenderer));
import { shallow } from 'enzyme';
import * as React from 'react';
import { mockComponent } from '../../../../../../helpers/mocks/component';
-import { mockAppState } from '../../../../../../helpers/testMocks';
import {
ProjectInformationRenderer,
ProjectInformationRendererProps
).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();
});
function shallowRender(props: Partial<ProjectInformationRendererProps> = {}) {
return shallow(
<ProjectInformationRenderer
- appState={mockAppState({
- regulatoryReportFeatureEnabled: true
- })}
+ hasFeature={jest.fn().mockReturnValue(true)}
canConfigureNotifications={true}
canUseBadges={true}
component={mockComponent({ qualifier: 'TRK', visibility: 'public' })}
exports[`should render correctly: default 1`] = `
<Fragment>
- <withAppStateContext(Component)
+ <withAvailableFeaturesContext(Component)
canConfigureNotifications={false}
canUseBadges={true}
component={
exports[`should render correctly: logged in user 1`] = `
<Fragment>
- <withAppStateContext(Component)
+ <withAvailableFeaturesContext(Component)
canConfigureNotifications={true}
canUseBadges={true}
component={
exports[`should render correctly: measures loaded 1`] = `
<Fragment>
- <withAppStateContext(Component)
+ <withAvailableFeaturesContext(Component)
canConfigureNotifications={false}
canUseBadges={true}
component={
exports[`should render correctly: private 1`] = `
<Fragment>
- <withAppStateContext(Component)
+ <withAvailableFeaturesContext(Component)
canConfigureNotifications={false}
canUseBadges={true}
component={
</Fragment>
`;
-exports[`should render app correctly when regulatoryReportFeatureEnabled is false 1`] = `
+exports[`should render app correctly when regulatoryReport feature is not enabled 1`] = `
<Fragment>
<div>
<h2
standalone?: boolean;
version: string;
webAnalyticsJsPath?: string;
- regulatoryReportFeatureEnabled?: boolean;
}
*/
export enum Feature {
- MonoRepositoryPullRequestDecoration = 'monorepo'
+ MonoRepositoryPullRequestDecoration = 'monorepo',
+ RegulatoryReport = 'regulatory-reports'
}
SONAR_LF_GRAVATAR_SERVER_URL,
RATING_GRID,
DEVELOPER_AGGREGATED_INFO_DISABLED);
-
- private static final String REGULATORY_REPORT_FEATURE_ENABLED_FLAG = "regulatoryReportFeatureEnabled";
private final Map<String, String> systemSettingValuesByKey;
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());
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);
}
"productionDatabase": true,
"branchesEnabled": false,
"projectImportFeatureEnabled": false,
- "regulatoryReportFeatureEnabled": false,
"canAdmin": false,
"standalone": true,
"edition": "community"
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();