Skip to content
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

Handle validation of list inputs #31

Merged
merged 6 commits into from
Dec 20, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Changing the way validation works so we don't generate a form error
  • Loading branch information
schottra committed Dec 19, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit ff0fbecd44447cae38f08983633fce6f72eb3bfa
Original file line number Diff line number Diff line change
@@ -82,6 +82,7 @@ function getInputs(workflow: Workflow, launchPlan: LaunchPlan): ParsedInput[] {
interface FormInputsState {
inputs: InputProps[];
getValues(): Record<string, Core.ILiteral>;
validate(): boolean;
}

// TODO: This could be made generic and composed with ParsedInput
@@ -104,19 +105,13 @@ function useFormInputsState(parsedInputs: ParsedInput[]): FormInputsState {
const validationErrors = validateFormInputs(inputs);
if (Object.keys(validationErrors).length) {
setErrors(validationErrors);
throw new ValidationError(
Object.keys(errors).map(
name => new ParameterError(name, errors[name].message)
)
);
return false;
}
setErrors({});
return true;
};

const getValues = () => {
validate();
return convertFormInputsToLiterals(inputs);
};
const getValues = () => convertFormInputsToLiterals(inputs);

useEffect(() => {
// TODO: Use default values from inputs
@@ -125,7 +120,8 @@ function useFormInputsState(parsedInputs: ParsedInput[]): FormInputsState {

return {
inputs,
getValues
getValues,
validate
};
}

@@ -225,7 +221,7 @@ export function useLaunchWorkflowFormState({
const inputLoadingState = waitForAllFetchables([workflow, launchPlans]);

const [parsedInputs, setParsedInputs] = useState<ParsedInput[]>([]);
const { inputs, getValues } = useFormInputsState(parsedInputs);
const { inputs, getValues, validate } = useFormInputsState(parsedInputs);
const workflowName = workflowId.name;

const onSelectWorkflow = (
@@ -242,12 +238,11 @@ export function useLaunchWorkflowFormState({
const launchPlanId = launchPlanData.id;
const { domain, project } = workflowId;

const literals = getValues();
const response = await createWorkflowExecution({
domain,
launchPlanId,
project,
inputs: { literals }
inputs: { literals: getValues() }
});
const newExecutionId = response.id as WorkflowExecutionIdentifier;
if (!newExecutionId) {
@@ -264,7 +259,14 @@ export function useLaunchWorkflowFormState({
doFetch: launchWorkflow
});

const onSubmit = submissionState.fetch;
const onSubmit = () => {
// We validate separately so that a request isn't triggered unless
// the inputs are valid.
if (!validate()) {
return;
}
submissionState.fetch();
};
const onCancel = onClose;

useEffect(() => {