mirror of
https://github.com/ansible/awx.git
synced 2026-05-08 01:47:35 -02:30
fix multiple notification form bugs
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { useFormikContext } from 'formik';
|
import { useFormikContext } from 'formik';
|
||||||
import { Alert } from '@patternfly/react-core';
|
import { Alert } from '@patternfly/react-core';
|
||||||
|
import { FormFullWidthLayout } from '../FormLayout';
|
||||||
|
|
||||||
const findErrorStrings = (obj, messages = []) => {
|
const findErrorStrings = (obj, messages = []) => {
|
||||||
if (typeof obj === 'string') {
|
if (typeof obj === 'string') {
|
||||||
@@ -35,7 +36,13 @@ function FormSubmitError({ error }) {
|
|||||||
typeof error.response.data === 'object' &&
|
typeof error.response.data === 'object' &&
|
||||||
Object.keys(error.response.data).length > 0
|
Object.keys(error.response.data).length > 0
|
||||||
) {
|
) {
|
||||||
const errorMessages = error.response.data;
|
const errorMessages = {};
|
||||||
|
Object.keys(error.response.data).forEach(fieldName => {
|
||||||
|
const errors = error.response.data[fieldName];
|
||||||
|
if (errors && errors.length) {
|
||||||
|
errorMessages[fieldName] = errors.join(' ');
|
||||||
|
}
|
||||||
|
});
|
||||||
setErrors(errorMessages);
|
setErrors(errorMessages);
|
||||||
|
|
||||||
const messages = findErrorStrings(error.response.data);
|
const messages = findErrorStrings(error.response.data);
|
||||||
@@ -52,15 +59,17 @@ function FormSubmitError({ error }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Alert
|
<FormFullWidthLayout>
|
||||||
variant="danger"
|
<Alert
|
||||||
isInline
|
variant="danger"
|
||||||
title={
|
isInline
|
||||||
Array.isArray(errorMessage)
|
title={
|
||||||
? errorMessage.map(msg => <div key={msg}>{msg}</div>)
|
Array.isArray(errorMessage)
|
||||||
: errorMessage
|
? errorMessage.map(msg => <div key={msg}>{msg}</div>)
|
||||||
}
|
: errorMessage
|
||||||
/>
|
}
|
||||||
|
/>
|
||||||
|
</FormFullWidthLayout>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,12 +54,13 @@ function NotificationTemplateFormFields({ i18n, defaultMessages }) {
|
|||||||
fieldId="notification-type"
|
fieldId="notification-type"
|
||||||
helperTextInvalid={typeMeta.error}
|
helperTextInvalid={typeMeta.error}
|
||||||
isRequired
|
isRequired
|
||||||
validated={!typeMeta.touched || typeMeta.error ? 'default' : 'error'}
|
validated={!typeMeta.touched || !typeMeta.error ? 'default' : 'error'}
|
||||||
label={i18n._(t`Type`)}
|
label={i18n._(t`Type`)}
|
||||||
>
|
>
|
||||||
<AnsibleSelect
|
<AnsibleSelect
|
||||||
{...typeField}
|
{...typeField}
|
||||||
id="notification-type"
|
id="notification-type"
|
||||||
|
isValid={!typeMeta.touched || !typeMeta.error}
|
||||||
data={[
|
data={[
|
||||||
{
|
{
|
||||||
value: '',
|
value: '',
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import {
|
|||||||
required,
|
required,
|
||||||
requiredEmail,
|
requiredEmail,
|
||||||
url,
|
url,
|
||||||
|
minMaxValue,
|
||||||
} from '../../../util/validators';
|
} from '../../../util/validators';
|
||||||
import { NotificationType } from '../../../types';
|
import { NotificationType } from '../../../types';
|
||||||
|
|
||||||
@@ -104,16 +105,17 @@ function EmailFields({ i18n }) {
|
|||||||
label={i18n._(t`Port`)}
|
label={i18n._(t`Port`)}
|
||||||
name="notification_configuration.port"
|
name="notification_configuration.port"
|
||||||
type="number"
|
type="number"
|
||||||
validate={required(null, i18n)}
|
validate={combine([required(null, i18n), minMaxValue(1, 65535, i18n)])}
|
||||||
isRequired
|
isRequired
|
||||||
min="0"
|
min="0"
|
||||||
|
max="65535"
|
||||||
/>
|
/>
|
||||||
<FormField
|
<FormField
|
||||||
id="email-timeout"
|
id="email-timeout"
|
||||||
label={i18n._(t`Timeout`)}
|
label={i18n._(t`Timeout`)}
|
||||||
name="notification_configuration.timeout"
|
name="notification_configuration.timeout"
|
||||||
type="number"
|
type="number"
|
||||||
validate={required(null, i18n)}
|
validate={combine([required(null, i18n), minMaxValue(1, 120, i18n)])}
|
||||||
isRequired
|
isRequired
|
||||||
min="1"
|
min="1"
|
||||||
max="120"
|
max="120"
|
||||||
@@ -306,7 +308,7 @@ function PagerdutyFields({ i18n }) {
|
|||||||
label={i18n._(t`Pagerduty subdomain`)}
|
label={i18n._(t`Pagerduty subdomain`)}
|
||||||
name="notification_configuration.subdomain"
|
name="notification_configuration.subdomain"
|
||||||
type="text"
|
type="text"
|
||||||
validate={required(i18n)}
|
validate={required(null, i18n)}
|
||||||
isRequired
|
isRequired
|
||||||
/>
|
/>
|
||||||
<FormField
|
<FormField
|
||||||
@@ -314,7 +316,7 @@ function PagerdutyFields({ i18n }) {
|
|||||||
label={i18n._(t`API service/integration key`)}
|
label={i18n._(t`API service/integration key`)}
|
||||||
name="notification_configuration.service_key"
|
name="notification_configuration.service_key"
|
||||||
type="text"
|
type="text"
|
||||||
validate={required(i18n)}
|
validate={required(null, i18n)}
|
||||||
isRequired
|
isRequired
|
||||||
/>
|
/>
|
||||||
<FormField
|
<FormField
|
||||||
@@ -322,7 +324,7 @@ function PagerdutyFields({ i18n }) {
|
|||||||
label={i18n._(t`Client identifier`)}
|
label={i18n._(t`Client identifier`)}
|
||||||
name="notification_configuration.client_name"
|
name="notification_configuration.client_name"
|
||||||
type="text"
|
type="text"
|
||||||
validate={required(i18n)}
|
validate={required(null, i18n)}
|
||||||
isRequired
|
isRequired
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -48,7 +48,8 @@ export default typeFieldNames;
|
|||||||
const initialConfigValues = {};
|
const initialConfigValues = {};
|
||||||
Object.keys(typeFieldNames).forEach(key => {
|
Object.keys(typeFieldNames).forEach(key => {
|
||||||
typeFieldNames[key].forEach(fieldName => {
|
typeFieldNames[key].forEach(fieldName => {
|
||||||
initialConfigValues[fieldName] = '';
|
const isBoolean = fieldName.includes('_ssl');
|
||||||
|
initialConfigValues[fieldName] = isBoolean ? false : '';
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -78,6 +78,9 @@ export function integer(i18n) {
|
|||||||
|
|
||||||
export function url(i18n) {
|
export function url(i18n) {
|
||||||
return value => {
|
return value => {
|
||||||
|
if (!value) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
// URL regex from https://urlregex.com/
|
// URL regex from https://urlregex.com/
|
||||||
if (
|
if (
|
||||||
// eslint-disable-next-line max-len
|
// eslint-disable-next-line max-len
|
||||||
|
|||||||
Reference in New Issue
Block a user