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 { FormattedMessage } from 'react-intl';
22 import DocLink from '../../../../components/common/DocLink';
23 import { ButtonLink } from '../../../../components/controls/buttons';
24 import ValidationInput, {
25 ValidationInputErrorPlacement,
26 } from '../../../../components/controls/ValidationInput';
27 import { Alert } from '../../../../components/ui/Alert';
28 import MandatoryFieldMarker from '../../../../components/ui/MandatoryFieldMarker';
29 import { translate } from '../../../../helpers/l10n';
30 import { AlmBindingDefinitionBase } from '../../../../types/alm-settings';
31 import '../../styles.css';
33 export interface AlmBindingDefinitionFormFieldProps<B extends AlmBindingDefinitionBase> {
36 help?: React.ReactNode;
41 onFieldChange: (id: keyof B, value: string) => void;
43 overwriteOnly?: boolean;
49 export function AlmBindingDefinitionFormField<B extends AlmBindingDefinitionBase>(
50 props: AlmBindingDefinitionFormFieldProps<B>
61 overwriteOnly = false,
66 const [showField, setShowField] = React.useState(!overwriteOnly);
69 <div className="settings-definition">
70 <div className="settings-definition-left">
71 <label className="h3" htmlFor={id}>
72 {translate('settings.almintegration.form', id)}
74 {!optional && <MandatoryFieldMarker />}
75 {help && <div className="markdown small spacer-top">{help}</div>}
77 <div className="settings-definition-right big-padded-top display-flex-column">
78 {!showField && overwriteOnly && (
80 <p>{translate('settings.almintegration.form.secret.field')}</p>
83 props.onFieldChange(propKey, '');
87 {translate('settings.almintegration.form.secret.update_field')}
92 {showField && isTextArea && (
96 maxLength={maxLength || 2000}
97 onChange={(e) => props.onFieldChange(propKey, e.currentTarget.value)}
104 {showField && !isTextArea && (
107 errorPlacement={ValidationInputErrorPlacement.Bottom}
109 isInvalid={isInvalid}
112 className="width-100"
113 autoFocus={autoFocus}
115 maxLength={maxLength || 100}
117 onChange={(e) => props.onFieldChange(propKey, e.currentTarget.value)}
125 {showField && isSecret && (
126 <Alert variant="info" className="spacer-top">
128 id="settings.almintegration.form.secret.can_encrypt"
129 defaultMessage={translate('settings.almintegration.form.secret.can_encrypt')}
132 <DocLink to="/instance-administration/security/#settings-encryption">
133 {translate('learn_more')}