3 * Copyright (C) 2009-2023 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 Modal from '../../../../components/controls/Modal';
22 import { ResetButtonLink, SubmitButton } from '../../../../components/controls/buttons';
23 import { Alert } from '../../../../components/ui/Alert';
24 import Spinner from '../../../../components/ui/Spinner';
25 import { translate } from '../../../../helpers/l10n';
29 AzureBindingDefinition,
30 BitbucketCloudBindingDefinition,
31 BitbucketServerBindingDefinition,
32 GithubBindingDefinition,
33 GitlabBindingDefinition,
34 } from '../../../../types/alm-settings';
35 import AzureForm from './AzureForm';
36 import BitbucketForm from './BitbucketForm';
37 import GithubForm from './GithubForm';
38 import GitlabForm from './GitlabForm';
40 export interface Props {
46 onFieldChange: (fieldId: keyof AlmBindingDefinition, value: string) => void;
47 formData: AlmBindingDefinition;
49 bitbucketVariant?: AlmKeys.BitbucketServer | AlmKeys.BitbucketCloud;
50 onBitbucketVariantChange: (
51 bitbucketVariant: AlmKeys.BitbucketServer | AlmKeys.BitbucketCloud,
53 validationError?: string;
56 export default class AlmBindingDefinitionFormRenderer extends React.PureComponent<Readonly<Props>> {
58 const { alm, formData, isUpdate, bitbucketVariant } = this.props;
64 onFieldChange={this.props.onFieldChange}
65 formData={formData as GitlabBindingDefinition}
71 onFieldChange={this.props.onFieldChange}
72 formData={formData as AzureBindingDefinition}
78 onFieldChange={this.props.onFieldChange}
79 formData={formData as GithubBindingDefinition}
82 case AlmKeys.BitbucketServer:
85 onFieldChange={this.props.onFieldChange}
87 formData as BitbucketServerBindingDefinition | BitbucketCloudBindingDefinition
90 variant={bitbucketVariant}
91 onVariantChange={this.props.onBitbucketVariantChange}
100 const { isUpdate, canSubmit, submitting, validationError } = this.props;
101 const header = translate('settings.almintegration.form.header', isUpdate ? 'edit' : 'create');
103 const handleSubmit = (event: React.SyntheticEvent<HTMLFormElement>) => {
104 event.preventDefault();
105 this.props.onSubmit();
110 contentLabel={header}
111 onRequestClose={this.props.onCancel}
112 shouldCloseOnOverlayClick={false}
115 <form onSubmit={handleSubmit}>
116 <div className="modal-head">
120 <div className="modal-body modal-container">
122 {validationError && !canSubmit && (
123 <Alert variant="error">
124 <p className="spacer-bottom">
125 {translate('settings.almintegration.configuration_invalid')}
127 <ul className="list-styled">
128 <li>{validationError}</li>
134 <div className="modal-foot">
135 <SubmitButton disabled={!canSubmit || submitting}>
136 {translate('settings.almintegration.form.save')}
137 <Spinner className="spacer-left" loading={submitting} />
139 <ResetButtonLink onClick={this.props.onCancel}>{translate('cancel')}</ResetButtonLink>