New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #32667 - add job wizard form validation #622
Fixes #32667 - add job wizard form validation #622
Conversation
426cb76
to
8d9fe27
Compare
8d9fe27
to
9ec5acd
Compare
@LaViro can you take a look please? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @MariaAga !
setJobTemplate( | ||
Number(filterJobTemplates(response?.data?.results)[0]?.id) || null | ||
), | ||
); | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just curious, did it change something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure, I think it was just "more correct" for it not to return the value
@@ -18,3 +18,7 @@ export const helpLabel = (text, id) => { | |||
</Popover> | |||
); | |||
}; | |||
|
|||
export const isPostiveNumber = number => /^\d+$/.test(number); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export const isPostiveNumber = number => /^\d+$/.test(number); | |
export const isPositiveNumber = number => /^\d+$/.test(number); |
also, can't we use parseInt(textWithNumber) > 0
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch, also changed to the suggestion
inputValidation(templateInputs, templateValues, () => | ||
setValid(currValid => ({ ...currValid, hostsAndInputs: false })) | ||
); | ||
|
||
inputValidation(advancedTemplateInputs, advancedValues.templateValues, () => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that we run twice the inputValidation
,
can we combine advancedValues
& templateValues
and then run inputValidation
once?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why should we combine them? They just run forEach
on the input so there is no duplicate code running. also they set different values on invalid
d789959
to
a35dc20
Compare
else setValidEnd(false); | ||
}, [starts, ends, isNeverEnds]); | ||
useEffect(() => { | ||
setValid(validEnd); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if eventually we update setValid
with validEnd
, do we really need to manage a state for validEnd
? or can we just use setValid
?
@@ -116,23 +126,32 @@ export const JobWizard = () => { | |||
jobTemplateID={jobTemplateID} | |||
/> | |||
), | |||
canJumpTo: isTemplate, | |||
canJumpTo: isTemplate && valid.hostsAndInputs, | |||
enableNext: isTemplate && valid.hostsAndInputs && valid.advanced, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the user got here, it probably means that valid.hostsAndInputs
is true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But a user can go a step back and enter invalid values
canJumpTo: | ||
isTemplate && valid.hostsAndInputs && valid.advanced && valid.schedule, | ||
enableNext: | ||
isTemplate && valid.hostsAndInputs && valid.advanced && valid.schedule, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, I think that for clicking next / run we can check just for the validity of the step itself
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [advancedValues, templateValues]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should it be:
// eslint-disable-next-line react-hooks/exhaustive-deps | |
}, [advancedValues, templateValues]); | |
}, [advancedValues, templateValues, advancedTemplateInputs, templateInputs]); | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On initial load this causes the useEffect to be called 23 times instead of 3.
There is no need to re check validation if the values didn't change as we are validating the values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since the data is being based on advancedTemplateInputs & templateInputs
if they change I guess re-validation should happen as well. does it happen because they are objects? maybe we need to useMemo
for them? I think @amirfefer faced a similar issue with the API hook in foreman.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They only change when the a new template is fetched, and when that happens advancedValues
is changed every time when setting defaults.
a35dc20
to
10f127b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @MariaAga, everything seems great, can you just rebase?
10f127b
to
d8a25c2
Compare
Thanks @LaViro, rebased! |
@adamruzicka can you take a look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine
Depends on: #556Doesn't include schedule validation yet