import { useFormikContext, Form } from 'formik'; import { Settings } from 'lucide-react'; import { useState } from 'react'; import { useCurrentEnvironment } from '@/react/hooks/useCurrentEnvironment'; import { useEnvironmentId } from '@/react/hooks/useEnvironmentId'; import { useIsEnvironmentAdmin } from '@/react/hooks/useUser'; import { NavTabs } from '@@/NavTabs'; import { Widget } from '@@/Widget'; import { useApiVersion } from '../../proxy/queries/useVersion'; import { BaseForm } from './BaseForm'; import { CapabilitiesTab } from './CapabilitiesTab'; import { CommandsTab } from './CommandsTab'; import { LabelsTab } from './LabelsTab'; import { NetworkTab } from './NetworkTab'; import { ResourcesTab } from './ResourcesTab'; import { RestartPolicyTab } from './RestartPolicyTab'; import { VolumesTab } from './VolumesTab'; import { Values } from './useInitialValues'; import { EnvVarsTab } from './EnvVarsTab'; import { EditResourcesForm } from './ResourcesTab/EditResourceForm'; export function InnerForm({ hideCapabilities = false, isLoading, isDuplicate, onChangeName, onRateLimit, }: { hideCapabilities: boolean; isDuplicate: boolean; isLoading: boolean; onChangeName: (value: string) => void; onRateLimit: (limited?: boolean) => void; }) { const { values, setFieldValue, errors, submitForm } = useFormikContext(); const environmentId = useEnvironmentId(); const [tab, setTab] = useState('commands'); const apiVersion = useApiVersion(environmentId); const isEnvironmentAdmin = useIsEnvironmentAdmin(); const envQuery = useCurrentEnvironment(); if (!envQuery.data) { return null; } const environment = envQuery.data; return (
{ setFieldValue('commands.cmd', null); setFieldValue('commands.entrypoint', null); }} isLoading={isLoading} onRateLimit={onRateLimit} />
onSelect={setTab} selectedId={tab} type="pills" justified options={[ { id: 'commands', label: 'Commands & logging', children: ( setFieldValue(`commands.${field}`, value) } /> ), }, { id: 'volumes', label: 'Volumes', children: ( setFieldValue('volumes', value) } errors={errors.volumes} allowBindMounts={ isEnvironmentAdmin || environment.SecuritySettings .allowBindMountsForRegularUsers } /> ), }, { id: 'network', label: 'Network', children: ( setFieldValue(`network.${field}`, value) } /> ), }, { id: 'env', label: 'Env', children: ( setFieldValue('env', value)} errors={errors.env} /> ), }, { id: 'labels', label: 'Labels', children: ( setFieldValue('labels', value)} errors={errors.labels} /> ), }, { id: 'restart', label: 'Restart policy', children: ( setFieldValue('restartPolicy', value) } /> ), }, { id: 'runtime', label: 'Runtime & resources', children: ( setFieldValue(`resources.${field}`, value) } allowPrivilegedMode={ isEnvironmentAdmin || environment.SecuritySettings .allowPrivilegedModeForRegularUsers } isDevicesFieldVisible={ isEnvironmentAdmin || environment.SecuritySettings .allowDeviceMappingForRegularUsers } isInitFieldVisible={apiVersion >= 1.37} isSysctlFieldVisible={ isEnvironmentAdmin || environment.SecuritySettings .allowSysctlSettingForRegularUsers } renderLimits={ isDuplicate ? (values) => ( { setFieldValue( 'resources.resources', values ); return submitForm(); }} isImageInvalid={!!errors?.image} /> ) : undefined } /> ), }, { id: 'capabilities', label: 'Capabilities', hidden: hideCapabilities, children: ( setFieldValue('capabilities', value) } /> ), }, ]} />
); }