import { Form, FormikErrors, useFormikContext } from 'formik'; import { RefreshCw } from 'lucide-react'; import { CommonFields } from '@/react/portainer/custom-templates/components/CommonFields'; import { CustomTemplatesVariablesDefinitionField } from '@/react/portainer/custom-templates/components/CustomTemplatesVariablesDefinitionField'; import { PlatformField } from '@/react/portainer/custom-templates/components/PlatformSelector'; import { GitForm } from '@/react/portainer/gitops/GitForm'; import { getTemplateVariables, intersectVariables, isTemplateVariablesEnabled, } from '@/react/portainer/custom-templates/components/utils'; import { TemplateTypeSelector } from '@/react/portainer/custom-templates/components/TemplateTypeSelector'; import { applySetStateAction } from '@/react-tools/apply-set-state-action'; import { EdgeTemplateSettings } from '@/react/portainer/templates/custom-templates/types'; import { WebEditorForm, usePreventExit } from '@@/WebEditorForm'; import { FormActions } from '@@/form-components/FormActions'; import { Button } from '@@/buttons'; import { FormError } from '@@/form-components/FormError'; import { EdgeSettingsFieldset } from '../CreateView/EdgeSettingsFieldset'; import { FormValues } from './types'; export function InnerForm({ isLoading, isEditorReadonly, gitFileContent, gitFileError, refreshGitFile, }: { isLoading: boolean; isEditorReadonly: boolean; gitFileContent?: string; gitFileError?: string; refreshGitFile: () => void; }) { const { values, initialValues, setFieldValue, errors, isValid, setFieldError, isSubmitting, dirty, setValues, } = useFormikContext(); usePreventExit( initialValues.FileContent, values.FileContent, !isEditorReadonly && !isSubmitting ); return (
setValues((values) => ({ ...values, ...newValues })) } errors={errors} /> setFieldValue('Platform', value)} /> setFieldValue('Type', value)} />

You can get more information about Compose file format in the{' '} official documentation .

{isTemplateVariablesEnabled && ( setFieldValue('Variables', values)} isVariablesNamesFromParent={!isEditorReadonly} errors={errors.Variables} /> )} {values.Git && ( <> setValues((values) => ({ ...values, // set ! for values.Git because this callback will only be called when it's defined (see L94) Git: { ...values.Git!, ...newValues }, })) } errors={typeof errors.Git === 'object' ? errors.Git : undefined} />
{gitFileError && (
Custom template could not be loaded, {gitFileError}.
)}
)} {values.EdgeSettings && ( setFieldValue( 'EdgeSettings', applySetStateAction(edgeValues, values.EdgeSettings) ) } gitConfig={values.Git} fileValues={{ fileContent: values.FileContent, }} values={values.EdgeSettings} errors={errors.EdgeSettings as FormikErrors} setFieldError={setFieldError} /> )} ); function handleChangeFileContent(value: string) { setFieldValue( 'FileContent', value, isTemplateVariablesEnabled ? !value : true ); parseTemplate(value); } function parseTemplate(value: string) { if (!isTemplateVariablesEnabled || value === '') { setFieldValue('Variables', []); return; } const [variables, validationError] = getTemplateVariables(value); setFieldError( 'FileContent', validationError ? `Template invalid: ${validationError}` : undefined ); if (variables) { setFieldValue( 'Variables', intersectVariables(values.Variables, variables) ); } } }