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 'sonar-ui-common/components/controls/buttons';
22 import HelpTooltip from 'sonar-ui-common/components/controls/HelpTooltip';
23 import { translate } from 'sonar-ui-common/helpers/l10n';
24 import { AlmBindingDefinition } from '../../../../types/alm-settings';
26 export interface AlmBindingDefinitionFormFieldProps<B extends AlmBindingDefinition> {
28 help?: React.ReactNode;
32 onFieldChange: (id: keyof B, value: string) => void;
34 overwriteOnly?: boolean;
39 export function AlmBindingDefinitionFormField<B extends AlmBindingDefinition>(
40 props: AlmBindingDefinitionFormFieldProps<B>
49 overwriteOnly = false,
53 const [showField, setShowField] = React.useState(!overwriteOnly);
56 <div className="modal-field">
57 <label className="display-flex-center" htmlFor={id}>
58 {translate('settings.almintegration.form', id)}
59 {!optional && <em className="mandatory">*</em>}
60 {help && <HelpTooltip className="spacer-left" overlay={help} placement="right" />}
63 {!showField && overwriteOnly && (
65 <p>{translate('settings.almintegration.form.secret_field')}</p>
68 props.onFieldChange(propKey, '');
71 {translate('settings.almintegration.form.update_secret_field')}
76 {showField && isTextArea && (
78 className="settings-large-input"
80 maxLength={maxLength || 2000}
81 onChange={e => props.onFieldChange(propKey, e.currentTarget.value)}
88 {showField && !isTextArea && (
91 className="input-super-large"
93 maxLength={maxLength || 100}
95 onChange={e => props.onFieldChange(propKey, e.currentTarget.value)}