import * as React from 'react';
import { getActivity } from '../../api/ce';
import { getStatus } from '../../api/project-dump';
-import withAppStateContext from '../../app/components/app-state/withAppStateContext';
+import withAvailableFeatures, {
+ WithAvailableFeaturesProps
+} from '../../app/components/available-features/withAvailableFeatures';
import withComponentContext from '../../app/components/componentContext/withComponentContext';
import { throwGlobalError } from '../../helpers/error';
import { translate } from '../../helpers/l10n';
-import { AppState } from '../../types/appstate';
+import { Feature } from '../../types/features';
import { DumpStatus, DumpTask } from '../../types/project-dump';
import { ActivityRequestParameters, TaskStatuses, TaskTypes } from '../../types/tasks';
import { Component } from '../../types/types';
const POLL_INTERNAL = 5000;
-interface Props {
- appState: AppState;
+interface Props extends WithAvailableFeaturesProps {
component: Component;
}
}
getLastTaskOfEachType(componentKey: string) {
- const {
- appState: { projectImportFeatureEnabled }
- } = this.props;
-
+ const projectImportFeatureEnabled = this.props.hasFeature(Feature.ProjectImport);
const all = projectImportFeatureEnabled
? [
this.getLastTask(componentKey, TaskTypes.ProjectExport),
};
render() {
- const {
- component,
- appState: { projectImportFeatureEnabled }
- } = this.props;
+ const { component } = this.props;
+ const projectImportFeatureEnabled = this.props.hasFeature(Feature.ProjectImport);
const { lastAnalysisTask, lastExportTask, lastImportTask, status } = this.state;
return (
}
}
-export default withComponentContext(withAppStateContext(ProjectDumpApp));
+export default withComponentContext(withAvailableFeatures(ProjectDumpApp));
import { getActivity } from '../../../api/ce';
import { getStatus } from '../../../api/project-dump';
import { mockComponent } from '../../../helpers/mocks/component';
-import { mockAppState, mockDumpStatus, mockDumpTask } from '../../../helpers/testMocks';
+import { mockDumpStatus, mockDumpTask } from '../../../helpers/testMocks';
import { waitAndUpdate } from '../../../helpers/testUtils';
import { TaskStatuses } from '../../../types/tasks';
import { ProjectDumpApp } from '../ProjectDumpApp';
expect(wrapper).toMatchSnapshot('loaded');
- wrapper = shallowRender({ appState: mockAppState({ projectImportFeatureEnabled: false }) });
+ wrapper = shallowRender({ hasFeature: jest.fn().mockReturnValue(false) });
await waitAndUpdate(wrapper);
expect(wrapper).toMatchSnapshot('loaded without import');
});
function shallowRender(overrides: Partial<ProjectDumpApp['props']> = {}) {
return shallow<ProjectDumpApp>(
<ProjectDumpApp
- appState={mockAppState({ projectImportFeatureEnabled: true })}
+ hasFeature={jest.fn().mockReturnValue(true)}
component={mockComponent()}
{...overrides}
/>
canAdmin?: boolean;
edition?: EditionKey;
globalPages?: Extension[];
- projectImportFeatureEnabled?: boolean;
instanceUsesDefaultAdminCredentials?: boolean;
multipleAlmEnabled?: boolean;
needIssueSync?: boolean;
export enum Feature {
MonoRepositoryPullRequestDecoration = 'monorepo',
- RegulatoryReport = 'regulatory-reports'
+ RegulatoryReport = 'regulatory-reports',
+ ProjectImport = 'project-import'
}
writeBranchSupport(json);
writeInstanceUsesDefaultAdminCredentials(json);
writeMultipleAlmEnabled(json);
- writeProjectImportFeature(json);
editionProvider.get().ifPresent(e -> json.prop("edition", e.name().toLowerCase(Locale.ENGLISH)));
writeNeedIssueSync(json);
json.prop("standalone", webServer.isStandalone());
json.prop("multipleAlmEnabled", multipleAlmFeatureProvider.enabled());
}
- private void writeProjectImportFeature(JsonWriter json) {
- Edition edition = editionProvider.get().orElse(null);
- boolean isEnabled = isEditionEEorDCE(edition);
- json.prop("projectImportFeatureEnabled", isEnabled);
- }
-
private void writeNeedIssueSync(JsonWriter json) {
try (DbSession dbSession = dbClient.openSession(false)) {
json.prop("needIssueSync", issueIndexSyncChecker.isIssueSyncInProgress(dbSession));
"version": "6.2",
"productionDatabase": true,
"branchesEnabled": false,
- "projectImportFeatureEnabled": false,
"canAdmin": false,
"standalone": true,
"edition": "community"
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import static org.sonar.core.platform.EditionProvider.Edition.*;
import static org.sonar.test.JsonAssert.assertJson;
public class GlobalActionTest {
}
- @Test
- public void project_import_feature_enabled_ee_dce() {
- init();
- when(editionProvider.get()).thenReturn(Optional.of(ENTERPRISE));
- assertJson(call()).isSimilarTo("{\"projectImportFeatureEnabled\":true}");
-
- when(editionProvider.get()).thenReturn(Optional.of(DATACENTER));
- assertJson(call()).isSimilarTo("{\"projectImportFeatureEnabled\":true}");
- }
-
- @Test
- public void project_import_feature_disabled_ce_de() {
- init();
- when(editionProvider.get()).thenReturn(Optional.of(COMMUNITY));
- assertJson(call()).isSimilarTo("{\"projectImportFeatureEnabled\":false}");
-
- when(editionProvider.get()).thenReturn(Optional.of(DEVELOPER));
- assertJson(call()).isSimilarTo("{\"projectImportFeatureEnabled\":false}");
-
- when(editionProvider.get()).thenReturn(Optional.empty());
- assertJson(call()).isSimilarTo("{\"projectImportFeatureEnabled\":false}");
- }
-
-
@Test
public void return_need_issue_sync() {
init();