import { FormikErrors } from 'formik'; import { ChangeEvent } from 'react'; import { Plus, Trash2 } from 'lucide-react'; import { FormError } from '@@/form-components/FormError'; import { ButtonSelector } from '@@/form-components/ButtonSelector/ButtonSelector'; import { Button } from '@@/buttons'; import { isServicePortError, newPort } from './utils'; import { ServicePort } from './types'; import { ServicePortInput } from './ServicePortInput'; import { ContainerPortInput } from './ContainerPortInput'; interface Props { values: ServicePort[]; onChange: (servicePorts: ServicePort[]) => void; serviceName?: string; errors?: string | string[] | FormikErrors[]; } export function ClusterIpForm({ values: servicePorts, onChange, errors, serviceName, }: Props) { const newClusterIpPort = newPort(serviceName); return ( <>
Published ports
{servicePorts.map((servicePort, index) => { const error = errors?.[index]; const servicePortError = isServicePortError(error) ? error : undefined; return (
) => { const newServicePorts = [...servicePorts]; const newValue = e.target.value === '' ? undefined : Number(e.target.value); newServicePorts[index] = { ...newServicePorts[index], targetPort: newValue, port: newValue, }; onChange(newServicePorts); }} /> {servicePortError?.targetPort && ( {servicePortError.targetPort} )}
) => { const newServicePorts = [...servicePorts]; newServicePorts[index] = { ...newServicePorts[index], port: e.target.value === '' ? undefined : Number(e.target.value), }; onChange(newServicePorts); }} /> {servicePortError?.port && ( {servicePortError.port} )}
{ const newServicePorts = [...servicePorts]; newServicePorts[index] = { ...newServicePorts[index], protocol: value, }; onChange(newServicePorts); }} value={servicePort.protocol || 'TCP'} options={[{ value: 'TCP' }, { value: 'UDP' }]} />
); })}
); }