]> source.dussan.org Git - sonarqube.git/blob
992f8046e4f645d0a90f7552210675cc50f55c23
[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 { DeferredSpinner, LightPrimary, Title } from 'design-system';
21 import * as React from 'react';
22 import { translate } from '../../../../helpers/l10n';
23 import { BitbucketCloudRepository } from '../../../../types/alm-integration';
24 import { AlmKeys, AlmSettingsInstance } from '../../../../types/alm-settings';
25 import AlmSettingsInstanceDropdown from '../components/AlmSettingsInstanceDropdown';
26 import PersonalAccessTokenForm from '../components/PersonalAccessTokenForm';
27 import WrongBindingCountAlert from '../components/WrongBindingCountAlert';
28 import BitbucketCloudSearchForm from './BitbucketCloudSearchForm';
29
30 export interface BitbucketCloudProjectCreateRendererProps {
31   isLastPage: boolean;
32   canAdmin?: boolean;
33   loading: boolean;
34   loadingMore: boolean;
35   onImport: (repositorySlug: string) => void;
36   onLoadMore: () => void;
37   onPersonalAccessTokenCreated: () => void;
38   onSearch: (searchQuery: string) => void;
39   onSelectedAlmInstanceChange: (instance: AlmSettingsInstance) => void;
40   repositories?: BitbucketCloudRepository[];
41   resetPat: boolean;
42   searching: boolean;
43   searchQuery: string;
44   showPersonalAccessTokenForm: boolean;
45   almInstances: AlmSettingsInstance[];
46   selectedAlmInstance?: AlmSettingsInstance;
47 }
48
49 export default function BitbucketCloudProjectCreateRenderer(
50   props: BitbucketCloudProjectCreateRendererProps
51 ) {
52   const {
53     almInstances,
54     isLastPage,
55     selectedAlmInstance,
56     canAdmin,
57     loading,
58     loadingMore,
59     repositories,
60     resetPat,
61     searching,
62     searchQuery,
63     showPersonalAccessTokenForm,
64   } = props;
65
66   return (
67     <>
68       <header className="sw-mb-10">
69         <Title className="sw-mb-4">
70           {translate('onboarding.create_project.bitbucketcloud.title')}
71         </Title>
72         <LightPrimary className="sw-body-sm">
73           {translate('onboarding.create_project.bitbucketcloud.subtitle')}
74         </LightPrimary>
75       </header>
76
77       <AlmSettingsInstanceDropdown
78         almKey={AlmKeys.BitbucketCloud}
79         almInstances={almInstances}
80         selectedAlmInstance={selectedAlmInstance}
81         onChangeConfig={props.onSelectedAlmInstanceChange}
82       />
83
84       <DeferredSpinner loading={loading} />
85
86       {!loading && !selectedAlmInstance && (
87         <WrongBindingCountAlert alm={AlmKeys.BitbucketCloud} canAdmin={!!canAdmin} />
88       )}
89
90       {!loading &&
91         selectedAlmInstance &&
92         (showPersonalAccessTokenForm ? (
93           <PersonalAccessTokenForm
94             almSetting={selectedAlmInstance}
95             resetPat={resetPat}
96             onPersonalAccessTokenCreated={props.onPersonalAccessTokenCreated}
97           />
98         ) : (
99           <BitbucketCloudSearchForm
100             isLastPage={isLastPage}
101             loadingMore={loadingMore}
102             searchQuery={searchQuery}
103             searching={searching}
104             onImport={props.onImport}
105             onSearch={props.onSearch}
106             onLoadMore={props.onLoadMore}
107             repositories={repositories}
108           />
109         ))}
110     </>
111   );
112 }