refactor(ui): change serverVersion field localtion

This commit is contained in:
ReaJason
2026-01-18 23:49:41 +08:00
parent 4955c9d4a2
commit 302e8fbb8f
11 changed files with 154 additions and 122 deletions
@@ -2,7 +2,7 @@ import { FileTextIcon } from "lucide-react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Separator } from "@/components/ui/separator"; import { Separator } from "@/components/ui/separator";
import { shouldHidden } from "@/lib/utils"; import { notNeedUrlPattern } from "@/lib/utils";
import { import {
type AntSwordShellToolConfig, type AntSwordShellToolConfig,
type BehinderShellToolConfig, type BehinderShellToolConfig,
@@ -45,7 +45,7 @@ export function BasicInfo({
label={t("mainConfig.shellMountType")} label={t("mainConfig.shellMountType")}
text={generateResult?.shellConfig.shellType} text={generateResult?.shellConfig.shellType}
/> />
{!shouldHidden(generateResult?.shellConfig?.shellType) && ( {!notNeedUrlPattern(generateResult?.shellConfig?.shellType) && (
<CopyableField <CopyableField
label={t("mainConfig.urlPattern")} label={t("mainConfig.urlPattern")}
text={generateResult?.injectorConfig.urlPattern} text={generateResult?.injectorConfig.urlPattern}
@@ -7,7 +7,6 @@ import { TabsContent } from "@/components/ui/tabs";
import type { MemShellFormSchema } from "@/types/schema"; import type { MemShellFormSchema } from "@/types/schema";
import { OptionalClassFormField } from "./classname-field"; import { OptionalClassFormField } from "./classname-field";
import { ShellTypeFormField } from "./shelltype-field"; import { ShellTypeFormField } from "./shelltype-field";
import { UrlPatternFormField } from "./urlpattern-field";
export function AntSwordTabContent({ export function AntSwordTabContent({
form, form,
@@ -21,10 +20,7 @@ export function AntSwordTabContent({
<TabsContent value="AntSword"> <TabsContent value="AntSword">
<Card> <Card>
<CardContent className="space-y-2 mt-4"> <CardContent className="space-y-2 mt-4">
<div className="grid grid-cols-1 md:grid-cols-2 gap-2"> <ShellTypeFormField form={form} shellTypes={shellTypes} />
<ShellTypeFormField form={form} shellTypes={shellTypes} />
<UrlPatternFormField form={form} />
</div>
<Controller <Controller
control={form.control} control={form.control}
name="antSwordPass" name="antSwordPass"
@@ -7,7 +7,6 @@ import { TabsContent } from "@/components/ui/tabs";
import type { MemShellFormSchema } from "@/types/schema"; import type { MemShellFormSchema } from "@/types/schema";
import { OptionalClassFormField } from "./classname-field"; import { OptionalClassFormField } from "./classname-field";
import { ShellTypeFormField } from "./shelltype-field"; import { ShellTypeFormField } from "./shelltype-field";
import { UrlPatternFormField } from "./urlpattern-field";
export function BehinderTabContent({ export function BehinderTabContent({
form, form,
@@ -21,10 +20,7 @@ export function BehinderTabContent({
<TabsContent value="Behinder"> <TabsContent value="Behinder">
<Card> <Card>
<CardContent className="space-y-2 mt-4"> <CardContent className="space-y-2 mt-4">
<div className="grid grid-cols-1 md:grid-cols-2 gap-2"> <ShellTypeFormField form={form} shellTypes={shellTypes} />
<ShellTypeFormField form={form} shellTypes={shellTypes} />
<UrlPatternFormField form={form} />
</div>
<Controller <Controller
control={form.control} control={form.control}
name="behinderPass" name="behinderPass"
@@ -28,7 +28,6 @@ import { env } from "@/config";
import type { MemShellFormSchema } from "@/types/schema"; import type { MemShellFormSchema } from "@/types/schema";
import { OptionalClassFormField } from "./classname-field"; import { OptionalClassFormField } from "./classname-field";
import { ShellTypeFormField } from "./shelltype-field"; import { ShellTypeFormField } from "./shelltype-field";
import { UrlPatternFormField } from "./urlpattern-field";
export function CommandTabContent({ export function CommandTabContent({
form, form,
@@ -54,10 +53,7 @@ export function CommandTabContent({
<TabsContent value="Command"> <TabsContent value="Command">
<Card> <Card>
<CardContent className="space-y-2 mt-4"> <CardContent className="space-y-2 mt-4">
<div className="grid grid-cols-1 md:grid-cols-2 gap-2"> <ShellTypeFormField form={form} shellTypes={shellTypes} />
<ShellTypeFormField form={form} shellTypes={shellTypes} />
<UrlPatternFormField form={form} />
</div>
<Controller <Controller
control={form.control} control={form.control}
name="commandParamName" name="commandParamName"
+25 -26
View File
@@ -13,7 +13,6 @@ import { env } from "@/config";
import type { MemShellFormSchema } from "@/types/schema"; import type { MemShellFormSchema } from "@/types/schema";
import { OptionalClassFormField } from "./classname-field"; import { OptionalClassFormField } from "./classname-field";
import { ShellTypeFormField } from "./shelltype-field"; import { ShellTypeFormField } from "./shelltype-field";
import { UrlPatternFormField } from "./urlpattern-field";
export default function CustomTabContent({ export default function CustomTabContent({
form, form,
@@ -87,15 +86,12 @@ export default function CustomTabContent({
<TabsContent value="Custom"> <TabsContent value="Custom">
<Card> <Card>
<CardContent className="space-y-2 mt-4"> <CardContent className="space-y-2 mt-4">
<div className="grid grid-cols-1 md:grid-cols-2 gap-2"> <ShellTypeFormField form={form} shellTypes={shellTypes} />
<ShellTypeFormField form={form} shellTypes={shellTypes} />
<UrlPatternFormField form={form} />
</div>
<Controller <Controller
control={form.control} control={form.control}
name="shellClassBase64" name="shellClassBase64"
render={({ field, fieldState }) => ( render={({ field, fieldState }) => (
<Field className="gap-1"> <Field className="gap-2">
<FieldLabel>{t("shellClass")}</FieldLabel> <FieldLabel>{t("shellClass")}</FieldLabel>
<RadioGroup <RadioGroup
value={isFile ? "file" : "base64"} value={isFile ? "file" : "base64"}
@@ -105,35 +101,38 @@ export default function CustomTabContent({
}} }}
className="flex items-center" className="flex items-center"
> >
<div className="flex items-center"> <div className="flex items-center gap-1">
<RadioGroupItem value="base64" id="optionOne" /> <RadioGroupItem value="base64" id="optionOne" />
<Label htmlFor="optionOne">Base64</Label> <Label htmlFor="optionOne">Base64</Label>
</div> </div>
<div className="flex items-center"> <div className="flex items-center gap-1">
<RadioGroupItem value="file" id="optionTwo" /> <RadioGroupItem value="file" id="optionTwo" />
<Label htmlFor="optionTwo">File</Label> <Label htmlFor="optionTwo">File</Label>
</div> </div>
</RadioGroup> </RadioGroup>
<div className="mt-2"> <div className="mt-2">
{isFile ? ( {isFile ? (
<Input <div className="grid w-full max-w-sm items-center gap-3">
onChange={(e) => { <Input
const file = e.target.files?.[0]; onChange={(e) => {
if (file) { const file = e.target.files?.[0];
const reader = new FileReader(); if (file) {
reader.onload = (event) => { const reader = new FileReader();
const base64String = reader.onload = (event) => {
(event.target?.result as string)?.split(",")[1] || const base64String =
""; (event.target?.result as string)?.split(
field.onChange(base64String); ",",
}; )[1] || "";
reader.readAsDataURL(file); field.onChange(base64String);
} };
}} reader.readAsDataURL(file);
accept=".class" }
placeholder={t("common:placeholders.input")} }}
type="file" accept=".class"
/> placeholder={t("common:placeholders.input")}
type="file"
/>
</div>
) : ( ) : (
<Textarea <Textarea
{...field} {...field}
@@ -7,7 +7,6 @@ import { TabsContent } from "@/components/ui/tabs";
import type { MemShellFormSchema } from "@/types/schema"; import type { MemShellFormSchema } from "@/types/schema";
import { OptionalClassFormField } from "./classname-field"; import { OptionalClassFormField } from "./classname-field";
import { ShellTypeFormField } from "./shelltype-field"; import { ShellTypeFormField } from "./shelltype-field";
import { UrlPatternFormField } from "./urlpattern-field";
export function GodzillaTabContent({ export function GodzillaTabContent({
form, form,
@@ -21,10 +20,7 @@ export function GodzillaTabContent({
<TabsContent value="Godzilla"> <TabsContent value="Godzilla">
<Card> <Card>
<CardContent className="flex flex-col gap-2 mt-4"> <CardContent className="flex flex-col gap-2 mt-4">
<div className="grid grid-cols-1 md:grid-cols-2 gap-2"> <ShellTypeFormField form={form} shellTypes={shellTypes} />
<ShellTypeFormField form={form} shellTypes={shellTypes} />
<UrlPatternFormField form={form} />
</div>
<div className="grid grid-cols-1 md:grid-cols-2 gap-2"> <div className="grid grid-cols-1 md:grid-cols-2 gap-2">
<Controller <Controller
control={form.control} control={form.control}
@@ -7,7 +7,6 @@ import { TabsContent } from "@/components/ui/tabs";
import type { MemShellFormSchema } from "@/types/schema"; import type { MemShellFormSchema } from "@/types/schema";
import { OptionalClassFormField } from "./classname-field"; import { OptionalClassFormField } from "./classname-field";
import { ShellTypeFormField } from "./shelltype-field"; import { ShellTypeFormField } from "./shelltype-field";
import { UrlPatternFormField } from "./urlpattern-field";
export function NeoRegTabContent({ export function NeoRegTabContent({
form, form,
@@ -21,10 +20,7 @@ export function NeoRegTabContent({
<TabsContent value="NeoreGeorg"> <TabsContent value="NeoreGeorg">
<Card> <Card>
<CardContent className="space-y-2 mt-4"> <CardContent className="space-y-2 mt-4">
<div className="grid grid-cols-1 md:grid-cols-2 gap-2"> <ShellTypeFormField form={form} shellTypes={shellTypes} />
<ShellTypeFormField form={form} shellTypes={shellTypes} />
<UrlPatternFormField form={form} />
</div>
<div className="grid grid-cols-1 md:grid-cols-2 gap-2"> <div className="grid grid-cols-1 md:grid-cols-2 gap-2">
<Controller <Controller
control={form.control} control={form.control}
@@ -1,6 +1,12 @@
import { Controller, type UseFormReturn } from "react-hook-form"; import { Controller, type UseFormReturn, useWatch } from "react-hook-form";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { Field, FieldLabel } from "@/components/ui/field"; import {
Field,
FieldContent,
FieldError,
FieldLabel,
} from "@/components/ui/field";
import { Input } from "@/components/ui/input";
import { import {
Select, Select,
SelectContent, SelectContent,
@@ -8,6 +14,7 @@ import {
SelectTrigger, SelectTrigger,
SelectValue, SelectValue,
} from "@/components/ui/select"; } from "@/components/ui/select";
import { cn, notNeedUrlPattern } from "@/lib/utils";
import type { MemShellFormSchema } from "@/types/schema"; import type { MemShellFormSchema } from "@/types/schema";
export function ShellTypeFormField({ export function ShellTypeFormField({
@@ -18,39 +25,118 @@ export function ShellTypeFormField({
shellTypes: Array<string>; shellTypes: Array<string>;
}>) { }>) {
const { t } = useTranslation(["memshell", "common"]); const { t } = useTranslation(["memshell", "common"]);
const shellType = useWatch({ control: form.control, name: "shellType" });
const server = useWatch({ control: form.control, name: "server" });
const needSelectServerVersion =
(server === "TongWeb" && shellType.endsWith("Valve")) ||
(server === "Jetty" &&
(shellType === "Handler" || shellType === "JakartaHandler"));
const needUrlPattern = !notNeedUrlPattern(shellType);
const serverVersionOptions = getServerVersionOptions(server);
return ( return (
<Controller <div className="grid grid-cols-1 md:grid-cols-2 gap-2">
control={form.control} <Controller
name="shellType" control={form.control}
render={({ field }) => ( name="shellType"
<Field className="gap-1"> render={({ field }) => (
<FieldLabel>{t("mainConfig.shellMountType")}</FieldLabel> <Field className="gap-1">
<Select <FieldLabel>{t("mainConfig.shellMountType")}</FieldLabel>
onValueChange={(e) => { <Select
form.resetField("urlPattern"); onValueChange={(e) => {
field.onChange(e); form.resetField("urlPattern");
}} field.onChange(e);
value={field.value} }}
> value={field.value}
<SelectTrigger> >
<SelectValue data-placeholder={t("common:placeholders.select")} /> <SelectTrigger>
</SelectTrigger> <SelectValue
<SelectContent key={shellTypes?.join(",")}> data-placeholder={t("common:placeholders.select")}
{shellTypes?.length ? ( />
shellTypes.map((v) => ( </SelectTrigger>
<SelectItem key={v} value={v}> <SelectContent key={shellTypes?.join(",")}>
{v} {shellTypes?.length ? (
shellTypes.map((v) => (
<SelectItem key={v} value={v}>
{v}
</SelectItem>
))
) : (
<SelectItem value=" ">
{t("tips.shellToolNotSelected")}
</SelectItem> </SelectItem>
)) )}
) : ( </SelectContent>
<SelectItem value=" "> </Select>
{t("tips.shellToolNotSelected")} </Field>
</SelectItem> )}
)} />
</SelectContent> <Controller
</Select> control={form.control}
</Field> name="urlPattern"
)} render={({ field, fieldState }) => (
/> <Field
className={cn("gap-1", needUrlPattern ? "grid" : "hidden")}
data-invalid={fieldState.invalid}
>
<FieldLabel>{t("common:urlPattern")}</FieldLabel>
<Input {...field} placeholder={t("common:placeholders.input")} />
{fieldState.error && <FieldError errors={[fieldState.error]} />}
</Field>
)}
/>
<Controller
control={form.control}
name="serverVersion"
render={({ field, fieldState }) => (
<Field
className={cn("gap-1", needSelectServerVersion ? "grid" : "hidden")}
orientation="vertical"
data-invalid={fieldState.invalid}
>
<FieldContent>
<FieldLabel htmlFor="serverVersion">
{t("common:serverVersion")}
</FieldLabel>
<Select onValueChange={field.onChange} value={field.value}>
<SelectTrigger
id="serverVersion"
aria-invalid={fieldState.invalid}
>
<SelectValue
data-placeholder={t("common:placeholders.select")}
/>
</SelectTrigger>
<SelectContent>
{serverVersionOptions.map((v) => (
<SelectItem key={v.value} value={v.value}>
{v.name}
</SelectItem>
))}
</SelectContent>
</Select>
{fieldState.error && <FieldError errors={[fieldState.error]} />}
</FieldContent>
</Field>
)}
/>
</div>
); );
} }
function getServerVersionOptions(server: string) {
let serverVersionOptions = [] as { name: string; value: string }[];
if (server === "TongWeb") {
serverVersionOptions = [
{ name: "6", value: "6" },
{ name: "7", value: "7" },
{ name: "8", value: "8" },
];
} else if (server === "Jetty") {
serverVersionOptions = [
{ name: "6", value: "6" },
{ name: "7+", value: "7+" },
{ name: "12", value: "12" },
];
}
return serverVersionOptions;
}
@@ -7,7 +7,6 @@ import { TabsContent } from "@/components/ui/tabs";
import type { MemShellFormSchema } from "@/types/schema"; import type { MemShellFormSchema } from "@/types/schema";
import { OptionalClassFormField } from "./classname-field"; import { OptionalClassFormField } from "./classname-field";
import { ShellTypeFormField } from "./shelltype-field"; import { ShellTypeFormField } from "./shelltype-field";
import { UrlPatternFormField } from "./urlpattern-field";
export function Suo5TabContent({ export function Suo5TabContent({
form, form,
@@ -23,10 +22,7 @@ export function Suo5TabContent({
<TabsContent value={tabValue}> <TabsContent value={tabValue}>
<Card> <Card>
<CardContent className="space-y-2 mt-4"> <CardContent className="space-y-2 mt-4">
<div className="grid grid-cols-1 md:grid-cols-2 gap-2"> <ShellTypeFormField form={form} shellTypes={shellTypes} />
<ShellTypeFormField form={form} shellTypes={shellTypes} />
<UrlPatternFormField form={form} />
</div>
<div className="grid grid-cols-1 md:grid-cols-2 gap-2"> <div className="grid grid-cols-1 md:grid-cols-2 gap-2">
<Controller <Controller
control={form.control} control={form.control}
@@ -1,29 +0,0 @@
import { Controller, type UseFormReturn } from "react-hook-form";
import { useTranslation } from "react-i18next";
import { Field, FieldError, FieldLabel } from "@/components/ui/field";
import { Input } from "@/components/ui/input";
import { cn, shouldHidden } from "@/lib/utils";
import type { MemShellFormSchema } from "@/types/schema";
export function UrlPatternFormField({
form,
}: Readonly<{ form: UseFormReturn<MemShellFormSchema> }>) {
const { t } = useTranslation("common");
const shellType = form.watch("shellType");
return (
<Controller
control={form.control}
name="urlPattern"
render={({ field, fieldState }) => (
<Field
className={cn("gap-1", shouldHidden(shellType) ? "hidden" : "grid")}
data-invalid={fieldState.invalid}
>
<FieldLabel>{t("urlPattern")}</FieldLabel>
<Input {...field} placeholder={t("placeholders.input")} />
{fieldState.error && <FieldError errors={[fieldState.error]} />}
</Field>
)}
/>
);
}
+1 -1
View File
@@ -69,7 +69,7 @@ export function formatBytes(bytes: number) {
return `${kbValue} ${sizes[1]}`; return `${kbValue} ${sizes[1]}`;
} }
export function shouldHidden(shellType: string | undefined) { export function notNeedUrlPattern(shellType: string | undefined) {
if (shellType === undefined) { if (shellType === undefined) {
return false; return false;
} }