import BoxedGroupAccordion from 'sonar-ui-common/components/controls/BoxedGroupAccordion';
import ListFooter from 'sonar-ui-common/components/controls/ListFooter';
import Radio from 'sonar-ui-common/components/controls/Radio';
+import CheckIcon from 'sonar-ui-common/components/icons/CheckIcon';
import { Alert } from 'sonar-ui-common/components/ui/Alert';
import DeferredSpinner from 'sonar-ui-common/components/ui/DeferredSpinner';
import { translate } from 'sonar-ui-common/helpers/l10n';
+import { colors } from '../../../app/theme';
+import { getProjectUrl } from '../../../helpers/urls';
import { AzureProject, AzureRepository } from '../../../types/alm-integration';
import { CreateProjectModes } from './types';
const [page, setPage] = React.useState(1);
const limitedRepositories = repositories.slice(0, page * PAGE_SIZE);
+ const isSelected = (repo: AzureRepository) =>
+ selectedRepository?.projectName === project.key && selectedRepository.name === repo.name;
+
return (
<BoxedGroupAccordion
className={classNames('big-spacer-bottom', {
<>
<div className="display-flex-wrap">
{limitedRepositories.map(repo => (
- <Radio
- checked={selectedRepository?.name === repo.name}
- className={classNames(
- 'display-flex-start spacer-right spacer-bottom create-project-import-bbs-repo overflow-hidden',
- importing && ['disabled', 'text-muted', 'link-no-underline']
+ <div
+ className="display-flex-start spacer-right spacer-bottom create-project-azdo-repo"
+ key={repo.name}>
+ {repo.sqProjectKey ? (
+ <>
+ <CheckIcon className="spacer-right" fill={colors.green} size={14} />
+ <div className="overflow-hidden">
+ <div className="little-spacer-bottom text-ellipsis">
+ <strong title={repo.sqProjectName}>
+ <Link to={getProjectUrl(repo.sqProjectKey)}>
+ {repo.sqProjectName}
+ </Link>
+ </strong>
+ </div>
+ <em>{translate('onboarding.create_project.repository_imported')}</em>
+ </div>
+ </>
+ ) : (
+ <Radio
+ checked={isSelected(repo)}
+ className="overflow-hidden"
+ disabled={importing}
+ onCheck={() => props.onSelectRepository(repo)}
+ value={repo.name}>
+ <strong className="text-ellipsis" title={repo.name}>
+ {repo.name}
+ </strong>
+ </Radio>
)}
- key={repo.name}
- onCheck={() => !importing && props.onSelectRepository(repo)}
- value={repo.name}>
- <strong className="text-ellipsis" title={repo.name}>
- {repo.name}
- </strong>
- </Radio>
+ </div>
))}
</div>
<ListFooter
import { shallow } from 'enzyme';
import * as React from 'react';
import BoxedGroupAccordion from 'sonar-ui-common/components/controls/BoxedGroupAccordion';
+import Radio from 'sonar-ui-common/components/controls/Radio';
import { mockAzureProject, mockAzureRepository } from '../../../../helpers/mocks/alm-integrations';
+import { mockEvent } from '../../../../helpers/testMocks';
import AzureProjectAccordion, { AzureProjectAccordionProps } from '../AzureProjectAccordion';
it('should render correctly', () => {
expect(shallowRender({ loading: true })).toMatchSnapshot('loading');
expect(shallowRender({ startsOpen: false })).toMatchSnapshot('closed');
- expect(shallowRender({ repositories: [mockAzureRepository()] })).toMatchSnapshot(
- 'with a repository'
- );
+ expect(
+ shallowRender({
+ repositories: [
+ mockAzureRepository(),
+ mockAzureRepository({ sqProjectKey: 'sq-key', sqProjectName: 'SQ Name' })
+ ]
+ })
+ ).toMatchSnapshot('with repositories');
expect(shallowRender({ importing: true, repositories: [mockAzureRepository()] })).toMatchSnapshot(
'importing'
);
).toBe(false);
});
+it('should trigger selection when repo is clicked', () => {
+ const onSelectRepository = jest.fn();
+ const repo = mockAzureRepository();
+ const wrapper = shallowRender({ onSelectRepository, repositories: [repo] });
+
+ wrapper
+ .find(Radio)
+ .props()
+ .onCheck(mockEvent());
+
+ expect(onSelectRepository).toBeCalledWith(repo);
+});
+
function shallowRender(overrides: Partial<AzureProjectAccordionProps> = {}) {
return shallow(
<AzureProjectAccordion
<div
className="display-flex-wrap"
>
- <Radio
- checked={false}
- className="display-flex-start spacer-right spacer-bottom create-project-import-bbs-repo overflow-hidden disabled text-muted link-no-underline"
+ <div
+ className="display-flex-start spacer-right spacer-bottom create-project-azdo-repo"
key="Azure repo 1"
- onCheck={[Function]}
- value="Azure repo 1"
>
- <strong
- className="text-ellipsis"
- title="Azure repo 1"
+ <Radio
+ checked={false}
+ className="overflow-hidden"
+ disabled={true}
+ onCheck={[Function]}
+ value="Azure repo 1"
>
- Azure repo 1
- </strong>
- </Radio>
+ <strong
+ className="text-ellipsis"
+ title="Azure repo 1"
+ >
+ Azure repo 1
+ </strong>
+ </Radio>
+ </div>
</div>
<ListFooter
count={1}
</BoxedGroupAccordion>
`;
-exports[`should render correctly: with a repository 1`] = `
+exports[`should render correctly: with repositories 1`] = `
<BoxedGroupAccordion
className="big-spacer-bottom open"
onClick={[Function]}
<div
className="display-flex-wrap"
>
- <Radio
- checked={false}
- className="display-flex-start spacer-right spacer-bottom create-project-import-bbs-repo overflow-hidden"
+ <div
+ className="display-flex-start spacer-right spacer-bottom create-project-azdo-repo"
key="Azure repo 1"
- onCheck={[Function]}
- value="Azure repo 1"
>
- <strong
- className="text-ellipsis"
- title="Azure repo 1"
+ <Radio
+ checked={false}
+ className="overflow-hidden"
+ disabled={false}
+ onCheck={[Function]}
+ value="Azure repo 1"
>
- Azure repo 1
- </strong>
- </Radio>
+ <strong
+ className="text-ellipsis"
+ title="Azure repo 1"
+ >
+ Azure repo 1
+ </strong>
+ </Radio>
+ </div>
+ <div
+ className="display-flex-start spacer-right spacer-bottom create-project-azdo-repo"
+ key="Azure repo 1"
+ >
+ <CheckIcon
+ className="spacer-right"
+ fill="#00aa00"
+ size={14}
+ />
+ <div
+ className="overflow-hidden"
+ >
+ <div
+ className="little-spacer-bottom text-ellipsis"
+ >
+ <strong
+ title="SQ Name"
+ >
+ <Link
+ onlyActiveOnIndex={false}
+ style={Object {}}
+ to={
+ Object {
+ "pathname": "/dashboard",
+ "query": Object {
+ "branch": undefined,
+ "id": "sq-key",
+ },
+ }
+ }
+ >
+ SQ Name
+ </Link>
+ </strong>
+ </div>
+ <em>
+ onboarding.create_project.repository_imported
+ </em>
+ </div>
+ </div>
</div>
<ListFooter
- count={1}
+ count={2}
loadMore={[Function]}
- total={1}
+ total={2}
/>
</DeferredSpinner>
</BoxedGroupAccordion>
justify-content: space-between;
}
+.create-project-azdo-repo {
+ width: 250px;
+ min-height: 40px;
+}
+
.create-project-import-bbs .open .boxed-group-header {
border-bottom: 1px solid var(--barBorderColor);
}
export interface AzureRepository {
name: string;
projectName: string;
+ sqProjectKey?: string;
+ sqProjectName?: string;
}
export interface BitbucketProject {