Skip to content

Commit

Permalink
edit-workflow: Fix validation on first edit
Browse files Browse the repository at this point in the history
  • Loading branch information
JBWatenbergScality committed Apr 14, 2022
1 parent a30a6fc commit 33f61f1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
1 change: 0 additions & 1 deletion src/react/workflow/ConfigurationTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ function EditForm({
bucketList: S3BucketList;
locations: Locations;
}) {
const history = useHistory();
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);

const schema =
Expand Down
11 changes: 9 additions & 2 deletions src/react/workflow/ExpirationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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`);
}}
/>
);
}}
Expand Down Expand Up @@ -210,6 +213,10 @@ export function ExpirationForm({ bucketList, locations, prefix = '' }: Props) {
<Input
id="prefix"
{...register(`${prefix}filter.objectKeyPrefix`)}
onChange={(evt) => {
register(`${prefix}filter.objectKeyPrefix`).onChange(evt);
trigger(`${prefix}filter.objectKeyPrefix`);
}}
aria-invalid={!!errors[`${prefix}filter.objectKeyPrefix`]}
aria-describedby="error-prefix"
autoComplete="off"
Expand Down
22 changes: 14 additions & 8 deletions src/react/workflow/ReplicationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function ReplicationComponent({
register,
control,
getValues,

trigger,
formState: { errors: formErrors },
} = useFormContext();
const errors = flattenFormErrors(formErrors);
Expand Down Expand Up @@ -134,7 +134,10 @@ function ReplicationComponent({
toggle={enabled}
id="enabled"
label={enabled ? 'Active' : 'Inactive'}
onChange={() => onChange(!enabled)}
onChange={() => {
onChange(!enabled);
trigger(`${prefix}enabled`);
}}
/>
);
}}
Expand Down Expand Up @@ -264,12 +267,15 @@ function ReplicationComponent({
<Select
id="destinationLocation"
onChange={onChange}
options={options}
formatOptionLabel={renderDestination(locations)}
value={options.find(
(l) => l.value === destinationLocation?.value,
)}
/>
value={destinationLocation}
>
{options &&
options.map((o, i) => (
<Option key={i} value={o.value}>
{renderDestination(locations)(o)}
</Option>
))}
</Select>
);
}}
/>
Expand Down
10 changes: 4 additions & 6 deletions src/react/workflow/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,10 @@ export const renderSource = (locations: Locations) => {
};
export const renderDestination = (locations: Locations) => {
return function does(option: SelectOption) {
return (
<div>
<span> {option.label} </span>
<small> ({getLocationTypeShort(option.value, locations)}) </small>
</div>
);
return `${option.label} (${getLocationTypeShort(
option.value,
locations,
)})`
};
};
export function newExpiration(bucketName?: string): Expiration {
Expand Down

0 comments on commit 33f61f1

Please sign in to comment.