import clsx from 'clsx'; import { FormikErrors } from 'formik'; import { FormSection } from '@@/form-components/FormSection'; import { InputList } from '@@/form-components/InputList'; import { ItemProps } from '@@/form-components/InputList/InputList'; import { isErrorType } from '@@/form-components/formikUtils'; import { FormError } from '@@/form-components/FormError'; import { InputGroup } from '@@/form-components/InputGroup'; import { Option, PortainerSelect } from '@@/form-components/PortainerSelect'; import { TaintEffect } from '../../types'; import { NodeTaint } from './types'; import { createNewTaint } from './nodeFormUtils'; interface Props { taints: NodeTaint[]; errors: FormikErrors; onChangeTaints: (taints: NodeTaint[]) => void; hasNodeWriteAccess: boolean; } const taintEffectOptions: Option[] = [ { label: 'NoSchedule', value: 'NoSchedule' }, { label: 'PreferNoSchedule', value: 'PreferNoSchedule' }, { label: 'NoExecute', value: 'NoExecute' }, ]; export function NodeTaints({ taints, onChangeTaints, errors, hasNodeWriteAccess, }: Props) { return ( value={taints} onChange={onChangeTaints} data-cy="node-taints-input" item={NodeTaintItem} addLabel="Add taint" canUndoDelete itemBuilder={createNewTaint} errors={errors} readOnly={!hasNodeWriteAccess} /> ); } function NodeTaintItem({ onChange, item, error, disabled, readOnly, index, }: ItemProps) { const formikError = isErrorType(error) ? error : undefined; return (
Key handleChange('key', e.target.value)} disabled={disabled} readOnly={readOnly} type="text" data-cy={`node-taint-key-input_${index}`} /> {!!formikError?.key && {formikError.key}}
Value handleChange('value', e.target.value)} disabled={disabled} readOnly={readOnly} type="text" data-cy={`node-taint-value-input_${index}`} /> {!!formikError?.value && {formikError.value}}
Effect handleChange('effect', value as TaintEffect)} options={taintEffectOptions} disabled={disabled || readOnly} data-cy={`node-taint-effect-select_${index}`} // className={clsx(item.needsDeletion && 'striked')} size="sm" /> {!!formikError?.effect && {formikError.effect}}
); function handleChange(key: keyof NodeTaint, value: string | TaintEffect) { onChange({ ...item, [key]: value, isChanged: true }); } }