From ad9461f52a05c4519daca75d24f5c8972f4fdba7 Mon Sep 17 00:00:00 2001 From: guillaume-peoch-sonarsource Date: Tue, 23 Jan 2024 17:41:31 +0100 Subject: [PATCH] SONAR-21480 AuthenticationFormField + configuration panels (GH, GL, SAML) --- .../AuthenticationFormField.tsx | 62 +++++--- .../AuthenticationMultiValuesField.tsx | 13 +- .../AuthenticationSecuredField.tsx | 18 +-- .../AuthenticationToggleField.tsx | 10 +- .../authentication/ConfigurationForm.tsx | 134 +++++++++--------- .../GitLabConfigurationForm.tsx | 118 +++++++-------- .../GithubAuthenticationTab.tsx | 2 +- .../__tests__/Authentication-Github-it.tsx | 2 +- .../__tests__/Authentication-Gitlab-it.tsx | 4 +- 9 files changed, 191 insertions(+), 172 deletions(-) diff --git a/server/sonar-web/src/main/js/apps/settings/components/authentication/AuthenticationFormField.tsx b/server/sonar-web/src/main/js/apps/settings/components/authentication/AuthenticationFormField.tsx index 244705fad3f..dc21f8ca35a 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/authentication/AuthenticationFormField.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/authentication/AuthenticationFormField.tsx @@ -17,16 +17,18 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +import styled from '@emotion/styled'; +import { FormField, Highlight, InputField, Note, RequiredIcon } from 'design-system'; import React from 'react'; +import { useIntl } from 'react-intl'; import ValidationInput, { ValidationInputErrorPlacement, } from '../../../../components/controls/ValidationInput'; import { DefinitionV2, ExtendedSettingDefinition, SettingType } from '../../../../types/settings'; import { getPropertyDescription, getPropertyName, isSecuredDefinition } from '../../utils'; -import AuthenticationFormFieldWrapper from './AuthenticationFormFieldWrapper'; import AuthenticationMultiValueField from './AuthenticationMultiValuesField'; import AuthenticationSecuredField from './AuthenticationSecuredField'; -import AuthenticationToggleField from './AuthenticationToggleField'; +import AuthenticationToggleFormField from './AuthenticationToggleField'; interface Props { settingValue?: string | boolean | string[]; @@ -40,15 +42,44 @@ interface Props { export default function AuthenticationFormField(props: Readonly) { const { mandatory = false, definition, settingValue, isNotSet, error } = props; + const intl = useIntl(); + const name = getPropertyName(definition); const description = getPropertyDescription(definition); + if (!isSecuredDefinition(definition) && definition.type === SettingType.BOOLEAN) { + return ( + <> +
+ + + {name} + {mandatory && ( + + )} + + + props.onFieldChange(definition.key, value)} + /> +
+ {description && {description}} + + ); + } + return ( - {definition.multiValues && ( ) { isNotSet={isNotSet} /> )} - {!isSecuredDefinition(definition) && definition.type === SettingType.BOOLEAN && ( - props.onFieldChange(definition.key, value)} - /> - )} {!isSecuredDefinition(definition) && definition.type === undefined && !definition.multiValues && ( @@ -81,8 +105,8 @@ export default function AuthenticationFormField(props: Readonly) { isValid={false} isInvalid={Boolean(error)} > - ) { /> )} - + ); } + +// This is needed to prevent the target input/button from being focused +// when clicking/hovering on the label. More info https://stackoverflow.com/questions/9098581/why-is-hover-for-input-triggered-on-corresponding-label-in-css +const StyledLabel = styled.label` + pointer-events: none; +`; diff --git a/server/sonar-web/src/main/js/apps/settings/components/authentication/AuthenticationMultiValuesField.tsx b/server/sonar-web/src/main/js/apps/settings/components/authentication/AuthenticationMultiValuesField.tsx index e3bcc9a384b..d10f23ab05d 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/authentication/AuthenticationMultiValuesField.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/authentication/AuthenticationMultiValuesField.tsx @@ -17,8 +17,8 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +import { DestructiveIcon, InputField, TrashIcon } from 'design-system'; import * as React from 'react'; -import { DeleteButton } from '../../../../components/controls/buttons'; import { translateWithParameters } from '../../../../helpers/l10n'; import { DefinitionV2, ExtendedSettingDefinition } from '../../../../types/settings'; import { getPropertyName } from '../../utils'; @@ -52,10 +52,10 @@ export default function AuthenticationMultiValueField(props: Props) { {displayValue.map((value, index) => { const isNotLast = index !== displayValue.length - 1; return ( -
  • - + handleSingleInputChange(index, e.currentTarget.value)} @@ -64,8 +64,9 @@ export default function AuthenticationMultiValueField(props: Props) { /> {isNotLast && ( -
    - + {!showSecretField && (definition.type === SettingType.TEXT ? ( -