From: Revanshu Paliwal Date: Thu, 17 Nov 2022 14:59:16 +0000 (+0100) Subject: SONAR-17588 Allow project onboarding when multiple Bitbucket integrations are configured X-Git-Tag: 9.8.0.63668~94 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9d2a38de3347dc85890fae454f82154a52267a69;p=sonarqube.git SONAR-17588 Allow project onboarding when multiple Bitbucket integrations are configured --- diff --git a/server/sonar-web/src/main/js/apps/create/project/AlmSettingsInstanceDropdown.tsx b/server/sonar-web/src/main/js/apps/create/project/AlmSettingsInstanceDropdown.tsx index 1bd3d726f48..6a6776fb355 100644 --- a/server/sonar-web/src/main/js/apps/create/project/AlmSettingsInstanceDropdown.tsx +++ b/server/sonar-web/src/main/js/apps/create/project/AlmSettingsInstanceDropdown.tsx @@ -28,24 +28,25 @@ export interface AlmSettingsInstanceDropdownProps { onChangeConfig: (instance: AlmSettingsInstance) => void; } +const MIN_SIZE_INSTANCES = 2; + export default function AlmSettingsInstanceDropdown(props: AlmSettingsInstanceDropdownProps) { const { almInstances, selectedAlmInstance } = props; + if (!almInstances || almInstances.length < MIN_SIZE_INSTANCES) { + return null; + } return ( - <> - {almInstances && almInstances.length > 1 ? ( -
- - -
- ) : null} - +
+ + +
); } diff --git a/server/sonar-web/src/main/js/apps/create/project/BitbucketCloudProjectCreate.tsx b/server/sonar-web/src/main/js/apps/create/project/BitbucketCloudProjectCreate.tsx index a091375ccad..0ee1f087eb4 100644 --- a/server/sonar-web/src/main/js/apps/create/project/BitbucketCloudProjectCreate.tsx +++ b/server/sonar-web/src/main/js/apps/create/project/BitbucketCloudProjectCreate.tsx @@ -30,7 +30,7 @@ import BitbucketCloudProjectCreateRenderer from './BitbucketCloudProjectCreateRe interface Props { canAdmin: boolean; - settings: AlmSettingsInstance[]; + almInstances: AlmSettingsInstance[]; loadingBindings: boolean; onProjectCreate: (projectKey: string) => void; location: Location; @@ -47,7 +47,7 @@ interface State { repositories: BitbucketCloudRepository[]; searching: boolean; searchQuery: string; - settings: AlmSettingsInstance; + selectedAlmInstance: AlmSettingsInstance; showPersonalAccessTokenForm: boolean; } @@ -67,7 +67,7 @@ export default class BitbucketCloudProjectCreate extends React.PureComponent 0) { - this.setState({ settings: this.props.settings[0] }, () => this.fetchData()); + if (prevProps.almInstances.length === 0 && this.props.almInstances.length > 0) { + this.setState({ selectedAlmInstance: this.props.almInstances[0] }, () => this.fetchData()); } } @@ -98,14 +98,14 @@ export default class BitbucketCloudProjectCreate extends React.PureComponent { - const { settings } = this.state; + const { selectedAlmInstance } = this.state; - if (!settings) { + if (!selectedAlmInstance) { return; } this.setState({ importingSlug: repositorySlug }); - const result = await importBitbucketCloudRepository(settings.key, repositorySlug).catch( - () => undefined - ); + const result = await importBitbucketCloudRepository( + selectedAlmInstance.key, + repositorySlug + ).catch(() => undefined); if (this.mounted) { this.setState({ importingSlug: undefined }); @@ -195,12 +196,23 @@ export default class BitbucketCloudProjectCreate extends React.PureComponent { + this.setState({ + selectedAlmInstance: instance, + showPersonalAccessTokenForm: true, + resetPat: false, + searching: false, + searchQuery: '', + projectsPaging: { pageIndex: 1, pageSize: BITBUCKET_CLOUD_PROJECTS_PAGESIZE }, + }); + }; + render() { - const { canAdmin, loadingBindings, location } = this.props; + const { canAdmin, loadingBindings, location, almInstances } = this.props; const { importingSlug, isLastPage = true, - settings, + selectedAlmInstance, loading, loadingMore, repositories, @@ -213,7 +225,8 @@ export default class BitbucketCloudProjectCreate extends React.PureComponent void; onPersonalAccessTokenCreated: () => void; onSearch: (searchQuery: string) => void; + onSelectedAlmInstanceChange: (instance: AlmSettingsInstance) => void; repositories?: BitbucketCloudRepository[]; resetPat: boolean; searching: boolean; searchQuery: string; showPersonalAccessTokenForm: boolean; - settings?: AlmSettingsInstance; + almInstances: AlmSettingsInstance[]; + selectedAlmInstance?: AlmSettingsInstance; } export default function BitbucketCloudProjectCreateRenderer( props: BitbucketCloudProjectCreateRendererProps ) { const { + almInstances, importingSlug, isLastPage, - settings, + selectedAlmInstance, canAdmin, loading, loadingMore, @@ -77,17 +81,24 @@ export default function BitbucketCloudProjectCreateRenderer( } /> + + + {loading && } - {!loading && !settings && ( + {!loading && !selectedAlmInstance && ( )} {!loading && - settings && + selectedAlmInstance && (showPersonalAccessTokenForm ? ( diff --git a/server/sonar-web/src/main/js/apps/create/project/BitbucketProjectCreate.tsx b/server/sonar-web/src/main/js/apps/create/project/BitbucketProjectCreate.tsx index 97b08aeed0d..92ad18e876b 100644 --- a/server/sonar-web/src/main/js/apps/create/project/BitbucketProjectCreate.tsx +++ b/server/sonar-web/src/main/js/apps/create/project/BitbucketProjectCreate.tsx @@ -36,7 +36,7 @@ import { DEFAULT_BBS_PAGE_SIZE } from './constants'; interface Props { canAdmin: boolean; - bitbucketSettings: AlmSettingsInstance[]; + almInstances: AlmSettingsInstance[]; loadingBindings: boolean; onProjectCreate: (projectKey: string) => void; location: Location; @@ -44,7 +44,7 @@ interface Props { } interface State { - bitbucketSetting?: AlmSettingsInstance; + selectedAlmInstance?: AlmSettingsInstance; importing: boolean; loading: boolean; projects?: BitbucketProject[]; @@ -63,7 +63,7 @@ export default class BitbucketProjectCreate extends React.PureComponent 0) { - this.setState({ bitbucketSetting: this.props.bitbucketSettings[0] }, () => + if (prevProps.almInstances.length === 0 && this.props.almInstances.length > 0) { + this.setState({ selectedAlmInstance: this.props.almInstances[0] }, () => this.fetchInitialData() ); } @@ -112,27 +112,27 @@ export default class BitbucketProjectCreate extends React.PureComponent => { - const { bitbucketSetting } = this.state; + const { selectedAlmInstance } = this.state; - if (!bitbucketSetting) { + if (!selectedAlmInstance) { return Promise.resolve(undefined); } - return getBitbucketServerProjects(bitbucketSetting.key).then(({ projects }) => projects); + return getBitbucketServerProjects(selectedAlmInstance.key).then(({ projects }) => projects); }; fetchBitbucketRepositories = ( projects: BitbucketProject[] ): Promise => { - const { bitbucketSetting } = this.state; + const { selectedAlmInstance } = this.state; - if (!bitbucketSetting) { + if (!selectedAlmInstance) { return Promise.resolve(undefined); } return Promise.all( projects.map((p) => { - return getBitbucketServerRepositories(bitbucketSetting.key, p.name).then( + return getBitbucketServerRepositories(selectedAlmInstance.key, p.name).then( ({ isLastPage, repositories }) => { // Because the WS uses the project name rather than its key to find // repositories, we can match more repositories than we expect. For @@ -183,15 +183,15 @@ export default class BitbucketProjectCreate extends React.PureComponent { - const { bitbucketSetting, selectedRepository } = this.state; + const { selectedAlmInstance, selectedRepository } = this.state; - if (!bitbucketSetting || !selectedRepository) { + if (!selectedAlmInstance || !selectedRepository) { return; } this.setState({ importing: true }); importBitbucketServerProject( - bitbucketSetting.key, + selectedAlmInstance.key, selectedRepository.projectKey, selectedRepository.slug ) @@ -209,9 +209,9 @@ export default class BitbucketProjectCreate extends React.PureComponent { - const { bitbucketSetting } = this.state; + const { selectedAlmInstance } = this.state; - if (!bitbucketSetting) { + if (!selectedAlmInstance) { return; } @@ -221,7 +221,7 @@ export default class BitbucketProjectCreate extends React.PureComponent { if (this.mounted) { this.setState({ searching: false, searchResults: repositories }); @@ -238,10 +238,19 @@ export default class BitbucketProjectCreate extends React.PureComponent { + this.setState({ + selectedAlmInstance: instance, + showPersonalAccessTokenForm: true, + searching: false, + searchResults: undefined, + }); + }; + render() { - const { canAdmin, loadingBindings, location } = this.props; + const { canAdmin, loadingBindings, location, almInstances } = this.props; const { - bitbucketSetting, + selectedAlmInstance, importing, loading, projectRepositories, @@ -254,7 +263,8 @@ export default class BitbucketProjectCreate extends React.PureComponent void; onSelectRepository: (repo: BitbucketRepository) => void; onPersonalAccessTokenCreated: () => void; + onSelectedAlmInstanceChange: (instance: AlmSettingsInstance) => void; projects?: BitbucketProject[]; projectRepositories?: BitbucketProjectRepositories; resetPat: boolean; @@ -53,7 +56,8 @@ export interface BitbucketProjectCreateRendererProps { export default function BitbucketProjectCreateRenderer(props: BitbucketProjectCreateRendererProps) { const { - bitbucketSetting, + almInstances, + selectedAlmInstance, canAdmin, importing, loading, @@ -96,17 +100,23 @@ export default function BitbucketProjectCreateRenderer(props: BitbucketProjectCr } /> + + {loading && } - {!loading && !bitbucketSetting && ( + {!loading && !selectedAlmInstance && ( )} {!loading && - bitbucketSetting && + selectedAlmInstance && (showPersonalAccessTokenForm ? ( diff --git a/server/sonar-web/src/main/js/apps/create/project/CreateProjectModeSelection.tsx b/server/sonar-web/src/main/js/apps/create/project/CreateProjectModeSelection.tsx index 22f27994a94..ac16e767c1d 100644 --- a/server/sonar-web/src/main/js/apps/create/project/CreateProjectModeSelection.tsx +++ b/server/sonar-web/src/main/js/apps/create/project/CreateProjectModeSelection.tsx @@ -24,11 +24,10 @@ import classNames from 'classnames'; import * as React from 'react'; import withAppStateContext from '../../../app/components/app-state/withAppStateContext'; import ChevronsIcon from '../../../components/icons/ChevronsIcon'; -import { translate, translateWithParameters } from '../../../helpers/l10n'; +import { translate } from '../../../helpers/l10n'; import { getBaseUrl } from '../../../helpers/system'; -import { AlmKeys } from '../../../types/alm-settings'; +import { AlmKeys, AlmKeysUnion } from '../../../types/alm-settings'; import { AppState } from '../../../types/appstate'; -import { ALLOWED_MULTIPLE_CONFIGS } from './constants'; import { CreateProjectModes } from './types'; export interface CreateProjectModeSelectionProps { @@ -43,35 +42,18 @@ export interface CreateProjectModeSelectionProps { const DEFAULT_ICON_SIZE = 50; -function getErrorMessage( - hasTooManyConfig: boolean, - hasConfig: boolean, - canAdmin: boolean | undefined, - alm: AlmKeys -) { - if (hasTooManyConfig) { - return translateWithParameters( - 'onboarding.create_project.too_many_alm_instances_X', - translate('alm', alm) - ); - } else if (!hasConfig) { +function getErrorMessage(hasConfig: boolean, canAdmin: boolean | undefined) { + if (!hasConfig) { return canAdmin ? translate('onboarding.create_project.alm_not_configured.admin') : translate('onboarding.create_project.alm_not_configured'); } -} - -function getMode( - isBitbucketOption: boolean, - hasBitbucketCloudConf: boolean, - mode: CreateProjectModes -) { - return isBitbucketOption && hasBitbucketCloudConf ? CreateProjectModes.BitbucketCloud : mode; + return undefined; } function renderAlmOption( props: CreateProjectModeSelectionProps, - alm: AlmKeys.Azure | AlmKeys.BitbucketServer | AlmKeys.GitHub | AlmKeys.GitLab, + alm: AlmKeysUnion, mode: CreateProjectModes, last = false ) { @@ -80,30 +62,26 @@ function renderAlmOption( appState: { canAdmin }, loadingBindings, } = props; - - const hasBitbucketCloudConf = almCounts[AlmKeys.BitbucketCloud] > 0; - const isBitbucketOption = alm === AlmKeys.BitbucketServer; - - const count = isBitbucketOption - ? almCounts[AlmKeys.BitbucketServer] + almCounts[AlmKeys.BitbucketCloud] - : almCounts[alm]; + const count = almCounts[alm]; const hasConfig = count > 0; - const hasTooManyConfig = count > 1 && !ALLOWED_MULTIPLE_CONFIGS.includes(alm); - const disabled = loadingBindings || hasTooManyConfig || (!hasConfig && !canAdmin); + const disabled = loadingBindings || (!hasConfig && !canAdmin); const onClick = () => { - if (hasTooManyConfig || (!hasConfig && !canAdmin)) { + if (!hasConfig && !canAdmin) { return null; } if (!hasConfig && canAdmin) { - return props.onConfigMode(alm); + const configMode = alm === AlmKeys.BitbucketCloud ? AlmKeys.BitbucketServer : alm; + return props.onConfigMode(configMode); } - return props.onSelectMode(getMode(isBitbucketOption, hasBitbucketCloudConf, mode)); + return props.onSelectMode(mode); }; - const errorMessage = getErrorMessage(hasTooManyConfig, hasConfig, canAdmin, alm); + const errorMessage = getErrorMessage(hasConfig, canAdmin); + + const svgFileName = alm === AlmKeys.BitbucketCloud ? AlmKeys.BitbucketServer : alm; return (
@@ -119,7 +97,7 @@ function renderAlmOption(
{translate('onboarding.create_project.select_method', alm)} @@ -164,6 +142,7 @@ export function CreateProjectModeSelection(props: CreateProjectModeSelectionProp
{renderAlmOption(props, AlmKeys.Azure, CreateProjectModes.AzureDevOps)} {renderAlmOption(props, AlmKeys.BitbucketServer, CreateProjectModes.BitbucketServer)} + {renderAlmOption(props, AlmKeys.BitbucketCloud, CreateProjectModes.BitbucketCloud)} {renderAlmOption(props, AlmKeys.GitHub, CreateProjectModes.GitHub)} {renderAlmOption(props, AlmKeys.GitLab, CreateProjectModes.GitLab, true)}
diff --git a/server/sonar-web/src/main/js/apps/create/project/CreateProjectPage.tsx b/server/sonar-web/src/main/js/apps/create/project/CreateProjectPage.tsx index aa6f2ff06b6..34660ee0bb8 100644 --- a/server/sonar-web/src/main/js/apps/create/project/CreateProjectPage.tsx +++ b/server/sonar-web/src/main/js/apps/create/project/CreateProjectPage.tsx @@ -179,7 +179,7 @@ export class CreateProjectPage extends React.PureComponent ); } diff --git a/server/sonar-web/src/main/js/apps/create/project/__tests__/BitbucketCloudProjectCreate-test.tsx b/server/sonar-web/src/main/js/apps/create/project/__tests__/BitbucketCloudProjectCreate-test.tsx index 7d2263cc0b4..4aee42212ca 100644 --- a/server/sonar-web/src/main/js/apps/create/project/__tests__/BitbucketCloudProjectCreate-test.tsx +++ b/server/sonar-web/src/main/js/apps/create/project/__tests__/BitbucketCloudProjectCreate-test.tsx @@ -46,10 +46,10 @@ jest.mock('../../../../api/alm-integrations', () => { }); it('Should render correctly', async () => { - const wrapper = shallowRender({ settings: [] }); + const wrapper = shallowRender({ almInstances: [] }); await waitAndUpdate(wrapper); expect(wrapper).toMatchSnapshot(); - wrapper.setProps({ settings: [mockBitbucketCloudAlmSettingsInstance()] }); + wrapper.setProps({ almInstances: [mockBitbucketCloudAlmSettingsInstance()] }); await waitAndUpdate(wrapper); expect(wrapper).toMatchSnapshot('Setting changeds'); }); @@ -174,7 +174,7 @@ function shallowRender(props?: Partial) { location={mockLocation()} canAdmin={true} router={mockRouter()} - settings={[mockBitbucketCloudAlmSettingsInstance()]} + almInstances={[mockBitbucketCloudAlmSettingsInstance()]} {...props} /> ); diff --git a/server/sonar-web/src/main/js/apps/create/project/__tests__/BitbucketCloudProjectCreateRender-test.tsx b/server/sonar-web/src/main/js/apps/create/project/__tests__/BitbucketCloudProjectCreateRender-test.tsx index 951aa97fbd1..43c4f5c6b80 100644 --- a/server/sonar-web/src/main/js/apps/create/project/__tests__/BitbucketCloudProjectCreateRender-test.tsx +++ b/server/sonar-web/src/main/js/apps/create/project/__tests__/BitbucketCloudProjectCreateRender-test.tsx @@ -26,7 +26,7 @@ import BitbucketCloudProjectCreateRenderer, { it('Should render correctly', () => { expect(shallowRender()).toMatchSnapshot(); - expect(shallowRender({ settings: undefined })).toMatchSnapshot('Wrong config'); + expect(shallowRender({ selectedAlmInstance: undefined })).toMatchSnapshot('Wrong config'); expect(shallowRender({ loading: true })).toMatchSnapshot('Loading...'); expect( shallowRender({ @@ -48,7 +48,9 @@ function shallowRender(props?: Partial resetPat={false} searching={false} searchQuery="" - settings={mockBitbucketCloudAlmSettingsInstance()} + selectedAlmInstance={mockBitbucketCloudAlmSettingsInstance()} + almInstances={[mockBitbucketCloudAlmSettingsInstance()]} + onSelectedAlmInstanceChange={jest.fn()} showPersonalAccessTokenForm={false} {...props} /> diff --git a/server/sonar-web/src/main/js/apps/create/project/__tests__/BitbucketProjectCreate-test.tsx b/server/sonar-web/src/main/js/apps/create/project/__tests__/BitbucketProjectCreate-test.tsx index c4d108190ca..91a6ea85605 100644 --- a/server/sonar-web/src/main/js/apps/create/project/__tests__/BitbucketProjectCreate-test.tsx +++ b/server/sonar-web/src/main/js/apps/create/project/__tests__/BitbucketProjectCreate-test.tsx @@ -66,7 +66,7 @@ beforeEach(jest.clearAllMocks); it('should render correctly', async () => { expect(shallowRender()).toMatchSnapshot(); - expect(shallowRender({ bitbucketSettings: [] })).toMatchSnapshot('No setting'); + expect(shallowRender({ almInstances: [] })).toMatchSnapshot('No setting'); const wrapper = shallowRender(); (getBitbucketServerRepositories as jest.Mock).mockRejectedValueOnce({}); @@ -130,7 +130,7 @@ it('should correctly handle search', async () => { }); it('should behave correctly when no setting', async () => { - const wrapper = shallowRender({ bitbucketSettings: [] }); + const wrapper = shallowRender({ almInstances: [] }); await wrapper.instance().handleSearch(''); await wrapper.instance().handleImportRepository(); await wrapper.instance().fetchBitbucketRepositories([mockBitbucketProject()]); @@ -144,7 +144,7 @@ function shallowRender(props: Partial = {}) { return shallow( { expect(shallowRender({ selectedRepository: mockBitbucketRepository() })).toMatchSnapshot( 'selected repo' ); - expect(shallowRender({ bitbucketSetting: undefined })).toMatchSnapshot( + expect(shallowRender({ selectedAlmInstance: undefined })).toMatchSnapshot( 'invalid config, regular user' ); - expect(shallowRender({ bitbucketSetting: undefined, canAdmin: true })).toMatchSnapshot( + expect(shallowRender({ selectedAlmInstance: undefined, canAdmin: true })).toMatchSnapshot( 'invalid config, admin user' ); }); @@ -48,7 +48,9 @@ it('should render correctly', () => { function shallowRender(props: Partial = {}) { return shallow( { onSelectMode.mockClear(); click(wrapper.find(almButton).at(2)); - expect(onSelectMode).toHaveBeenCalledWith(CreateProjectModes.GitHub); + expect(onSelectMode).toHaveBeenCalledWith(CreateProjectModes.BitbucketCloud); onSelectMode.mockClear(); click(wrapper.find(almButton).at(3)); + expect(onSelectMode).toHaveBeenCalledWith(CreateProjectModes.GitHub); + onSelectMode.mockClear(); + + click(wrapper.find(almButton).at(4)); expect(onSelectMode).toHaveBeenCalledWith(CreateProjectModes.GitLab); onSelectMode.mockClear(); @@ -91,7 +95,7 @@ it('should correctly pass the selected mode up', () => { { [AlmKeys.BitbucketCloud]: 1, [AlmKeys.BitbucketServer]: 0 } ); - click(wrapper.find(almButton).at(1)); + click(wrapper.find(almButton).at(2)); expect(onSelectMode).toHaveBeenCalledWith(CreateProjectModes.BitbucketCloud); onSelectMode.mockClear(); }); @@ -136,7 +140,7 @@ function shallowRender( ) { const almCounts = { [AlmKeys.Azure]: 1, - [AlmKeys.BitbucketCloud]: 0, + [AlmKeys.BitbucketCloud]: 1, [AlmKeys.BitbucketServer]: 1, [AlmKeys.GitHub]: 1, [AlmKeys.GitLab]: 1, diff --git a/server/sonar-web/src/main/js/apps/create/project/__tests__/__snapshots__/BitbucketCloudProjectCreate-test.tsx.snap b/server/sonar-web/src/main/js/apps/create/project/__tests__/__snapshots__/BitbucketCloudProjectCreate-test.tsx.snap index 8861fde1541..efaf694bc72 100644 --- a/server/sonar-web/src/main/js/apps/create/project/__tests__/__snapshots__/BitbucketCloudProjectCreate-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/create/project/__tests__/__snapshots__/BitbucketCloudProjectCreate-test.tsx.snap @@ -2,6 +2,7 @@ exports[`Should render correctly 1`] = ` } /> + } /> + @@ -69,6 +103,23 @@ exports[`Should render correctly: Need App password 1`] = ` } /> + } /> + `; exports[`should render correctly: No repository 1`] = ` `; exports[`should render correctly: No setting 1`] = ` } /> + } /> + } /> + } /> + } /> + @@ -274,6 +347,23 @@ exports[`should render correctly: pat form 1`] = ` } /> + } /> +
+
+ +
@@ -185,6 +206,27 @@ exports[`should render correctly: invalid configs, admin 1`] = `

+
+ +
@@ -315,6 +357,37 @@ exports[`should render correctly: invalid configs, admin 2`] = `

+
+ +
@@ -445,6 +518,27 @@ exports[`should render correctly: invalid configs, not admin 1`] = `

+
+ +
@@ -577,6 +671,33 @@ exports[`should render correctly: loading instances 1`] = `
+
+ +
@@ -734,6 +855,37 @@ exports[`should render correctly: no alm conf yet, admin 1`] = `

+
+ +
diff --git a/server/sonar-web/src/main/js/apps/create/project/__tests__/__snapshots__/CreateProjectPage-test.tsx.snap b/server/sonar-web/src/main/js/apps/create/project/__tests__/__snapshots__/CreateProjectPage-test.tsx.snap index 623e4d2b0dc..6ec13628e53 100644 --- a/server/sonar-web/src/main/js/apps/create/project/__tests__/__snapshots__/CreateProjectPage-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/create/project/__tests__/__snapshots__/CreateProjectPage-test.tsx.snap @@ -143,7 +143,7 @@ exports[`should render correctly for bitbucket mode 1`] = ` id="create-project" >
diff --git a/server/sonar-web/src/main/js/apps/create/project/constants.ts b/server/sonar-web/src/main/js/apps/create/project/constants.ts index 68567ef7eea..d47426c1831 100644 --- a/server/sonar-web/src/main/js/apps/create/project/constants.ts +++ b/server/sonar-web/src/main/js/apps/create/project/constants.ts @@ -1,5 +1,3 @@ -import { AlmKeys } from '../../../types/alm-settings'; - /* * SonarQube * Copyright (C) 2009-2022 SonarSource SA @@ -22,5 +20,3 @@ import { AlmKeys } from '../../../types/alm-settings'; export const PROJECT_NAME_MAX_LEN = 255; export const DEFAULT_BBS_PAGE_SIZE = 25; - -export const ALLOWED_MULTIPLE_CONFIGS = [AlmKeys.GitLab, AlmKeys.Azure, AlmKeys.GitHub]; diff --git a/server/sonar-web/src/main/js/apps/projects/components/ProjectCreationMenu.tsx b/server/sonar-web/src/main/js/apps/projects/components/ProjectCreationMenu.tsx index 97abfd16f81..b764b4dbd14 100644 --- a/server/sonar-web/src/main/js/apps/projects/components/ProjectCreationMenu.tsx +++ b/server/sonar-web/src/main/js/apps/projects/components/ProjectCreationMenu.tsx @@ -31,7 +31,6 @@ import { hasGlobalPermission } from '../../../helpers/users'; import { AlmKeys, AlmSettingsInstance } from '../../../types/alm-settings'; import { Permissions } from '../../../types/permissions'; import { LoggedInUser } from '../../../types/users'; -import { ALLOWED_MULTIPLE_CONFIGS } from '../../create/project/constants'; import ProjectCreationMenuItem from './ProjectCreationMenuItem'; interface Props { @@ -80,18 +79,10 @@ export class ProjectCreationMenu extends React.PureComponent { const almSettings: AlmSettingsInstance[] = await getAlmSettings().catch(() => []); - // Import is only available if exactly one binding is configured const boundAlms = IMPORT_COMPATIBLE_ALMS.filter((key) => { - let currentAlmSettings: AlmSettingsInstance[]; - if (key === AlmKeys.BitbucketServer || key === AlmKeys.BitbucketCloud) { - currentAlmSettings = almSettings.filter( - (s) => s.alm === AlmKeys.BitbucketCloud || s.alm === AlmKeys.BitbucketServer - ); - } else { - currentAlmSettings = almSettings.filter((s) => s.alm === key); - } + const currentAlmSettings = almSettings.filter((s) => s.alm === key); return ( - this.configLengthChecker(key, currentAlmSettings.length) && + currentAlmSettings.length > 0 && key === currentAlmSettings[0].alm && this.almSettingIsValid(currentAlmSettings[0]) ); @@ -104,10 +95,6 @@ export class ProjectCreationMenu extends React.PureComponent { } }; - configLengthChecker = (key: AlmKeys, length: number) => { - return ALLOWED_MULTIPLE_CONFIGS.includes(key) ? length > 0 : length === 1; - }; - render() { const { className, currentUser } = this.props; const { boundAlms } = this.state; diff --git a/server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectCreationMenu-test.tsx b/server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectCreationMenu-test.tsx index a73c1ea5999..87b621ecebe 100644 --- a/server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectCreationMenu-test.tsx +++ b/server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectCreationMenu-test.tsx @@ -117,11 +117,22 @@ it('should filter alm bindings appropriately', async () => { wrapper = shallowRender(); await waitAndUpdate(wrapper); - expect(wrapper.state().boundAlms).toEqual([AlmKeys.Azure, AlmKeys.GitHub, AlmKeys.GitLab]); + expect(wrapper.state().boundAlms).toEqual([ + AlmKeys.Azure, + AlmKeys.BitbucketServer, + AlmKeys.BitbucketCloud, + AlmKeys.GitHub, + AlmKeys.GitLab, + ]); wrapper = shallowRender(); await waitAndUpdate(wrapper); - expect(wrapper.state().boundAlms).toEqual([AlmKeys.Azure, AlmKeys.GitHub, AlmKeys.GitLab]); + expect(wrapper.state().boundAlms).toEqual([ + AlmKeys.Azure, + AlmKeys.BitbucketServer, + AlmKeys.GitHub, + AlmKeys.GitLab, + ]); }); function shallowRender(overrides: Partial = {}) { diff --git a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/AlmBindingDefinitionBox.tsx b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/AlmBindingDefinitionBox.tsx index ee27acc7694..2d75e7a76d8 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/AlmBindingDefinitionBox.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/AlmBindingDefinitionBox.tsx @@ -38,13 +38,11 @@ import { AlmSettingsBindingStatusType, } from '../../../../types/alm-settings'; import { EditionKey } from '../../../../types/editions'; -import { ALLOWED_MULTIPLE_CONFIGS } from '../../../create/project/constants'; export interface AlmBindingDefinitionBoxProps { alm: AlmKeys; branchesEnabled: boolean; definition: AlmBindingDefinitionBase; - multipleDefinitions: boolean; onCheck: (definitionKey: string) => void; onDelete: (definitionKey: string) => void; onEdit: (definitionKey: string) => void; @@ -108,23 +106,8 @@ function getPRDecorationFeatureStatus( function getImportFeatureStatus( alm: AlmKeys, definition: AlmBindingDefinitionBase, - multipleDefinitions: boolean, type: AlmSettingsBindingStatusType.Success | AlmSettingsBindingStatusType.Failure ) { - if (multipleDefinitions && !ALLOWED_MULTIPLE_CONFIGS.includes(alm)) { - return ( -
- - {translate('settings.almintegration.feature.alm_repo_import.disabled')} - - -
- ); - } - if (!definition.url && alm !== AlmKeys.BitbucketCloud) { return (
@@ -156,7 +139,7 @@ function getPrDecoFeatureDescription(alm: AlmKeys) { } export default function AlmBindingDefinitionBox(props: AlmBindingDefinitionBoxProps) { - const { alm, branchesEnabled, definition, multipleDefinitions, status = DEFAULT_STATUS } = props; + const { alm, branchesEnabled, definition, status = DEFAULT_STATUS } = props; return (
@@ -202,7 +185,7 @@ export default function AlmBindingDefinitionBox(props: AlmBindingDefinitionBoxPr {translate('settings.almintegration.feature.alm_repo_import.title')} - {getImportFeatureStatus(alm, definition, multipleDefinitions, status.type)} + {getImportFeatureStatus(alm, definition, status.type)}
)}
diff --git a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/AlmTabRenderer.tsx b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/AlmTabRenderer.tsx index 6e1382cc881..f36e4f931c7 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/AlmTabRenderer.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/AlmTabRenderer.tsx @@ -107,7 +107,6 @@ export default function AlmTabRenderer(props: AlmTabRendererProps) { branchesEnabled={branchesEnabled} definition={def} key={def.key} - multipleDefinitions={definitions.length > 1} onCheck={props.onCheck} onDelete={props.onDelete} onEdit={props.onEdit} diff --git a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/AlmBindingDefinitionBox-test.tsx b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/AlmBindingDefinitionBox-test.tsx index 8a1f5e2754c..e32365f2f57 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/AlmBindingDefinitionBox-test.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/AlmBindingDefinitionBox-test.tsx @@ -31,7 +31,6 @@ import AlmBindingDefinitionBox, { AlmBindingDefinitionBoxProps } from '../AlmBin it('should render correctly', () => { expect(shallowRender()).toMatchSnapshot('default'); - expect(shallowRender({ multipleDefinitions: true })).toMatchSnapshot('multiple definitions'); expect( shallowRender({ status: mockAlmSettingsBindingStatus({ @@ -106,7 +105,6 @@ function shallowRender(props: Partial = {}) { alm={AlmKeys.GitHub} branchesEnabled={true} definition={mockGithubBindingDefinition()} - multipleDefinitions={false} onCheck={jest.fn()} onDelete={jest.fn()} onEdit={jest.fn()} diff --git a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/__snapshots__/AlmBindingDefinitionBox-test.tsx.snap b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/__snapshots__/AlmBindingDefinitionBox-test.tsx.snap index 4afcf1ec133..afbd6543c06 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/__snapshots__/AlmBindingDefinitionBox-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/__snapshots__/AlmBindingDefinitionBox-test.tsx.snap @@ -164,48 +164,6 @@ exports[`should render correctly: error 1`] = `
`; -exports[`should render correctly: multiple definitions 1`] = ` -
-
- - -
-
-

- key -

- - http://github.enterprise.com - -
- - settings.almintegration.checking_configuration -
-`; - exports[`should render correctly: success 1`] = `