diff --git a/create-a-container/client/src/components/containers/ResourceValueInput.tsx b/create-a-container/client/src/components/containers/ResourceValueInput.tsx index 9533372f..396e76d1 100644 --- a/create-a-container/client/src/components/containers/ResourceValueInput.tsx +++ b/create-a-container/client/src/components/containers/ResourceValueInput.tsx @@ -24,6 +24,8 @@ interface ResourceValueInputProps { presets: readonly number[]; value: number; onChange: (value: number) => void; + /** Preset label override; defaults to the value with its unit. */ + formatValue?: (value: number) => string; } /** @@ -39,6 +41,7 @@ export function ResourceValueInput({ presets, value, onChange, + formatValue, }: ResourceValueInputProps) { const [isCustom, setIsCustom] = useState(() => !presets.includes(value)); @@ -50,7 +53,7 @@ export function ResourceValueInput({ const options = [ ...presets.map((preset) => ({ value: String(preset), - label: formatPreset(preset, unit), + label: formatValue ? formatValue(preset) : formatPreset(preset, unit), })), { value: CUSTOM_OPTION, label: 'Custom…' }, ]; diff --git a/create-a-container/client/src/components/containers/ResourcesSection.tsx b/create-a-container/client/src/components/containers/ResourcesSection.tsx index a69f0533..e55a8706 100644 --- a/create-a-container/client/src/components/containers/ResourcesSection.tsx +++ b/create-a-container/client/src/components/containers/ResourcesSection.tsx @@ -15,6 +15,7 @@ import { Save } from 'lucide-react'; import { api, ApiError } from '@/lib/api'; import { keys, queries } from '@/lib/queries'; import { useSession } from '@/lib/auth'; +import { RESOURCE_DEFAULTS, formatIdleTime } from '@/lib/resources'; import type { EffectiveResources, ResourceRequest } from '@/lib/types'; import { ResourceValueInput } from './ResourceValueInput'; @@ -44,9 +45,21 @@ const RESOURCE_OPTIONS = [ min: 5, presets: [5, 10, 20, 50, 100, 200, 500], }, + { + key: 'idleTime', + label: 'Idle shutdown', + unit: 'hours', + step: 1, + min: 0, + presets: [0, 1, 4, 8, 24, 72, 168, 336, 720], + }, ] as const; -const DEFAULTS: EffectiveResources = { memory: 8192, swap: 0, cpus: 4, rootfs: 50 }; +/** Display value for a resource row; idleTime reads as "Never" / "3 days". */ +function formatResource(key: keyof EffectiveResources, value: number, unit: string): string { + if (key === 'idleTime') return formatIdleTime(value); + return unit ? `${value} ${unit}` : `${value}`; +} interface ResourcesSectionProps { siteId: string; @@ -121,7 +134,7 @@ export function ResourcesSection({ onError: (err: ApiError) => toast.error(err.message), }); - const resources = effective || DEFAULTS; + const resources = effective || RESOURCE_DEFAULTS; if (!hostname) { return ( @@ -162,6 +175,11 @@ export function ResourcesSection({
Resource allocations for this container. Changes above the default require admin approval.
++ Idle shutdown stops the container after that long without traffic through the proxy + (SSH and direct connections don't count). Shortening it applies immediately; longer + or Never requires admin approval. +
{!isOwner && (Only owners can make resource requests on their containers. @@ -174,9 +192,9 @@ export function ResourcesSection({ )}