Skip to content

Commit

Permalink
allow empty/null user and password in UI
Browse files Browse the repository at this point in the history
  • Loading branch information
pmuellr committed Mar 23, 2020
1 parent 9dcc8c7 commit 3eda5fe
Showing 1 changed file with 12 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,26 +97,6 @@ export function getActionType(): ActionTypeModel {
)
);
}
if (!action.secrets.user) {
errors.user.push(
i18n.translate(
'xpack.triggersActionsUI.components.builtinActionTypes.error.requiredUserText',
{
defaultMessage: 'Username is required.',
}
)
);
}
if (!action.secrets.password) {
errors.password.push(
i18n.translate(
'xpack.triggersActionsUI.components.builtinActionTypes.error.requiredPasswordText',
{
defaultMessage: 'Password is required.',
}
)
);
}
return validationResult;
},
validateParams: (actionParams: EmailActionParams): ValidationResult => {
Expand Down Expand Up @@ -303,7 +283,7 @@ const EmailActionConnectorFields: React.FunctionComponent<ActionConnectorFieldsP
id="emailUser"
fullWidth
error={errors.user}
isInvalid={errors.user.length > 0 && user !== undefined}
isInvalid={errors.user.length > 0}
label={i18n.translate(
'xpack.triggersActionsUI.sections.builtinActionTypes.emailAction.userTextFieldLabel',
{
Expand All @@ -313,17 +293,12 @@ const EmailActionConnectorFields: React.FunctionComponent<ActionConnectorFieldsP
>
<EuiFieldText
fullWidth
isInvalid={errors.user.length > 0 && user !== undefined}
isInvalid={errors.user.length > 0}
name="user"
value={user || ''}
data-test-subj="emailUserInput"
onChange={e => {
editActionSecrets('user', e.target.value);
}}
onBlur={() => {
if (!user) {
editActionSecrets('user', '');
}
editActionSecrets('user', nullableString(e.target.value));
}}
/>
</EuiFormRow>
Expand All @@ -333,7 +308,7 @@ const EmailActionConnectorFields: React.FunctionComponent<ActionConnectorFieldsP
id="emailPassword"
fullWidth
error={errors.password}
isInvalid={errors.password.length > 0 && password !== undefined}
isInvalid={errors.password.length > 0}
label={i18n.translate(
'xpack.triggersActionsUI.sections.builtinActionTypes.emailAction.passwordFieldLabel',
{
Expand All @@ -343,17 +318,12 @@ const EmailActionConnectorFields: React.FunctionComponent<ActionConnectorFieldsP
>
<EuiFieldPassword
fullWidth
isInvalid={errors.password.length > 0 && password !== undefined}
isInvalid={errors.password.length > 0}
name="password"
value={password || ''}
data-test-subj="emailPasswordInput"
onChange={e => {
editActionSecrets('password', e.target.value);
}}
onBlur={() => {
if (!password) {
editActionSecrets('password', '');
}
editActionSecrets('password', nullableString(e.target.value));
}}
/>
</EuiFormRow>
Expand Down Expand Up @@ -624,3 +594,9 @@ const EmailParamsFields: React.FunctionComponent<ActionParamsProps<EmailActionPa
</Fragment>
);
};

// if the string == null or is empty, return null, else return string
function nullableString(str: string | null | undefined) {
if (str == null || str.trim() === '') return null;
return str;
}

0 comments on commit 3eda5fe

Please sign in to comment.