mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-25 22:36:38 +00:00
Enter key handling & hostname field reset in resource create
This commit is contained in:
@@ -630,19 +630,29 @@ export default function Page() {
|
|||||||
defaultValue={row.original.ip}
|
defaultValue={row.original.ip}
|
||||||
className="min-w-[150px]"
|
className="min-w-[150px]"
|
||||||
onBlur={(e) => {
|
onBlur={(e) => {
|
||||||
const parsed = parseHostTarget(e.target.value);
|
const input = e.target.value.trim();
|
||||||
|
const hasProtocol = /^(https?|h2c):\/\//.test(input);
|
||||||
|
const hasPort = /:\d+(?:\/|$)/.test(input);
|
||||||
|
|
||||||
if (parsed) {
|
if (hasProtocol || hasPort) {
|
||||||
updateTarget(row.original.targetId, {
|
const parsed = parseHostTarget(input);
|
||||||
...row.original,
|
if (parsed) {
|
||||||
method: parsed.protocol,
|
updateTarget(row.original.targetId, {
|
||||||
ip: parsed.host,
|
...row.original,
|
||||||
port: parsed.port ? Number(parsed.port) : undefined,
|
method: hasProtocol ? parsed.protocol : row.original.method,
|
||||||
});
|
ip: parsed.host,
|
||||||
|
port: hasPort ? parsed.port : row.original.port
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
updateTarget(row.original.targetId, {
|
||||||
|
...row.original,
|
||||||
|
ip: input
|
||||||
|
});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
updateTarget(row.original.targetId, {
|
updateTarget(row.original.targetId, {
|
||||||
...row.original,
|
...row.original,
|
||||||
ip: e.target.value,
|
ip: input
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
@@ -744,6 +754,11 @@ export default function Page() {
|
|||||||
<SettingsSectionForm>
|
<SettingsSectionForm>
|
||||||
<Form {...baseForm}>
|
<Form {...baseForm}>
|
||||||
<form
|
<form
|
||||||
|
onKeyDown={(e) => {
|
||||||
|
if (e.key === "Enter") {
|
||||||
|
e.preventDefault(); // block default enter refresh
|
||||||
|
}
|
||||||
|
}}
|
||||||
className="space-y-4"
|
className="space-y-4"
|
||||||
id="base-resource-form"
|
id="base-resource-form"
|
||||||
>
|
>
|
||||||
@@ -856,6 +871,11 @@ export default function Page() {
|
|||||||
<SettingsSectionForm>
|
<SettingsSectionForm>
|
||||||
<Form {...tcpUdpForm}>
|
<Form {...tcpUdpForm}>
|
||||||
<form
|
<form
|
||||||
|
onKeyDown={(e) => {
|
||||||
|
if (e.key === "Enter") {
|
||||||
|
e.preventDefault(); // block default enter refresh
|
||||||
|
}
|
||||||
|
}}
|
||||||
className="space-y-4"
|
className="space-y-4"
|
||||||
id="tcp-udp-settings-form"
|
id="tcp-udp-settings-form"
|
||||||
>
|
>
|
||||||
@@ -1204,11 +1224,21 @@ export default function Page() {
|
|||||||
id="ip"
|
id="ip"
|
||||||
{...field}
|
{...field}
|
||||||
onBlur={(e) => {
|
onBlur={(e) => {
|
||||||
const parsed = parseHostTarget(e.target.value);
|
const input = e.target.value.trim();
|
||||||
if (parsed) {
|
const hasProtocol = /^(https?|h2c):\/\//.test(input);
|
||||||
addTargetForm.setValue("method", parsed.protocol);
|
const hasPort = /:\d+(?:\/|$)/.test(input);
|
||||||
addTargetForm.setValue("ip", parsed.host);
|
|
||||||
addTargetForm.setValue("port", parsed.port);
|
if (hasProtocol || hasPort) {
|
||||||
|
const parsed = parseHostTarget(input);
|
||||||
|
if (parsed) {
|
||||||
|
if (hasProtocol || !addTargetForm.getValues("method")) {
|
||||||
|
addTargetForm.setValue("method", parsed.protocol);
|
||||||
|
}
|
||||||
|
addTargetForm.setValue("ip", parsed.host);
|
||||||
|
if (hasPort || !addTargetForm.getValues("port")) {
|
||||||
|
addTargetForm.setValue("port", parsed.port);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
field.onBlur();
|
field.onBlur();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -620,6 +620,11 @@ WantedBy=default.target`
|
|||||||
<SettingsSectionForm>
|
<SettingsSectionForm>
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<form
|
<form
|
||||||
|
onKeyDown={(e) => {
|
||||||
|
if (e.key === "Enter") {
|
||||||
|
e.preventDefault(); // block default enter refresh
|
||||||
|
}
|
||||||
|
}}
|
||||||
className="space-y-4"
|
className="space-y-4"
|
||||||
id="create-site-form"
|
id="create-site-form"
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user