Add domain validation for inference mode in resource forms

This commit is contained in:
Owen
2026-09-16 09:41:46 -04:00
parent 66c9bdbfa3
commit 262ca8a1d0
3 changed files with 177 additions and 104 deletions
@@ -76,11 +76,13 @@ export default function PrivateResourceInferencePage() {
}) })
), ),
httpConfigSubdomain: z.string().nullish(), httpConfigSubdomain: z.string().nullish(),
httpConfigDomainId: z.string().nullish(), httpConfigDomainId: z
.string()
.min(1, { message: t("domainRequired") }),
httpConfigFullDomain: z.string().nullish(), httpConfigFullDomain: z.string().nullish(),
ssl: z.boolean().optional() ssl: z.boolean().optional()
}), }),
[] [t]
); );
type FormValues = z.infer<typeof formSchema>; type FormValues = z.infer<typeof formSchema>;
@@ -103,7 +105,7 @@ export default function PrivateResourceInferencePage() {
defaultValues: { defaultValues: {
providers: [], providers: [],
httpConfigSubdomain: siteResource.subdomain ?? null, httpConfigSubdomain: siteResource.subdomain ?? null,
httpConfigDomainId: siteResource.domainId ?? null, httpConfigDomainId: siteResource.domainId ?? "",
httpConfigFullDomain: siteResource.fullDomain ?? null, httpConfigFullDomain: siteResource.fullDomain ?? null,
ssl: siteResource.ssl ?? false ssl: siteResource.ssl ?? false
} }
@@ -289,50 +291,74 @@ export default function PrivateResourceInferencePage() {
</SettingsSubsectionHeader> </SettingsSubsectionHeader>
</SettingsFormCell> </SettingsFormCell>
<SettingsFormCell span="full"> <SettingsFormCell span="full">
<DomainPicker <FormField
key={`inference-domain-${siteResource.id}`} control={form.control}
orgId={siteResource.orgId} name="httpConfigDomainId"
cols={2} render={() => (
hideFreeDomain <FormItem>
defaultSubdomain={ <DomainPicker
httpConfigSubdomain ?? undefined key={`inference-domain-${siteResource.id}`}
} orgId={
defaultDomainId={ siteResource.orgId
httpConfigDomainId ?? undefined }
} cols={2}
defaultFullDomain={ hideFreeDomain
httpConfigFullDomain ?? defaultSubdomain={
undefined httpConfigSubdomain ??
} undefined
onDomainChange={(res) => { }
if (res === null) { defaultDomainId={
form.setValue( httpConfigDomainId ??
"httpConfigSubdomain", undefined
null }
); defaultFullDomain={
form.setValue( httpConfigFullDomain ??
"httpConfigDomainId", undefined
null }
); onDomainChange={(
form.setValue( res
"httpConfigFullDomain", ) => {
null if (res === null) {
); form.setValue(
return; "httpConfigSubdomain",
} null
form.setValue( );
"httpConfigSubdomain", form.setValue(
res.subdomain ?? null "httpConfigDomainId",
); "",
form.setValue( {
"httpConfigDomainId", shouldValidate:
res.domainId true
); }
form.setValue( );
"httpConfigFullDomain", form.setValue(
res.fullDomain "httpConfigFullDomain",
); null
}} );
return;
}
form.setValue(
"httpConfigSubdomain",
res.subdomain ??
null
);
form.setValue(
"httpConfigDomainId",
res.domainId,
{
shouldValidate:
true
}
);
form.setValue(
"httpConfigFullDomain",
res.fullDomain
);
}}
/>
<FormMessage />
</FormItem>
)}
/> />
</SettingsFormCell> </SettingsFormCell>
<SettingsFormCell span="half"> <SettingsFormCell span="half">
@@ -139,6 +139,22 @@ export default function GeneralForm() {
: "Port number should not be set for HTTP resources", : "Port number should not be set for HTTP resources",
path: ["proxyPort"] path: ["proxyPort"]
} }
)
.refine(
(data) => {
if (
["http", "ssh", "rdp", "vnc", "inference"].includes(
resource.mode
)
) {
return !!data.domainId;
}
return true;
},
{
message: t("domainRequired"),
path: ["domainId"]
}
); );
type GeneralFormValues = z.infer<typeof GeneralFormSchema>; type GeneralFormValues = z.infer<typeof GeneralFormSchema>;
@@ -434,63 +450,87 @@ export default function GeneralForm() {
resource.mode resource.mode
) && ( ) && (
<SettingsFormCell span="full"> <SettingsFormCell span="full">
<div id="resource-domain-picker"> <FormField
<DomainPicker control={form.control}
allowWildcard={ name="domainId"
resource.mode !== render={() => (
"inference" <FormItem>
} <div id="resource-domain-picker">
key={ <DomainPicker
resource.resourceId allowWildcard={
} resource.mode !==
orgId={orgId as string} "inference"
cols={2} }
defaultSubdomain={ key={
form.watch( resource.resourceId
"subdomain" }
) ?? undefined orgId={
} orgId as string
defaultDomainId={ }
form.watch( cols={2}
"domainId" defaultSubdomain={
) ?? undefined form.watch(
} "subdomain"
defaultFullDomain={ ) ??
resourceFullDomainName || undefined
undefined }
} defaultDomainId={
onDomainChange={( form.watch(
res "domainId"
) => { ) ??
if (res === null) { undefined
form.setValue( }
"domainId", defaultFullDomain={
undefined resourceFullDomainName ||
); undefined
form.setValue( }
"subdomain", onDomainChange={(
undefined res
); ) => {
setResourceFullDomain( if (
`${resource.ssl ? "https" : "http"}://` res ===
); null
return; ) {
} form.setValue(
form.setValue( "domainId",
"domainId", undefined,
res.domainId {
); shouldValidate:
form.setValue( true
"subdomain", }
res.subdomain ?? );
undefined form.setValue(
); "subdomain",
setResourceFullDomain( undefined
`${resource.ssl ? "https" : "http"}://${toUnicode(res.fullDomain)}` );
); setResourceFullDomain(
}} `${resource.ssl ? "https" : "http"}://`
/> );
</div> return;
}
form.setValue(
"domainId",
res.domainId,
{
shouldValidate:
true
}
);
form.setValue(
"subdomain",
res.subdomain ??
undefined
);
setResourceFullDomain(
`${resource.ssl ? "https" : "http"}://${toUnicode(res.fullDomain)}`
);
}}
/>
</div>
<FormMessage />
</FormItem>
)}
/>
</SettingsFormCell> </SettingsFormCell>
)} )}
{!["tcp", "udp", "inference"].includes( {!["tcp", "udp", "inference"].includes(
+7
View File
@@ -523,6 +523,13 @@ export function createCreateFormSchema(t: TranslateFn) {
}); });
} }
} }
if (data.mode === "inference" && !data.httpConfigDomainId) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: t("domainRequired"),
path: ["httpConfigDomainId"]
});
}
}); });
} }