From 33f61f1cf5a239815ea6692a8f5495ebf35b6c88 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste WATENBERG Date: Thu, 14 Apr 2022 17:29:44 +0200 Subject: [PATCH] edit-workflow: Fix validation on first edit --- src/react/workflow/ConfigurationTab.tsx | 1 - src/react/workflow/ExpirationForm.tsx | 11 +++++++++-- src/react/workflow/ReplicationForm.tsx | 22 ++++++++++++++-------- src/react/workflow/utils.tsx | 10 ++++------ 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/react/workflow/ConfigurationTab.tsx b/src/react/workflow/ConfigurationTab.tsx index 13c255268..af047524e 100644 --- a/src/react/workflow/ConfigurationTab.tsx +++ b/src/react/workflow/ConfigurationTab.tsx @@ -290,7 +290,6 @@ function EditForm({ bucketList: S3BucketList; locations: Locations; }) { - const history = useHistory(); const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false); const schema = diff --git a/src/react/workflow/ExpirationForm.tsx b/src/react/workflow/ExpirationForm.tsx index b2550de22..d9670b32d 100644 --- a/src/react/workflow/ExpirationForm.tsx +++ b/src/react/workflow/ExpirationForm.tsx @@ -86,7 +86,7 @@ export const expirationSchema = Joi.object({ ); export function ExpirationForm({ bucketList, locations, prefix = '' }: Props) { - const { register, control, watch, getValues, setValue, formState } = + const { register, control, watch, getValues, setValue, formState, trigger } = useFormContext(); const { errors: formErrors } = formState; @@ -140,7 +140,10 @@ export function ExpirationForm({ bucketList, locations, prefix = '' }: Props) { id="enabled" toggle={enabled} label={enabled ? 'Active' : 'Inactive'} - onChange={() => onChange(!enabled)} + onChange={() => { + onChange(!enabled); + trigger(`${prefix}enabled`); + }} /> ); }} @@ -210,6 +213,10 @@ export function ExpirationForm({ bucketList, locations, prefix = '' }: Props) { { + register(`${prefix}filter.objectKeyPrefix`).onChange(evt); + trigger(`${prefix}filter.objectKeyPrefix`); + }} aria-invalid={!!errors[`${prefix}filter.objectKeyPrefix`]} aria-describedby="error-prefix" autoComplete="off" diff --git a/src/react/workflow/ReplicationForm.tsx b/src/react/workflow/ReplicationForm.tsx index 705f764b8..23e24cea5 100644 --- a/src/react/workflow/ReplicationForm.tsx +++ b/src/react/workflow/ReplicationForm.tsx @@ -74,7 +74,7 @@ function ReplicationComponent({ register, control, getValues, - + trigger, formState: { errors: formErrors }, } = useFormContext(); const errors = flattenFormErrors(formErrors); @@ -134,7 +134,10 @@ function ReplicationComponent({ toggle={enabled} id="enabled" label={enabled ? 'Active' : 'Inactive'} - onChange={() => onChange(!enabled)} + onChange={() => { + onChange(!enabled); + trigger(`${prefix}enabled`); + }} /> ); }} @@ -264,12 +267,15 @@ function ReplicationComponent({ ); }} /> diff --git a/src/react/workflow/utils.tsx b/src/react/workflow/utils.tsx index 56f1dd67d..1755d801c 100644 --- a/src/react/workflow/utils.tsx +++ b/src/react/workflow/utils.tsx @@ -63,12 +63,10 @@ export const renderSource = (locations: Locations) => { }; export const renderDestination = (locations: Locations) => { return function does(option: SelectOption) { - return ( -
- {option.label} - ({getLocationTypeShort(option.value, locations)}) -
- ); + return `${option.label} (${getLocationTypeShort( + option.value, + locations, + )})` }; }; export function newExpiration(bucketName?: string): Expiration {