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 { Card } from '@@/Card'; import { Widget } from '@@/Widget'; import { isServicePortError, newPort } from './utils'; import { ServiceFormValues, ServicePort } from './types'; import { ServicePortInput } from './ServicePortInput'; import { ContainerPortInput } from './ContainerPortInput'; interface Props { services: ServiceFormValues[]; serviceIndex: number; onChangeService: (services: ServiceFormValues[]) => void; servicePorts: ServicePort[]; onChangePort: (servicePorts: ServicePort[]) => void; serviceName?: string; errors?: string | string[] | FormikErrors[]; } export function ClusterIpServiceForm({ services, serviceIndex, onChangeService, servicePorts, onChangePort, errors, serviceName, }: Props) { const newClusterIpPort = newPort(serviceName); return (
ClusterIP service
Ports
{servicePorts.map((servicePort, portIndex) => { const error = errors?.[portIndex]; const servicePortError = isServicePortError(error) ? error : undefined; return (
) => { const newServicePorts = [...servicePorts]; const newValue = e.target.value === '' ? undefined : Number(e.target.value); newServicePorts[portIndex] = { ...newServicePorts[portIndex], targetPort: newValue, port: newValue, }; onChangePort(newServicePorts); }} /> {servicePortError?.targetPort && ( {servicePortError.targetPort} )}
) => { const newServicePorts = [...servicePorts]; newServicePorts[portIndex] = { ...newServicePorts[portIndex], port: e.target.value === '' ? undefined : Number(e.target.value), }; onChangePort(newServicePorts); }} /> {servicePortError?.port && ( {servicePortError.port} )}
{ const newServicePorts = [...servicePorts]; newServicePorts[portIndex] = { ...newServicePorts[portIndex], protocol: value, }; onChangePort(newServicePorts); }} value={servicePort.protocol || 'TCP'} options={[{ value: 'TCP' }, { value: 'UDP' }]} />
); })}
); }