import type { FormikProps } from 'formik'; import React from 'react'; import type { IParameter, IPipelineCommand } from '../../domain'; import { HelpField } from '../../help'; import { DayPickerInput, FormikFormField, ReactSelectInput, TextInput } from '../../presentation'; export interface IParametersProps { formik: FormikProps; parameters: IParameter[]; } export class Parameters extends React.Component { private shouldInclude = (p: IParameter) => { const { values } = this.props.formik; if (p.conditional) { const comparingTo = values.parameters[p.conditional.parameter]; const value = p.conditional.comparatorValue; switch (p.conditional.comparator) { case '>': return parseFloat(comparingTo) > parseFloat(value); case '>=': return parseFloat(comparingTo) >= parseFloat(value); case '<': return parseFloat(comparingTo) < parseFloat(value); case '<=': return parseFloat(comparingTo) <= parseFloat(value); case '!=': return comparingTo !== value; case '=': return comparingTo === value; } } return true; }; public render() { const { parameters } = this.props; const hasRequiredParameters = parameters.some((p) => p.required); const visibleParameters = parameters.filter((p) => !p.conditional || this.shouldInclude(p)); /* We need to use bracket notation because parameter names are strings that can have all sorts of characters */ const formikFieldNameForParam = (param: IParameter) => `parameters["${param.name}"]`; return ( <>

This pipeline is parameterized. Please enter values for the parameters below.

{visibleParameters && visibleParameters.map((parameter, i) => { const fieldProps = { name: formikFieldNameForParam(parameter), label: parameter.label || parameter.name, help: parameter.description && , fastField: false, required: parameter.required, }; return ( {!parameter.hasOptions && parameter.constraint === 'date' && ( } /> )} {!parameter.hasOptions && !parameter.constraint && ( } /> )} {parameter.hasOptions && ( ( ({ label: `${o.value}`, value: o.value }))} /> )} /> )} ); })} {hasRequiredParameters && (
* Required
)} ); } }