2023-10-11 19:32:02 +00:00
import { Field , Form , FormikProps } from 'formik' ;
import { MultiValue } from 'react-select' ;
import { useEnvironmentId } from '@/react/hooks/useEnvironmentId' ;
import { useCurrentEnvironment } from '@/react/hooks/useCurrentEnvironment' ;
2024-04-08 14:22:43 +00:00
import { Registry } from '@/react/portainer/registries/types/registry' ;
2023-10-11 19:32:02 +00:00
import { FormControl } from '@@/form-components/FormControl' ;
import { FormSection } from '@@/form-components/FormSection' ;
import { Input } from '@@/form-components/Input' ;
import { FormActions } from '@@/form-components/FormActions' ;
import { IngressClassDatatable } from '../../cluster/ingressClass/IngressClassDatatable' ;
import { useIngressControllerClassMapQuery } from '../../cluster/ingressClass/useIngressControllerClassMap' ;
import { CreateNamespaceFormValues } from '../CreateView/types' ;
import { AnnotationsBeTeaser } from '../../annotations/AnnotationsBeTeaser' ;
import { LoadBalancerFormSection } from './LoadBalancerFormSection' ;
import { NamespaceSummary } from './NamespaceSummary' ;
import { StorageQuotaFormSection } from './StorageQuotaFormSection/StorageQuotaFormSection' ;
import { ResourceQuotaFormSection } from './ResourceQuotaFormSection' ;
import { RegistriesFormSection } from './RegistriesFormSection' ;
import { ResourceQuotaFormValues } from './ResourceQuotaFormSection/types' ;
export function NamespaceInnerForm ( {
errors ,
isValid ,
setFieldValue ,
values ,
isSubmitting ,
initialValues ,
} : FormikProps < CreateNamespaceFormValues > ) {
const environmentId = useEnvironmentId ( ) ;
const environmentQuery = useCurrentEnvironment ( ) ;
const ingressClassesQuery = useIngressControllerClassMapQuery ( {
environmentId ,
allowedOnly : true ,
} ) ;
if ( environmentQuery . isLoading ) {
return null ;
}
const useLoadBalancer =
environmentQuery . data ? . Kubernetes . Configuration . UseLoadBalancer ;
const enableResourceOverCommit =
environmentQuery . data ? . Kubernetes . Configuration . EnableResourceOverCommit ;
const enableIngressControllersPerNamespace =
environmentQuery . data ? . Kubernetes . Configuration
. IngressAvailabilityPerNamespace ;
const storageClasses =
environmentQuery . data ? . Kubernetes . Configuration . StorageClasses ? ? [ ] ;
return (
< Form >
< FormControl
inputId = "namespace"
label = "Name"
required
errors = { errors . name }
>
< Field
as = { Input }
id = "namespace"
name = "name"
placeholder = "e.g. my-namespace"
data - cy = "k8sNamespaceCreate-namespaceNameInput"
/ >
< / FormControl >
< AnnotationsBeTeaser / >
< ResourceQuotaFormSection
enableResourceOverCommit = { enableResourceOverCommit }
values = { values . resourceQuota }
onChange = { ( resourceQuota : ResourceQuotaFormValues ) = >
setFieldValue ( 'resourceQuota' , resourceQuota )
}
errors = { errors . resourceQuota }
/ >
{ useLoadBalancer && < LoadBalancerFormSection / > }
{ enableIngressControllersPerNamespace && (
< FormSection title = "Networking" >
< IngressClassDatatable
onChange = { ( classes ) = > setFieldValue ( 'ingressClasses' , classes ) }
values = { values . ingressClasses }
description = "Enable the ingress controllers that users can select when publishing applications in this namespace."
2024-10-01 01:15:51 +00:00
noIngressControllerLabel = "No ingress controllers available in the cluster. Go to the cluster setup view to configure and allow the use of ingress controllers in the cluster."
2023-10-11 19:32:02 +00:00
view = "namespace"
isLoading = { ingressClassesQuery . isLoading }
initialValues = { initialValues . ingressClasses }
/ >
< / FormSection >
) }
< RegistriesFormSection
values = { values . registries }
onChange = { ( registries : MultiValue < Registry > ) = >
setFieldValue ( 'registries' , registries )
}
errors = { errors . registries }
/ >
2023-10-16 18:15:44 +00:00
{ storageClasses . length > 0 && < StorageQuotaFormSection / > }
2023-10-11 19:32:02 +00:00
< NamespaceSummary
initialValues = { initialValues }
values = { values }
isValid = { isValid }
/ >
2023-11-22 02:37:11 +00:00
< FormActions
submitLabel = "Create namespace"
loadingText = "Creating namespace"
isLoading = { isSubmitting }
isValid = { isValid }
data - cy = "k8sNamespaceCreate-submitButton"
/ >
2023-10-11 19:32:02 +00:00
< / Form >
) ;
}