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 { ButtonLink } from '../../../../components/controls/buttons';
22 import HelpTooltip from '../../../../components/controls/HelpTooltip';
23 import MandatoryFieldMarker from '../../../../components/ui/MandatoryFieldMarker';
24 import { translate } from '../../../../helpers/l10n';
25 import { AlmBindingDefinitionBase } from '../../../../types/alm-settings';
27 export interface AlmBindingDefinitionFormFieldProps<B extends AlmBindingDefinitionBase> {
29 help?: React.ReactNode;
33 onFieldChange: (id: keyof B, value: string) => void;
35 overwriteOnly?: boolean;
40 export function AlmBindingDefinitionFormField<B extends AlmBindingDefinitionBase>(
41 props: AlmBindingDefinitionFormFieldProps<B>
50 overwriteOnly = false,
54 const [showField, setShowField] = React.useState(!overwriteOnly);
57 <div className="modal-field">
58 <label className="display-flex-center" htmlFor={id}>
59 {translate('settings.almintegration.form', id)}
60 {!optional && <MandatoryFieldMarker />}
61 {help && <HelpTooltip className="spacer-left" overlay={help} placement="right" />}
64 {!showField && overwriteOnly && (
66 <p>{translate('settings.almintegration.form.secret_field')}</p>
69 props.onFieldChange(propKey, '');
72 {translate('settings.almintegration.form.update_secret_field')}
77 {showField && isTextArea && (
79 className="settings-large-input"
81 maxLength={maxLength || 2000}
82 onChange={e => props.onFieldChange(propKey, e.currentTarget.value)}
89 {showField && !isTextArea && (
92 className="input-super-large"
94 maxLength={maxLength || 100}
96 onChange={e => props.onFieldChange(propKey, e.currentTarget.value)}