]> source.dussan.org Git - sonarqube.git/blob
2c0ac91f58d3ea94c09474417c4dfc893a8192a6
[sonarqube.git] /
1 /*
2  * SonarQube
3  * Copyright (C) 2009-2021 SonarSource SA
4  * mailto:info AT sonarsource DOT com
5  *
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.
10  *
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.
15  *
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.
19  */
20 import * as React from 'react';
21 import { ResetButtonLink, SubmitButton } from 'sonar-ui-common/components/controls/buttons';
22 import SimpleModal from 'sonar-ui-common/components/controls/SimpleModal';
23 import { Alert } from 'sonar-ui-common/components/ui/Alert';
24 import DeferredSpinner from 'sonar-ui-common/components/ui/DeferredSpinner';
25 import { translate } from 'sonar-ui-common/helpers/l10n';
26
27 export interface AlmBindingDefinitionFormModalProps {
28   action: 'edit' | 'create';
29   canSubmit: () => boolean;
30   children: React.ReactNode;
31   help?: React.ReactNode;
32   isSecondInstance: boolean;
33   onCancel: () => void;
34   onSubmit: () => void;
35 }
36
37 export default function AlmBindingDefinitionFormModalRenderer(
38   props: AlmBindingDefinitionFormModalProps
39 ) {
40   const { action, children, help, isSecondInstance } = props;
41   const header = translate('settings.almintegration.form.header', action);
42
43   return (
44     <SimpleModal header={header} onClose={props.onCancel} onSubmit={props.onSubmit} size="medium">
45       {({ onCloseClick, onFormSubmit, submitting }) => (
46         <form className="views-form" onSubmit={onFormSubmit}>
47           <div className="modal-head">
48             <h2>{header}</h2>
49           </div>
50
51           <div className="modal-body modal-container">
52             {isSecondInstance && action === 'create' && (
53               <Alert className="big-spacer-bottom" variant="warning">
54                 {translate('settings.almintegration.form.second_instance_warning')}
55               </Alert>
56             )}
57
58             <div className="display-flex-start">
59               <div className="flex-1">{children}</div>
60
61               {help && (
62                 <Alert className="huge-spacer-left flex-1" variant="info">
63                   {help}
64                 </Alert>
65               )}
66             </div>
67           </div>
68
69           <div className="modal-foot">
70             <DeferredSpinner className="spacer-right" loading={submitting} />
71             <SubmitButton disabled={submitting || !props.canSubmit()}>
72               {translate('settings.almintegration.form.save')}
73             </SubmitButton>
74             <ResetButtonLink onClick={onCloseClick}>{translate('cancel')}</ResetButtonLink>
75           </div>
76         </form>
77       )}
78     </SimpleModal>
79   );
80 }