]> source.dussan.org Git - sonarqube.git/blob
28356e43449f8ccd296ff6f98991b9efa977b5be
[sonarqube.git] /
1 /*
2  * SonarQube
3  * Copyright (C) 2009-2023 SonarSource SA
4  * mailto:info AT sonarsource DOT com
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 3 of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19  */
20 import * as React from 'react';
21 import { translate } from '../../../../helpers/l10n';
22 import { getBaseUrl } from '../../../../helpers/system';
23 import { BitbucketCloudRepository } from '../../../../types/alm-integration';
24 import { AlmKeys, AlmSettingsInstance } from '../../../../types/alm-settings';
25 import AlmSettingsInstanceDropdown from '../components/AlmSettingsInstanceDropdown';
26 import CreateProjectPageHeader from '../components/CreateProjectPageHeader';
27 import PersonalAccessTokenForm from '../components/PersonalAccessTokenForm';
28 import WrongBindingCountAlert from '../components/WrongBindingCountAlert';
29 import BitbucketCloudSearchForm from './BitbucketCloudSearchForm';
30
31 export interface BitbucketCloudProjectCreateRendererProps {
32   importingSlug?: string;
33   isLastPage: boolean;
34   canAdmin?: boolean;
35   loading: boolean;
36   loadingMore: boolean;
37   onImport: (repositorySlug: string) => void;
38   onLoadMore: () => void;
39   onPersonalAccessTokenCreated: () => void;
40   onSearch: (searchQuery: string) => void;
41   onSelectedAlmInstanceChange: (instance: AlmSettingsInstance) => void;
42   repositories?: BitbucketCloudRepository[];
43   resetPat: boolean;
44   searching: boolean;
45   searchQuery: string;
46   showPersonalAccessTokenForm: boolean;
47   almInstances: AlmSettingsInstance[];
48   selectedAlmInstance?: AlmSettingsInstance;
49 }
50
51 export default function BitbucketCloudProjectCreateRenderer(
52   props: BitbucketCloudProjectCreateRendererProps
53 ) {
54   const {
55     almInstances,
56     importingSlug,
57     isLastPage,
58     selectedAlmInstance,
59     canAdmin,
60     loading,
61     loadingMore,
62     repositories,
63     resetPat,
64     searching,
65     searchQuery,
66     showPersonalAccessTokenForm,
67   } = props;
68
69   return (
70     <>
71       <CreateProjectPageHeader
72         title={
73           <span className="text-middle">
74             <img
75               alt="" // Should be ignored by screen readers
76               className="spacer-right"
77               height="24"
78               src={`${getBaseUrl()}/images/alm/bitbucket.svg`}
79             />
80             {translate('onboarding.create_project.bitbucketcloud.title')}
81           </span>
82         }
83       />
84
85       <AlmSettingsInstanceDropdown
86         almKey={AlmKeys.BitbucketCloud}
87         almInstances={almInstances}
88         selectedAlmInstance={selectedAlmInstance}
89         onChangeConfig={props.onSelectedAlmInstanceChange}
90       />
91
92       {loading && <i className="spinner" />}
93
94       {!loading && !selectedAlmInstance && (
95         <WrongBindingCountAlert alm={AlmKeys.BitbucketCloud} canAdmin={!!canAdmin} />
96       )}
97
98       {!loading &&
99         selectedAlmInstance &&
100         (showPersonalAccessTokenForm ? (
101           <PersonalAccessTokenForm
102             almSetting={selectedAlmInstance}
103             resetPat={resetPat}
104             onPersonalAccessTokenCreated={props.onPersonalAccessTokenCreated}
105           />
106         ) : (
107           <BitbucketCloudSearchForm
108             importingSlug={importingSlug}
109             isLastPage={isLastPage}
110             loadingMore={loadingMore}
111             searchQuery={searchQuery}
112             searching={searching}
113             onImport={props.onImport}
114             onSearch={props.onSearch}
115             onLoadMore={props.onLoadMore}
116             repositories={repositories}
117           />
118         ))}
119     </>
120   );
121 }