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 },
154 const renderMonoRepoFieldWithDocLink = (docLink: string) => {
155 return renderMonoRepoField({
159 onFieldChange: props.onFieldChange
170 onFieldChange: props.onFieldChange,
176 id: 'azure.repository',
177 onFieldChange: props.onFieldChange,
178 propKey: 'repository',
179 value: repository || ''
181 {renderMonoRepoFieldWithDocLink('/documentation/analysis/azuredevops-integration/')}
184 case AlmKeys.Bitbucket:
193 <strong>{'{KEY}'}</strong>
194 {'/repos/{SLUG}/browse'}
198 id: 'bitbucket.repository',
199 onFieldChange: props.onFieldChange,
200 propKey: 'repository',
201 value: repository || ''
208 {'.../projects/{KEY}/repos/'}
209 <strong>{'{SLUG}'}</strong>
214 id: 'bitbucket.slug',
215 onFieldChange: props.onFieldChange,
219 {renderMonoRepoFieldWithDocLink('/documentation/analysis/bitbucket-integration/')}
227 helpParams: { example: 'SonarSource/sonarqube' },
228 id: 'github.repository',
229 onFieldChange: props.onFieldChange,
230 propKey: 'repository',
231 value: repository || ''
233 {renderBooleanField({
235 id: 'github.summary_comment_setting',
236 onFieldChange: props.onFieldChange,
237 propKey: 'summaryCommentEnabled',
238 value: summaryCommentEnabled === undefined ? true : summaryCommentEnabled
240 {renderMonoRepoFieldWithDocLink('/documentation/analysis/github-integration/')}
247 id: 'gitlab.repository',
248 onFieldChange: props.onFieldChange,
249 propKey: 'repository',
250 value: repository || ''
252 {renderMonoRepoFieldWithDocLink('/documentation/analysis/gitlab-integration/')}