Skip to content

Commit

Permalink
fix(core/pipeline): Pass Trigger validateFn to the trigger's Formik
Browse files Browse the repository at this point in the history
A trigger type can register a 'validateFn'.
This validateFn is run against its trigger data by the PipelineConfigValidator.
If any errors are found, the little triangle shows up next to the save pipeline button.

However, those same trigger validation errors didn't show up on the form fields themselves.
This PR wires the validateFn into the Trigger's Formik validate prop.
Validation is run twice (once by formik, once by PipelineConfigValidator).
Not ideal, but acceptable.
  • Loading branch information
christopherthielen committed Oct 10, 2019
1 parent d0777fa commit 36192ab
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions app/scripts/modules/core/src/pipeline/config/triggers/Trigger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,22 @@ export interface ITriggerProps {
updateTrigger: (index: number, changes: { [key: string]: any }) => void;
}

export const Trigger = (props: ITriggerProps) => (
<SpinFormik
onSubmit={() => null}
initialValues={props.trigger}
render={formik => <TriggerForm {...props} formik={formik} />}
/>
);
export const Trigger = (props: ITriggerProps) => {
function getValidateFn() {
const triggerType = Registry.pipeline.getTriggerTypes().find(type => type.key === props.trigger.type);
const validateWithContext = (values: ITrigger) => triggerType.validateFn(values, { pipeline: props.pipeline });
return triggerType && triggerType.validateFn ? validateWithContext : undefined;
}

return (
<SpinFormik<ITrigger>
onSubmit={() => null}
initialValues={props.trigger}
validate={getValidateFn()}
render={formik => <TriggerForm {...props} formik={formik} />}
/>
);
};

const commonTriggerFields: Array<keyof ITrigger> = [
'enabled',
Expand Down

0 comments on commit 36192ab

Please sign in to comment.