2022-11-21 07:51:55 +00:00
import { useFormikContext , Field } from 'formik' ;
2022-06-01 04:28:31 +00:00
2023-03-06 20:25:04 +00:00
import { GroupField } from '@/react/portainer/environments/wizard/EnvironmentsCreationView/shared/MetadataFieldset/GroupsField' ;
2022-06-17 16:18:42 +00:00
import { FormControl } from '@@/form-components/FormControl' ;
import { Input } from '@@/form-components/Input' ;
import { SwitchField } from '@@/form-components/SwitchField' ;
import { TextTip } from '@@/Tip/TextTip' ;
2023-03-06 20:25:04 +00:00
import { TagSelector } from '@@/TagSelector' ;
import { EdgeGroupsSelector } from '../../edge-stacks/components/EdgeGroupsSelector' ;
2022-04-14 10:14:23 +00:00
2022-06-01 04:28:31 +00:00
import { ScriptFormValues } from './types' ;
2022-04-14 10:14:23 +00:00
interface Props {
2022-06-01 04:28:31 +00:00
hideIdGetter? : boolean ;
2023-03-06 20:25:04 +00:00
showMetaFields? : boolean ;
2022-04-14 10:14:23 +00:00
}
2022-06-01 04:28:31 +00:00
export function EdgeScriptSettingsFieldset ( {
2022-04-14 10:14:23 +00:00
hideIdGetter ,
2023-03-06 20:25:04 +00:00
showMetaFields ,
2022-04-14 10:14:23 +00:00
} : Props ) {
2023-10-27 13:35:10 +00:00
const { values , setFieldValue , errors } =
useFormikContext < ScriptFormValues > ( ) ;
2022-04-14 10:14:23 +00:00
2022-06-01 04:28:31 +00:00
return (
< >
2023-03-06 20:25:04 +00:00
{ showMetaFields && (
< >
< GroupField name = "group" / >
< EdgeGroupsSelector
value = { values . edgeGroupsIds }
onChange = { ( value ) = > setFieldValue ( 'edgeGroupsIds' , value ) }
isGroupVisible = { ( group ) = > ! group . Dynamic }
horizontal
/ >
< TagSelector
value = { values . tagsIds }
onChange = { ( value ) = > setFieldValue ( 'tagsIds' , value ) }
/ >
< / >
) }
2022-04-14 10:14:23 +00:00
{ ! hideIdGetter && (
2022-05-05 07:02:34 +00:00
< >
< FormControl
label = "Edge ID Generator"
2023-10-27 13:35:10 +00:00
tooltip = "Enter a single-line bash command that generates a unique Edge ID. For example, you can use 'uuidgen' or 'uuid'. The result will be assigned to the 'PORTAINER_EDGE_ID' environment variable."
2022-05-05 07:02:34 +00:00
inputId = "edge-id-generator-input"
2023-10-27 13:35:10 +00:00
required
errors = { errors . edgeIdGenerator }
2022-05-05 07:02:34 +00:00
>
< Input
type = "text"
name = "edgeIdGenerator"
value = { values . edgeIdGenerator }
id = "edge-id-generator-input"
onChange = { ( e ) = > setFieldValue ( e . target . name , e . target . value ) }
/ >
< / FormControl >
2022-06-01 04:28:31 +00:00
< div className = "form-group" >
< div className = "col-sm-12" >
< TextTip color = "blue" >
< code > PORTAINER_EDGE_ID < / code > environment variable is required
to successfully connect the edge agent to Portainer
< / TextTip >
< / div >
< / div >
2022-05-05 07:02:34 +00:00
< / >
2022-04-14 10:14:23 +00:00
) }
2022-04-17 07:34:20 +00:00
< FormControl
label = "Environment variables"
tooltip = "Comma separated list of environment variables that will be sourced from the host where the agent is deployed."
2022-06-01 04:28:31 +00:00
inputId = "env-variables-input"
2022-04-17 07:34:20 +00:00
>
2022-06-01 04:28:31 +00:00
< Field
2022-04-17 07:34:20 +00:00
name = "envVars"
2022-06-01 04:28:31 +00:00
as = { Input }
placeholder = "foo=bar,myvar"
id = "env-variables-input"
2022-04-17 07:34:20 +00:00
/ >
< / FormControl >
2022-06-01 04:28:31 +00:00
< div className = "form-group" >
< div className = "col-sm-12" >
< SwitchField
checked = { values . allowSelfSignedCertificates }
onChange = { ( value ) = >
setFieldValue ( 'allowSelfSignedCertificates' , value )
}
label = "Allow self-signed certs"
2022-08-02 22:19:28 +00:00
labelClass = "col-sm-3 col-lg-2"
2022-06-01 04:28:31 +00:00
tooltip = "When allowing self-signed certificates the edge agent will ignore the domain validation when connecting to Portainer via HTTPS"
/ >
< / div >
< / div >
< / >
2022-04-14 10:14:23 +00:00
) ;
}