mirror of
https://github.com/fosrl/pangolin.git
synced 2026-09-17 16:19:48 +02:00
Merge pull request #3775 from fosrl/dev
Add domain validation for inference mode in resource forms
This commit is contained in:
@@ -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,22 +291,33 @@ export default function PrivateResourceInferencePage() {
|
|||||||
</SettingsSubsectionHeader>
|
</SettingsSubsectionHeader>
|
||||||
</SettingsFormCell>
|
</SettingsFormCell>
|
||||||
<SettingsFormCell span="full">
|
<SettingsFormCell span="full">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="httpConfigDomainId"
|
||||||
|
render={() => (
|
||||||
|
<FormItem>
|
||||||
<DomainPicker
|
<DomainPicker
|
||||||
key={`inference-domain-${siteResource.id}`}
|
key={`inference-domain-${siteResource.id}`}
|
||||||
orgId={siteResource.orgId}
|
orgId={
|
||||||
|
siteResource.orgId
|
||||||
|
}
|
||||||
cols={2}
|
cols={2}
|
||||||
hideFreeDomain
|
hideFreeDomain
|
||||||
defaultSubdomain={
|
defaultSubdomain={
|
||||||
httpConfigSubdomain ?? undefined
|
httpConfigSubdomain ??
|
||||||
|
undefined
|
||||||
}
|
}
|
||||||
defaultDomainId={
|
defaultDomainId={
|
||||||
httpConfigDomainId ?? undefined
|
httpConfigDomainId ??
|
||||||
|
undefined
|
||||||
}
|
}
|
||||||
defaultFullDomain={
|
defaultFullDomain={
|
||||||
httpConfigFullDomain ??
|
httpConfigFullDomain ??
|
||||||
undefined
|
undefined
|
||||||
}
|
}
|
||||||
onDomainChange={(res) => {
|
onDomainChange={(
|
||||||
|
res
|
||||||
|
) => {
|
||||||
if (res === null) {
|
if (res === null) {
|
||||||
form.setValue(
|
form.setValue(
|
||||||
"httpConfigSubdomain",
|
"httpConfigSubdomain",
|
||||||
@@ -312,7 +325,11 @@ export default function PrivateResourceInferencePage() {
|
|||||||
);
|
);
|
||||||
form.setValue(
|
form.setValue(
|
||||||
"httpConfigDomainId",
|
"httpConfigDomainId",
|
||||||
null
|
"",
|
||||||
|
{
|
||||||
|
shouldValidate:
|
||||||
|
true
|
||||||
|
}
|
||||||
);
|
);
|
||||||
form.setValue(
|
form.setValue(
|
||||||
"httpConfigFullDomain",
|
"httpConfigFullDomain",
|
||||||
@@ -322,11 +339,16 @@ export default function PrivateResourceInferencePage() {
|
|||||||
}
|
}
|
||||||
form.setValue(
|
form.setValue(
|
||||||
"httpConfigSubdomain",
|
"httpConfigSubdomain",
|
||||||
res.subdomain ?? null
|
res.subdomain ??
|
||||||
|
null
|
||||||
);
|
);
|
||||||
form.setValue(
|
form.setValue(
|
||||||
"httpConfigDomainId",
|
"httpConfigDomainId",
|
||||||
res.domainId
|
res.domainId,
|
||||||
|
{
|
||||||
|
shouldValidate:
|
||||||
|
true
|
||||||
|
}
|
||||||
);
|
);
|
||||||
form.setValue(
|
form.setValue(
|
||||||
"httpConfigFullDomain",
|
"httpConfigFullDomain",
|
||||||
@@ -334,6 +356,10 @@ export default function PrivateResourceInferencePage() {
|
|||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
</SettingsFormCell>
|
</SettingsFormCell>
|
||||||
<SettingsFormCell span="half">
|
<SettingsFormCell span="half">
|
||||||
<FormField
|
<FormField
|
||||||
|
|||||||
@@ -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,6 +450,11 @@ export default function GeneralForm() {
|
|||||||
resource.mode
|
resource.mode
|
||||||
) && (
|
) && (
|
||||||
<SettingsFormCell span="full">
|
<SettingsFormCell span="full">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="domainId"
|
||||||
|
render={() => (
|
||||||
|
<FormItem>
|
||||||
<div id="resource-domain-picker">
|
<div id="resource-domain-picker">
|
||||||
<DomainPicker
|
<DomainPicker
|
||||||
allowWildcard={
|
allowWildcard={
|
||||||
@@ -443,17 +464,21 @@ export default function GeneralForm() {
|
|||||||
key={
|
key={
|
||||||
resource.resourceId
|
resource.resourceId
|
||||||
}
|
}
|
||||||
orgId={orgId as string}
|
orgId={
|
||||||
|
orgId as string
|
||||||
|
}
|
||||||
cols={2}
|
cols={2}
|
||||||
defaultSubdomain={
|
defaultSubdomain={
|
||||||
form.watch(
|
form.watch(
|
||||||
"subdomain"
|
"subdomain"
|
||||||
) ?? undefined
|
) ??
|
||||||
|
undefined
|
||||||
}
|
}
|
||||||
defaultDomainId={
|
defaultDomainId={
|
||||||
form.watch(
|
form.watch(
|
||||||
"domainId"
|
"domainId"
|
||||||
) ?? undefined
|
) ??
|
||||||
|
undefined
|
||||||
}
|
}
|
||||||
defaultFullDomain={
|
defaultFullDomain={
|
||||||
resourceFullDomainName ||
|
resourceFullDomainName ||
|
||||||
@@ -462,10 +487,17 @@ export default function GeneralForm() {
|
|||||||
onDomainChange={(
|
onDomainChange={(
|
||||||
res
|
res
|
||||||
) => {
|
) => {
|
||||||
if (res === null) {
|
if (
|
||||||
|
res ===
|
||||||
|
null
|
||||||
|
) {
|
||||||
form.setValue(
|
form.setValue(
|
||||||
"domainId",
|
"domainId",
|
||||||
undefined
|
undefined,
|
||||||
|
{
|
||||||
|
shouldValidate:
|
||||||
|
true
|
||||||
|
}
|
||||||
);
|
);
|
||||||
form.setValue(
|
form.setValue(
|
||||||
"subdomain",
|
"subdomain",
|
||||||
@@ -478,7 +510,11 @@ export default function GeneralForm() {
|
|||||||
}
|
}
|
||||||
form.setValue(
|
form.setValue(
|
||||||
"domainId",
|
"domainId",
|
||||||
res.domainId
|
res.domainId,
|
||||||
|
{
|
||||||
|
shouldValidate:
|
||||||
|
true
|
||||||
|
}
|
||||||
);
|
);
|
||||||
form.setValue(
|
form.setValue(
|
||||||
"subdomain",
|
"subdomain",
|
||||||
@@ -491,6 +527,10 @@ export default function GeneralForm() {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
</SettingsFormCell>
|
</SettingsFormCell>
|
||||||
)}
|
)}
|
||||||
{!["tcp", "udp", "inference"].includes(
|
{!["tcp", "udp", "inference"].includes(
|
||||||
|
|||||||
@@ -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"]
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user