import { ChangeEvent, ReactNode } from 'react'; import { Info, Plus, RefreshCw, Trash2 } from 'lucide-react'; import Route from '@/assets/ico/route.svg?c'; import { Link } from '@@/Link'; import { Icon } from '@@/Icon'; import { Select, Option } from '@@/form-components/Input/Select'; import { FormError } from '@@/form-components/FormError'; import { Widget, WidgetBody, WidgetTitle } from '@@/Widget'; import { Tooltip } from '@@/Tip/Tooltip'; import { Button } from '@@/buttons'; import { Annotations } from './Annotations'; import { Rule, ServicePorts } from './types'; import '../style.css'; const PathTypes: Record = { nginx: ['ImplementationSpecific', 'Prefix', 'Exact'], traefik: ['Prefix', 'Exact'], other: ['Prefix', 'Exact'], }; const PlaceholderAnnotations: Record = { nginx: ['e.g. nginx.ingress.kubernetes.io/rewrite-target', '/$1'], traefik: ['e.g. traefik.ingress.kubernetes.io/router.tls', 'true'], other: ['e.g. app.kubernetes.io/name', 'examplename'], }; interface Props { environmentID: number; rule: Rule; errors: Record; isLoading: boolean; isEdit: boolean; namespace: string; servicePorts: ServicePorts; ingressClassOptions: Option[]; serviceOptions: Option[]; tlsOptions: Option[]; namespacesOptions: Option[]; removeIngressRoute: (hostIndex: number, pathIndex: number) => void; removeIngressHost: (hostIndex: number) => void; removeAnnotation: (index: number) => void; addNewIngressHost: (noHost?: boolean) => void; addNewIngressRoute: (hostIndex: number) => void; addNewAnnotation: (type?: 'rewrite' | 'regex' | 'ingressClass') => void; handleNamespaceChange: (val: string) => void; handleHostChange: (hostIndex: number, val: string) => void; handleTLSChange: (hostIndex: number, tls: string) => void; handleIngressChange: ( key: 'IngressName' | 'IngressClassName', value: string ) => void; handleAnnotationChange: ( index: number, key: 'Key' | 'Value', val: string ) => void; handlePathChange: ( hostIndex: number, pathIndex: number, key: 'Route' | 'PathType' | 'ServiceName' | 'ServicePort', val: string ) => void; reloadTLSCerts: () => void; } export function IngressForm({ environmentID, rule, isLoading, isEdit, servicePorts, tlsOptions, handleTLSChange, addNewIngressHost, serviceOptions, handleHostChange, handleIngressChange, handlePathChange, addNewIngressRoute, removeIngressRoute, removeIngressHost, addNewAnnotation, removeAnnotation, reloadTLSCerts, handleAnnotationChange, ingressClassOptions, errors, namespacesOptions, handleNamespaceChange, namespace, }: Props) { if (isLoading) { return
Loading...
; } const hasNoHostRule = rule.Hosts?.some((host) => host.NoHost); const placeholderAnnotation = PlaceholderAnnotations[rule.IngressType || 'other'] || PlaceholderAnnotations.other; const pathTypes = PathTypes[rule.IngressType || 'other'] || PathTypes.other; return (
{isEdit ? ( namespace ) : ( ) => handleIngressChange('IngressName', e.target.value) } disabled={isEdit} /> )} {errors.ingressName && !isEdit && ( {errors.ingressName} )}
) => handleHostChange(hostIndex, e.target.value) } />
{errors[`hosts[${hostIndex}].host`] && ( {errors[`hosts[${hostIndex}].host`]} )}
TLS secret ) => handlePathChange( hostIndex, pathIndex, 'ServiceName', e.target.value ) } defaultValue={path.ServiceName} />
{errors[ `hosts[${hostIndex}].paths[${pathIndex}].servicename` ] && ( { errors[ `hosts[${hostIndex}].paths[${pathIndex}].servicename` ] } )}
{servicePorts && ( <>
Service port ({ label: type, value: type, })) : [] } onChange={(e: ChangeEvent) => handlePathChange( hostIndex, pathIndex, 'PathType', e.target.value ) } defaultValue={path.PathType} />
{errors[ `hosts[${hostIndex}].paths[${pathIndex}].pathType` ] && ( { errors[ `hosts[${hostIndex}].paths[${pathIndex}].pathType` ] } )}
Path ) => handlePathChange( hostIndex, pathIndex, 'Route', e.target.value ) } />
{errors[ `hosts[${hostIndex}].paths[${pathIndex}].path` ] && ( { errors[ `hosts[${hostIndex}].paths[${pathIndex}].path` ] } )}
))}
))} {namespace && (
)}
); }