Files

215 lines
8.9 KiB
TypeScript
Raw Permalink Normal View History

2026-10-05 18:10:18 -04:00
import type { AppForm } from '@/components/form';
import { type AdminLocation, useAllAdminLocations } from '@/api/admin/locations/queries';
2026-10-08 18:49:15 -04:00
import { type NodeFormValues, nodeNumberValidators, validateNodeName } from '@/components/admin/nodes/nodeForm';
2026-10-05 18:10:18 -04:00
import TitledGreyBox from '@/components/elements/TitledGreyBox';
interface Props {
form: AppForm<NodeFormValues>;
prefix?: string;
requiresSslScheme?: boolean;
}
type LocationOption = AdminLocation;
interface FormFieldsProps {
form: AppForm<NodeFormValues>;
prefix: string;
}
interface IdentityFieldsProps extends FormFieldsProps {
locations: LocationOption[];
}
interface NetworkFieldsProps extends FormFieldsProps {
requiresSslScheme: boolean;
}
const IdentityFields = ({ form, locations, prefix }: IdentityFieldsProps) => (
2026-10-08 16:53:20 -04:00
<div className='space-y-6'>
2026-10-05 18:10:18 -04:00
<form.AppField
2026-10-08 16:53:20 -04:00
name='name'
2026-10-05 18:10:18 -04:00
validators={{
2026-10-08 16:53:20 -04:00
onChange: ({ value }) => validateNodeName(value),
2026-10-05 18:10:18 -04:00
}}
>
{(field) => (
<field.TextField
2026-10-08 16:53:20 -04:00
type='text'
2026-10-05 18:10:18 -04:00
id={`${prefix}name`}
2026-10-08 16:53:20 -04:00
label='Name'
description='A short identifier used to distinguish this node from others.'
2026-10-05 18:10:18 -04:00
/>
)}
</form.AppField>
2026-10-08 16:53:20 -04:00
<form.AppField name='description'>
2026-10-05 18:10:18 -04:00
{(field) => (
<field.TextField
2026-10-08 16:53:20 -04:00
type='text'
2026-10-05 18:10:18 -04:00
id={`${prefix}description`}
2026-10-08 16:53:20 -04:00
label='Description'
description='A longer description of this node.'
2026-10-05 18:10:18 -04:00
/>
)}
</form.AppField>
<form.AppField
2026-10-08 16:53:20 -04:00
name='locationId'
2026-10-05 18:10:18 -04:00
validators={{
onChange: ({ value }) => (value >= 1 ? undefined : 'A location must be selected.'),
}}
>
{(field) => (
<field.SelectField
id={`${prefix}location_id`}
2026-10-08 16:53:20 -04:00
label='Location'
2026-10-05 18:10:18 -04:00
options={locations.map((location) => ({
value: location.attributes.id,
label: location.attributes.short,
}))}
/>
)}
</form.AppField>
</div>
);
const NetworkFields = ({ form, prefix, requiresSslScheme }: NetworkFieldsProps) => {
const schemeDescription = requiresSslScheme
? 'This Panel is using HTTPS, so browsers require node connections to use SSL.'
: 'In most cases you should use SSL. Use HTTP only for non-SSL nodes.';
return (
2026-10-08 16:53:20 -04:00
<div className='space-y-6'>
<div className='grid grid-cols-1 lg:grid-cols-[1fr_16rem] gap-6'>
2026-10-05 18:10:18 -04:00
<form.AppField
2026-10-08 16:53:20 -04:00
name='fqdn'
2026-10-05 18:10:18 -04:00
validators={{
onChange: ({ value }) => (value.length >= 1 ? undefined : 'An FQDN must be provided.'),
}}
>
{(field) => (
<field.TextField
2026-10-08 16:53:20 -04:00
type='text'
2026-10-05 18:10:18 -04:00
id={`${prefix}fqdn`}
2026-10-08 16:53:20 -04:00
label='FQDN'
description='The domain name or IP address that points to this node.'
2026-10-05 18:10:18 -04:00
/>
)}
</form.AppField>
<form.AppField
2026-10-08 16:53:20 -04:00
name='scheme'
2026-10-05 18:10:18 -04:00
validators={{
onChange: ({ value }) =>
requiresSslScheme && value === 'http'
? 'HTTP node connections cannot be used when the Panel is loaded over HTTPS.'
: undefined,
}}
>
{(field) => (
<field.SelectField
id={`${prefix}scheme`}
2026-10-08 16:53:20 -04:00
label='Communicate Over SSL'
2026-10-05 18:10:18 -04:00
options={[
{ value: 'https', label: 'Use SSL Connection (https)' },
{
value: 'http',
label: 'Use HTTP Connection (http)',
disabled: requiresSslScheme,
},
]}
description={schemeDescription}
/>
)}
</form.AppField>
</div>
2026-10-08 16:53:20 -04:00
<div className='grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-1 gap-x-8 gap-y-5'>
<form.AppField name='public'>
2026-10-05 18:10:18 -04:00
{(field) => (
<field.SwitchField
2026-10-08 16:53:20 -04:00
label='Node Visibility'
description='Public nodes are available for automatic server deployment.'
controlPosition='end'
className='w-full'
2026-10-05 18:10:18 -04:00
/>
)}
</form.AppField>
2026-10-08 16:53:20 -04:00
<form.AppField name='behindProxy'>
2026-10-05 18:10:18 -04:00
{(field) => (
<field.SwitchField
2026-10-08 16:53:20 -04:00
label='Behind Proxy'
description='Enable if this node sits behind a proxy such as Cloudflare.'
controlPosition='end'
className='w-full'
2026-10-05 18:10:18 -04:00
/>
)}
</form.AppField>
2026-10-08 16:53:20 -04:00
<form.AppField name='maintenanceMode'>
2026-10-05 18:10:18 -04:00
{(field) => (
<field.SwitchField
2026-10-08 16:53:20 -04:00
label='Maintenance Mode'
description='Servers on a node in maintenance mode cannot be accessed.'
controlPosition='end'
className='w-full sm:col-span-2 xl:col-span-1'
2026-10-05 18:10:18 -04:00
/>
)}
</form.AppField>
</div>
</div>
);
};
const ResourceFields = ({ form, prefix }: FormFieldsProps) => (
2026-10-08 16:53:20 -04:00
<div className='grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-4 gap-6'>
<form.AppField name='memory' validators={nodeNumberValidators.memory}>
{(field) => <field.NumberField id={`${prefix}memory`} label='Memory (MiB)' min={1} />}
2026-10-05 18:10:18 -04:00
</form.AppField>
2026-10-08 16:53:20 -04:00
<form.AppField name='memoryOverallocate' validators={nodeNumberValidators.memoryOverallocate}>
2026-10-05 18:10:18 -04:00
{(field) => (
2026-10-08 16:53:20 -04:00
<field.NumberField id={`${prefix}memory_overallocate`} label='Memory Overallocate (%)' min={-1} />
2026-10-05 18:10:18 -04:00
)}
</form.AppField>
2026-10-08 16:53:20 -04:00
<form.AppField name='disk' validators={nodeNumberValidators.disk}>
{(field) => <field.NumberField id={`${prefix}disk`} label='Disk Space (MiB)' min={1} />}
2026-10-05 18:10:18 -04:00
</form.AppField>
2026-10-08 16:53:20 -04:00
<form.AppField name='diskOverallocate' validators={nodeNumberValidators.diskOverallocate}>
{(field) => <field.NumberField id={`${prefix}disk_overallocate`} label='Disk Overallocate (%)' min={-1} />}
2026-10-05 18:10:18 -04:00
</form.AppField>
</div>
);
const DaemonFields = ({ form, prefix }: FormFieldsProps) => (
2026-10-08 16:53:20 -04:00
<div className='grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-[12rem_12rem_12rem_1fr] gap-6'>
<form.AppField name='daemonListen' validators={nodeNumberValidators.daemonListen}>
{(field) => <field.NumberField id={`${prefix}daemon_listen`} label='Daemon Port' min={1} max={65535} />}
2026-10-05 18:10:18 -04:00
</form.AppField>
2026-10-08 16:53:20 -04:00
<form.AppField name='daemonSftp' validators={nodeNumberValidators.daemonSftp}>
{(field) => <field.NumberField id={`${prefix}daemon_sftp`} label='Daemon SFTP Port' min={1} max={65535} />}
2026-10-05 18:10:18 -04:00
</form.AppField>
2026-10-08 16:53:20 -04:00
<form.AppField name='uploadSize' validators={nodeNumberValidators.uploadSize}>
{(field) => <field.NumberField id={`${prefix}upload_size`} label='Upload Size Limit (MiB)' min={1} />}
2026-10-05 18:10:18 -04:00
</form.AppField>
2026-10-08 16:53:20 -04:00
<form.AppField name='daemonBase'>
{(field) => <field.TextField type='text' id={`${prefix}daemon_base`} label='Daemon Base Path' />}
2026-10-05 18:10:18 -04:00
</form.AppField>
</div>
);
export default function NodeFormFields({ form, prefix = '', requiresSslScheme = false }: Props) {
const { data: locations = [] } = useAllAdminLocations();
return (
2026-10-08 16:53:20 -04:00
<div className='grid grid-cols-1 xl:grid-cols-2 gap-6'>
<TitledGreyBox title='Identity'>
2026-10-05 18:10:18 -04:00
<IdentityFields form={form} locations={locations} prefix={prefix} />
</TitledGreyBox>
2026-10-08 16:53:20 -04:00
<TitledGreyBox title='Network'>
2026-10-05 18:10:18 -04:00
<NetworkFields form={form} prefix={prefix} requiresSslScheme={requiresSslScheme} />
</TitledGreyBox>
2026-10-08 16:53:20 -04:00
<TitledGreyBox title='Resource Limits' className='xl:col-span-2'>
2026-10-05 18:10:18 -04:00
<ResourceFields form={form} prefix={prefix} />
</TitledGreyBox>
2026-10-08 16:53:20 -04:00
<TitledGreyBox title='Daemon' className='xl:col-span-2'>
2026-10-05 18:10:18 -04:00
<DaemonFields form={form} prefix={prefix} />
</TitledGreyBox>
</div>
);
}