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 { ButtonPrimary, FlagMessage, Modal, Spinner } from 'design-system';
21 import * as React from 'react';
22 import { translate } from '../../../../helpers/l10n';
26 AzureBindingDefinition,
27 BitbucketCloudBindingDefinition,
28 BitbucketServerBindingDefinition,
29 GithubBindingDefinition,
30 GitlabBindingDefinition,
31 } from '../../../../types/alm-settings';
32 import AzureForm from './AzureForm';
33 import BitbucketForm from './BitbucketForm';
34 import GithubForm from './GithubForm';
35 import GitlabForm from './GitlabForm';
37 export interface Props {
43 onFieldChange: (fieldId: keyof AlmBindingDefinition, value: string) => void;
44 formData: AlmBindingDefinition;
46 bitbucketVariant?: AlmKeys.BitbucketServer | AlmKeys.BitbucketCloud;
47 onBitbucketVariantChange: (
48 bitbucketVariant: AlmKeys.BitbucketServer | AlmKeys.BitbucketCloud,
50 validationError?: string;
53 export default class AlmBindingDefinitionFormRenderer extends React.PureComponent<Readonly<Props>> {
55 const { alm, formData, isUpdate, bitbucketVariant } = this.props;
61 onFieldChange={this.props.onFieldChange}
62 formData={formData as GitlabBindingDefinition}
68 onFieldChange={this.props.onFieldChange}
69 formData={formData as AzureBindingDefinition}
75 onFieldChange={this.props.onFieldChange}
76 formData={formData as GithubBindingDefinition}
79 case AlmKeys.BitbucketServer:
82 onFieldChange={this.props.onFieldChange}
84 formData as BitbucketServerBindingDefinition | BitbucketCloudBindingDefinition
87 variant={bitbucketVariant}
88 onVariantChange={this.props.onBitbucketVariantChange}
97 const { isUpdate, canSubmit, submitting, validationError } = this.props;
98 const header = translate('settings.almintegration.form.header', isUpdate ? 'edit' : 'create');
99 const FORM_ID = `settings.almintegration.form.${isUpdate ? 'edit' : 'create'}`;
101 const handleSubmit = (event: React.SyntheticEvent<HTMLFormElement>) => {
102 event.preventDefault();
103 this.props.onSubmit();
107 <form id={FORM_ID} onSubmit={handleSubmit}>
109 {validationError && !canSubmit && (
110 <FlagMessage variant="error" className="sw-w-full">
112 <p>{translate('settings.almintegration.configuration_invalid')}</p>
114 <li>{validationError}</li>
126 onClose={this.props.onCancel}
130 <Spinner loading={submitting} />
135 disabled={!canSubmit || submitting}
137 {translate('settings.almintegration.form.save')}
141 secondaryButtonLabel={translate('cancel')}