1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
/*
* SonarQube
* Copyright (C) 2009-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import * as React from 'react';
import EllipsisIcon from 'sonar-ui-common/components/icons/EllipsisIcon';
import { translate } from 'sonar-ui-common/helpers/l10n';
import { getBaseUrl } from 'sonar-ui-common/helpers/urls';
import { AlmKeys, AlmSettingsInstance, ProjectAlmBindingResponse } from '../../types/alm-settings';
import AzurePipelinesTutorial from './azure-pipelines/AzurePipelinesTutorial';
import BitbucketPipelinesTutorial from './bitbucket-pipelines/BitbucketPipelinesTutorial';
import GitHubActionTutorial from './github-action/GitHubActionTutorial';
import GitLabCITutorial from './gitlabci/GitLabCITutorial';
import JenkinsTutorial from './jenkins/JenkinsTutorial';
import ManualTutorial from './manual/ManualTutorial';
import { TutorialModes } from './types';
export interface TutorialSelectionRendererProps {
almBinding?: AlmSettingsInstance;
baseUrl: string;
component: T.Component;
currentUser: T.LoggedInUser;
loading: boolean;
onSelectTutorial: (mode: TutorialModes) => void;
projectBinding?: ProjectAlmBindingResponse;
selectedTutorial?: TutorialModes;
willRefreshAutomatically?: boolean;
}
const DEFAULT_ICON_SIZE = 80;
const GH_ACTION_ICON_SIZE = 64;
function renderButton(
mode: TutorialModes,
onSelectTutorial: (mode: TutorialModes) => void,
icon: React.ReactNode
) {
return (
<button
className={`button button-huge display-flex-column spacer-left spacer-right huge-spacer-bottom tutorial-mode-${mode}`}
// Currently, OtherCI is the same tutorial as Manual. We might update it to its own stand-alone
// tutorial in the future.
onClick={() => onSelectTutorial(mode === TutorialModes.OtherCI ? TutorialModes.Manual : mode)}
type="button">
{icon}
<div className="medium big-spacer-top">
{translate('onboarding.tutorial.choose_method', mode)}
</div>
</button>
);
}
export default function TutorialSelectionRenderer(props: TutorialSelectionRendererProps) {
const {
almBinding,
baseUrl,
component,
currentUser,
loading,
projectBinding,
selectedTutorial,
willRefreshAutomatically
} = props;
if (loading) {
return <i className="spinner" />;
}
let showGitHubActions = true;
let showGitLabCICD = true;
let showBitbucketPipelines = true;
let showAzurePipelines = true;
let showJenkins = true;
if (projectBinding !== undefined) {
showGitHubActions = projectBinding.alm === AlmKeys.GitHub;
showGitLabCICD = projectBinding.alm === AlmKeys.GitLab;
showBitbucketPipelines = projectBinding?.alm === AlmKeys.BitbucketCloud;
showAzurePipelines = [AlmKeys.Azure, AlmKeys.GitHub].includes(projectBinding.alm);
showJenkins = [
AlmKeys.BitbucketCloud,
AlmKeys.BitbucketServer,
AlmKeys.GitHub,
AlmKeys.GitLab
].includes(projectBinding.alm);
}
return (
<>
{selectedTutorial === undefined && (
<div className="tutorial-selection">
<header className="spacer-top spacer-bottom padded">
<h1 className="text-center big-spacer-bottom">
{translate('onboarding.tutorial.choose_method')}
</h1>
</header>
<div className="display-flex-justify-center display-flex-wrap">
{renderButton(
TutorialModes.Manual,
props.onSelectTutorial,
<img
alt="" // Should be ignored by screen readers
height={DEFAULT_ICON_SIZE}
src={`${getBaseUrl()}/images/tutorials/manual.svg`}
/>
)}
{showAzurePipelines &&
renderButton(
TutorialModes.AzurePipelines,
props.onSelectTutorial,
<img
alt="" // Should be ignored by screen readers
height={DEFAULT_ICON_SIZE}
src={`${getBaseUrl()}/images/tutorials/azure-pipelines.svg`}
/>
)}
{showBitbucketPipelines &&
renderButton(
TutorialModes.BitbucketPipelines,
props.onSelectTutorial,
<img
alt="" // Should be ignored by screen readers
height={DEFAULT_ICON_SIZE}
src={`${getBaseUrl()}/images/alm/bitbucket.svg`}
/>
)}
{showGitHubActions &&
renderButton(
TutorialModes.GitHubActions,
props.onSelectTutorial,
<img
alt="" // Should be ignored by screen readers
height={GH_ACTION_ICON_SIZE}
className="spacer-bottom spacer-top"
src={`${getBaseUrl()}/images/tutorials/github-actions.svg`}
/>
)}
{showGitLabCICD &&
renderButton(
TutorialModes.GitLabCI,
props.onSelectTutorial,
<img
alt="" // Should be ignored by screen readers
height={DEFAULT_ICON_SIZE}
src={`${getBaseUrl()}/images/alm/gitlab.svg`}
/>
)}
{showJenkins &&
renderButton(
TutorialModes.Jenkins,
props.onSelectTutorial,
<img
alt="" // Should be ignored by screen readers
height={DEFAULT_ICON_SIZE}
src={`${getBaseUrl()}/images/tutorials/jenkins.svg`}
/>
)}
{renderButton(
TutorialModes.OtherCI,
props.onSelectTutorial,
<EllipsisIcon size={DEFAULT_ICON_SIZE / 2} />
)}
</div>
</div>
)}
{selectedTutorial === TutorialModes.Manual && (
<ManualTutorial component={component} currentUser={currentUser} />
)}
{selectedTutorial === TutorialModes.BitbucketPipelines && (
<BitbucketPipelinesTutorial
almBinding={almBinding}
baseUrl={baseUrl}
component={component}
currentUser={currentUser}
projectBinding={projectBinding}
willRefreshAutomatically={willRefreshAutomatically}
/>
)}
{selectedTutorial === TutorialModes.GitHubActions && (
<GitHubActionTutorial
almBinding={almBinding}
baseUrl={baseUrl}
component={component}
currentUser={currentUser}
projectBinding={projectBinding}
willRefreshAutomatically={willRefreshAutomatically}
/>
)}
{selectedTutorial === TutorialModes.Jenkins && (
<JenkinsTutorial
almBinding={almBinding}
baseUrl={baseUrl}
component={component}
projectBinding={projectBinding}
willRefreshAutomatically={willRefreshAutomatically}
/>
)}
{selectedTutorial === TutorialModes.GitLabCI && (
<GitLabCITutorial
baseUrl={baseUrl}
component={component}
currentUser={currentUser}
willRefreshAutomatically={willRefreshAutomatically}
/>
)}
{selectedTutorial === TutorialModes.AzurePipelines && (
<AzurePipelinesTutorial
alm={almBinding?.alm}
baseUrl={baseUrl}
component={component}
currentUser={currentUser}
willRefreshAutomatically={willRefreshAutomatically}
/>
)}
</>
);
}
|