3 * Copyright (C) 2009-2021 SonarSource SA
4 * mailto:info AT sonarsource DOT com
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.
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.
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.
20 import * as React from 'react';
21 import { FormattedMessage } from 'react-intl';
22 import { Link } from 'react-router';
23 import HelpTooltip from 'sonar-ui-common/components/controls/HelpTooltip';
24 import { Alert } from 'sonar-ui-common/components/ui/Alert';
25 import { translate } from 'sonar-ui-common/helpers/l10n';
26 import { AlmKeys, ProjectAlmBindingResponse } from '../../../../types/alm-settings';
27 import InputForBoolean from '../inputs/InputForBoolean';
29 export interface AlmSpecificFormProps {
31 formData: T.Omit<ProjectAlmBindingResponse, 'alm'>;
32 onFieldChange: (id: keyof ProjectAlmBindingResponse, value: string | boolean) => void;
33 monorepoEnabled: boolean;
36 interface LabelProps {
38 helpParams?: T.Dict<string | JSX.Element>;
43 interface CommonFieldProps extends LabelProps {
44 onFieldChange: (id: keyof ProjectAlmBindingResponse, value: string | boolean) => void;
45 propKey: keyof ProjectAlmBindingResponse;
48 function renderLabel(props: LabelProps) {
49 const { help, helpParams, optional, id } = props;
51 <label className="display-flex-center" htmlFor={id}>
52 {translate('settings.pr_decoration.binding.form', id)}
53 {!optional && <em className="mandatory">*</em>}
56 className="spacer-left"
59 defaultMessage={translate('settings.pr_decoration.binding.form', id, 'help')}
60 id={`settings.pr_decoration.binding.form.${id}.help`}
71 function renderBooleanField(
72 props: Omit<CommonFieldProps, 'optional'> & {
74 inputExtra?: React.ReactNode;
77 const { id, value, onFieldChange, propKey, inputExtra } = props;
79 <div className="form-field">
80 {renderLabel({ ...props, optional: true })}
81 <div className="display-flex-center">
85 onChange={v => onFieldChange(propKey, v)}
95 props: CommonFieldProps & {
99 const { id, propKey, value, onFieldChange } = props;
101 <div className="form-field">
104 className="input-super-large"
108 onChange={e => onFieldChange(propKey, e.currentTarget.value)}
116 function renderMonoRepoField(props: {
117 monorepoEnabled: boolean;
120 onFieldChange: (id: keyof ProjectAlmBindingResponse, value: string | boolean) => void;
122 if (!props.monorepoEnabled) {
126 return renderBooleanField({
130 <Link to={props.docLink} target="_blank">
131 {translate('learn_more')}
136 onFieldChange: props.onFieldChange,
138 value: props.value ?? false,
139 inputExtra: props.value && (
140 <Alert className="no-margin-bottom spacer-left" variant="warning" display="inline">
141 {translate('settings.pr_decoration.binding.form.monorepo.warning')}
147 export default function AlmSpecificForm(props: AlmSpecificFormProps) {
150 formData: { repository, slug, summaryCommentEnabled, monorepo },
161 onFieldChange: props.onFieldChange,
167 id: 'azure.repository',
168 onFieldChange: props.onFieldChange,
169 propKey: 'repository',
170 value: repository || ''
172 {renderMonoRepoField({
175 docLink: '/documentation/analysis/azuredevops-integration/',
176 onFieldChange: props.onFieldChange
180 case AlmKeys.Bitbucket:
189 <strong>{'{KEY}'}</strong>
190 {'/repos/{SLUG}/browse'}
194 id: 'bitbucket.repository',
195 onFieldChange: props.onFieldChange,
196 propKey: 'repository',
197 value: repository || ''
204 {'.../projects/{KEY}/repos/'}
205 <strong>{'{SLUG}'}</strong>
210 id: 'bitbucket.slug',
211 onFieldChange: props.onFieldChange,
215 {renderMonoRepoField({
218 docLink: '/documentation/analysis/bitbucket-integration/',
219 onFieldChange: props.onFieldChange
228 helpParams: { example: 'SonarSource/sonarqube' },
229 id: 'github.repository',
230 onFieldChange: props.onFieldChange,
231 propKey: 'repository',
232 value: repository || ''
234 {renderBooleanField({
236 id: 'github.summary_comment_setting',
237 onFieldChange: props.onFieldChange,
238 propKey: 'summaryCommentEnabled',
239 value: summaryCommentEnabled === undefined ? true : summaryCommentEnabled
241 {renderMonoRepoField({
244 docLink: '/documentation/analysis/github-integration/',
245 onFieldChange: props.onFieldChange
251 id: 'gitlab.repository',
252 onFieldChange: props.onFieldChange,
253 propKey: 'repository',
254 value: repository || ''