Skip to content

Commit c1f4cb5

Browse files
committed
refactor(ui): change serverVersion field localtion
1 parent 5a6ecc5 commit c1f4cb5

File tree

11 files changed

+154
-122
lines changed

11 files changed

+154
-122
lines changed

web/app/components/memshell/results/basic-info.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { FileTextIcon } from "lucide-react";
22
import { useTranslation } from "react-i18next";
33
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
44
import { Separator } from "@/components/ui/separator";
5-
import { shouldHidden } from "@/lib/utils";
5+
import { notNeedUrlPattern } from "@/lib/utils";
66
import {
77
type AntSwordShellToolConfig,
88
type BehinderShellToolConfig,
@@ -45,7 +45,7 @@ export function BasicInfo({
4545
label={t("mainConfig.shellMountType")}
4646
text={generateResult?.shellConfig.shellType}
4747
/>
48-
{!shouldHidden(generateResult?.shellConfig?.shellType) && (
48+
{!notNeedUrlPattern(generateResult?.shellConfig?.shellType) && (
4949
<CopyableField
5050
label={t("mainConfig.urlPattern")}
5151
text={generateResult?.injectorConfig.urlPattern}

web/app/components/memshell/tabs/antsword-tab.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { TabsContent } from "@/components/ui/tabs";
77
import type { MemShellFormSchema } from "@/types/schema";
88
import { OptionalClassFormField } from "./classname-field";
99
import { ShellTypeFormField } from "./shelltype-field";
10-
import { UrlPatternFormField } from "./urlpattern-field";
1110

1211
export function AntSwordTabContent({
1312
form,
@@ -21,10 +20,7 @@ export function AntSwordTabContent({
2120
<TabsContent value="AntSword">
2221
<Card>
2322
<CardContent className="space-y-2 mt-4">
24-
<div className="grid grid-cols-1 md:grid-cols-2 gap-2">
25-
<ShellTypeFormField form={form} shellTypes={shellTypes} />
26-
<UrlPatternFormField form={form} />
27-
</div>
23+
<ShellTypeFormField form={form} shellTypes={shellTypes} />
2824
<Controller
2925
control={form.control}
3026
name="antSwordPass"

web/app/components/memshell/tabs/behinder-tab.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { TabsContent } from "@/components/ui/tabs";
77
import type { MemShellFormSchema } from "@/types/schema";
88
import { OptionalClassFormField } from "./classname-field";
99
import { ShellTypeFormField } from "./shelltype-field";
10-
import { UrlPatternFormField } from "./urlpattern-field";
1110

1211
export function BehinderTabContent({
1312
form,
@@ -21,10 +20,7 @@ export function BehinderTabContent({
2120
<TabsContent value="Behinder">
2221
<Card>
2322
<CardContent className="space-y-2 mt-4">
24-
<div className="grid grid-cols-1 md:grid-cols-2 gap-2">
25-
<ShellTypeFormField form={form} shellTypes={shellTypes} />
26-
<UrlPatternFormField form={form} />
27-
</div>
23+
<ShellTypeFormField form={form} shellTypes={shellTypes} />
2824
<Controller
2925
control={form.control}
3026
name="behinderPass"

web/app/components/memshell/tabs/command-tab.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import { env } from "@/config";
2828
import type { MemShellFormSchema } from "@/types/schema";
2929
import { OptionalClassFormField } from "./classname-field";
3030
import { ShellTypeFormField } from "./shelltype-field";
31-
import { UrlPatternFormField } from "./urlpattern-field";
3231

3332
export function CommandTabContent({
3433
form,
@@ -54,10 +53,7 @@ export function CommandTabContent({
5453
<TabsContent value="Command">
5554
<Card>
5655
<CardContent className="space-y-2 mt-4">
57-
<div className="grid grid-cols-1 md:grid-cols-2 gap-2">
58-
<ShellTypeFormField form={form} shellTypes={shellTypes} />
59-
<UrlPatternFormField form={form} />
60-
</div>
56+
<ShellTypeFormField form={form} shellTypes={shellTypes} />
6157
<Controller
6258
control={form.control}
6359
name="commandParamName"

web/app/components/memshell/tabs/custom-tab.tsx

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { env } from "@/config";
1313
import type { MemShellFormSchema } from "@/types/schema";
1414
import { OptionalClassFormField } from "./classname-field";
1515
import { ShellTypeFormField } from "./shelltype-field";
16-
import { UrlPatternFormField } from "./urlpattern-field";
1716

1817
export default function CustomTabContent({
1918
form,
@@ -87,15 +86,12 @@ export default function CustomTabContent({
8786
<TabsContent value="Custom">
8887
<Card>
8988
<CardContent className="space-y-2 mt-4">
90-
<div className="grid grid-cols-1 md:grid-cols-2 gap-2">
91-
<ShellTypeFormField form={form} shellTypes={shellTypes} />
92-
<UrlPatternFormField form={form} />
93-
</div>
89+
<ShellTypeFormField form={form} shellTypes={shellTypes} />
9490
<Controller
9591
control={form.control}
9692
name="shellClassBase64"
9793
render={({ field, fieldState }) => (
98-
<Field className="gap-1">
94+
<Field className="gap-2">
9995
<FieldLabel>{t("shellClass")}</FieldLabel>
10096
<RadioGroup
10197
value={isFile ? "file" : "base64"}
@@ -105,35 +101,38 @@ export default function CustomTabContent({
105101
}}
106102
className="flex items-center"
107103
>
108-
<div className="flex items-center">
104+
<div className="flex items-center gap-1">
109105
<RadioGroupItem value="base64" id="optionOne" />
110106
<Label htmlFor="optionOne">Base64</Label>
111107
</div>
112-
<div className="flex items-center">
108+
<div className="flex items-center gap-1">
113109
<RadioGroupItem value="file" id="optionTwo" />
114110
<Label htmlFor="optionTwo">File</Label>
115111
</div>
116112
</RadioGroup>
117113
<div className="mt-2">
118114
{isFile ? (
119-
<Input
120-
onChange={(e) => {
121-
const file = e.target.files?.[0];
122-
if (file) {
123-
const reader = new FileReader();
124-
reader.onload = (event) => {
125-
const base64String =
126-
(event.target?.result as string)?.split(",")[1] ||
127-
"";
128-
field.onChange(base64String);
129-
};
130-
reader.readAsDataURL(file);
131-
}
132-
}}
133-
accept=".class"
134-
placeholder={t("common:placeholders.input")}
135-
type="file"
136-
/>
115+
<div className="grid w-full max-w-sm items-center gap-3">
116+
<Input
117+
onChange={(e) => {
118+
const file = e.target.files?.[0];
119+
if (file) {
120+
const reader = new FileReader();
121+
reader.onload = (event) => {
122+
const base64String =
123+
(event.target?.result as string)?.split(
124+
",",
125+
)[1] || "";
126+
field.onChange(base64String);
127+
};
128+
reader.readAsDataURL(file);
129+
}
130+
}}
131+
accept=".class"
132+
placeholder={t("common:placeholders.input")}
133+
type="file"
134+
/>
135+
</div>
137136
) : (
138137
<Textarea
139138
{...field}

web/app/components/memshell/tabs/godzilla-tab.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { TabsContent } from "@/components/ui/tabs";
77
import type { MemShellFormSchema } from "@/types/schema";
88
import { OptionalClassFormField } from "./classname-field";
99
import { ShellTypeFormField } from "./shelltype-field";
10-
import { UrlPatternFormField } from "./urlpattern-field";
1110

1211
export function GodzillaTabContent({
1312
form,
@@ -21,10 +20,7 @@ export function GodzillaTabContent({
2120
<TabsContent value="Godzilla">
2221
<Card>
2322
<CardContent className="flex flex-col gap-2 mt-4">
24-
<div className="grid grid-cols-1 md:grid-cols-2 gap-2">
25-
<ShellTypeFormField form={form} shellTypes={shellTypes} />
26-
<UrlPatternFormField form={form} />
27-
</div>
23+
<ShellTypeFormField form={form} shellTypes={shellTypes} />
2824
<div className="grid grid-cols-1 md:grid-cols-2 gap-2">
2925
<Controller
3026
control={form.control}

web/app/components/memshell/tabs/neoreg-tab.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { TabsContent } from "@/components/ui/tabs";
77
import type { MemShellFormSchema } from "@/types/schema";
88
import { OptionalClassFormField } from "./classname-field";
99
import { ShellTypeFormField } from "./shelltype-field";
10-
import { UrlPatternFormField } from "./urlpattern-field";
1110

1211
export function NeoRegTabContent({
1312
form,
@@ -21,10 +20,7 @@ export function NeoRegTabContent({
2120
<TabsContent value="NeoreGeorg">
2221
<Card>
2322
<CardContent className="space-y-2 mt-4">
24-
<div className="grid grid-cols-1 md:grid-cols-2 gap-2">
25-
<ShellTypeFormField form={form} shellTypes={shellTypes} />
26-
<UrlPatternFormField form={form} />
27-
</div>
23+
<ShellTypeFormField form={form} shellTypes={shellTypes} />
2824
<div className="grid grid-cols-1 md:grid-cols-2 gap-2">
2925
<Controller
3026
control={form.control}
Lines changed: 120 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1-
import { Controller, type UseFormReturn } from "react-hook-form";
1+
import { Controller, type UseFormReturn, useWatch } from "react-hook-form";
22
import { useTranslation } from "react-i18next";
3-
import { Field, FieldLabel } from "@/components/ui/field";
3+
import {
4+
Field,
5+
FieldContent,
6+
FieldError,
7+
FieldLabel,
8+
} from "@/components/ui/field";
9+
import { Input } from "@/components/ui/input";
410
import {
511
Select,
612
SelectContent,
713
SelectItem,
814
SelectTrigger,
915
SelectValue,
1016
} from "@/components/ui/select";
17+
import { cn, notNeedUrlPattern } from "@/lib/utils";
1118
import type { MemShellFormSchema } from "@/types/schema";
1219

1320
export function ShellTypeFormField({
@@ -18,39 +25,118 @@ export function ShellTypeFormField({
1825
shellTypes: Array<string>;
1926
}>) {
2027
const { t } = useTranslation(["memshell", "common"]);
28+
const shellType = useWatch({ control: form.control, name: "shellType" });
29+
const server = useWatch({ control: form.control, name: "server" });
30+
const needSelectServerVersion =
31+
(server === "TongWeb" && shellType.endsWith("Valve")) ||
32+
(server === "Jetty" &&
33+
(shellType === "Handler" || shellType === "JakartaHandler"));
34+
const needUrlPattern = !notNeedUrlPattern(shellType);
35+
const serverVersionOptions = getServerVersionOptions(server);
2136
return (
22-
<Controller
23-
control={form.control}
24-
name="shellType"
25-
render={({ field }) => (
26-
<Field className="gap-1">
27-
<FieldLabel>{t("mainConfig.shellMountType")}</FieldLabel>
28-
<Select
29-
onValueChange={(e) => {
30-
form.resetField("urlPattern");
31-
field.onChange(e);
32-
}}
33-
value={field.value}
34-
>
35-
<SelectTrigger>
36-
<SelectValue data-placeholder={t("common:placeholders.select")} />
37-
</SelectTrigger>
38-
<SelectContent key={shellTypes?.join(",")}>
39-
{shellTypes?.length ? (
40-
shellTypes.map((v) => (
41-
<SelectItem key={v} value={v}>
42-
{v}
37+
<div className="grid grid-cols-1 md:grid-cols-2 gap-2">
38+
<Controller
39+
control={form.control}
40+
name="shellType"
41+
render={({ field }) => (
42+
<Field className="gap-1">
43+
<FieldLabel>{t("mainConfig.shellMountType")}</FieldLabel>
44+
<Select
45+
onValueChange={(e) => {
46+
form.resetField("urlPattern");
47+
field.onChange(e);
48+
}}
49+
value={field.value}
50+
>
51+
<SelectTrigger>
52+
<SelectValue
53+
data-placeholder={t("common:placeholders.select")}
54+
/>
55+
</SelectTrigger>
56+
<SelectContent key={shellTypes?.join(",")}>
57+
{shellTypes?.length ? (
58+
shellTypes.map((v) => (
59+
<SelectItem key={v} value={v}>
60+
{v}
61+
</SelectItem>
62+
))
63+
) : (
64+
<SelectItem value=" ">
65+
{t("tips.shellToolNotSelected")}
4366
</SelectItem>
44-
))
45-
) : (
46-
<SelectItem value=" ">
47-
{t("tips.shellToolNotSelected")}
48-
</SelectItem>
49-
)}
50-
</SelectContent>
51-
</Select>
52-
</Field>
53-
)}
54-
/>
67+
)}
68+
</SelectContent>
69+
</Select>
70+
</Field>
71+
)}
72+
/>
73+
<Controller
74+
control={form.control}
75+
name="urlPattern"
76+
render={({ field, fieldState }) => (
77+
<Field
78+
className={cn("gap-1", needUrlPattern ? "grid" : "hidden")}
79+
data-invalid={fieldState.invalid}
80+
>
81+
<FieldLabel>{t("common:urlPattern")}</FieldLabel>
82+
<Input {...field} placeholder={t("common:placeholders.input")} />
83+
{fieldState.error && <FieldError errors={[fieldState.error]} />}
84+
</Field>
85+
)}
86+
/>
87+
<Controller
88+
control={form.control}
89+
name="serverVersion"
90+
render={({ field, fieldState }) => (
91+
<Field
92+
className={cn("gap-1", needSelectServerVersion ? "grid" : "hidden")}
93+
orientation="vertical"
94+
data-invalid={fieldState.invalid}
95+
>
96+
<FieldContent>
97+
<FieldLabel htmlFor="serverVersion">
98+
{t("common:serverVersion")}
99+
</FieldLabel>
100+
<Select onValueChange={field.onChange} value={field.value}>
101+
<SelectTrigger
102+
id="serverVersion"
103+
aria-invalid={fieldState.invalid}
104+
>
105+
<SelectValue
106+
data-placeholder={t("common:placeholders.select")}
107+
/>
108+
</SelectTrigger>
109+
<SelectContent>
110+
{serverVersionOptions.map((v) => (
111+
<SelectItem key={v.value} value={v.value}>
112+
{v.name}
113+
</SelectItem>
114+
))}
115+
</SelectContent>
116+
</Select>
117+
{fieldState.error && <FieldError errors={[fieldState.error]} />}
118+
</FieldContent>
119+
</Field>
120+
)}
121+
/>
122+
</div>
55123
);
56124
}
125+
126+
function getServerVersionOptions(server: string) {
127+
let serverVersionOptions = [] as { name: string; value: string }[];
128+
if (server === "TongWeb") {
129+
serverVersionOptions = [
130+
{ name: "6", value: "6" },
131+
{ name: "7", value: "7" },
132+
{ name: "8", value: "8" },
133+
];
134+
} else if (server === "Jetty") {
135+
serverVersionOptions = [
136+
{ name: "6", value: "6" },
137+
{ name: "7+", value: "7+" },
138+
{ name: "12", value: "12" },
139+
];
140+
}
141+
return serverVersionOptions;
142+
}

web/app/components/memshell/tabs/suo5-tab.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { TabsContent } from "@/components/ui/tabs";
77
import type { MemShellFormSchema } from "@/types/schema";
88
import { OptionalClassFormField } from "./classname-field";
99
import { ShellTypeFormField } from "./shelltype-field";
10-
import { UrlPatternFormField } from "./urlpattern-field";
1110

1211
export function Suo5TabContent({
1312
form,
@@ -23,10 +22,7 @@ export function Suo5TabContent({
2322
<TabsContent value={tabValue}>
2423
<Card>
2524
<CardContent className="space-y-2 mt-4">
26-
<div className="grid grid-cols-1 md:grid-cols-2 gap-2">
27-
<ShellTypeFormField form={form} shellTypes={shellTypes} />
28-
<UrlPatternFormField form={form} />
29-
</div>
25+
<ShellTypeFormField form={form} shellTypes={shellTypes} />
3026
<div className="grid grid-cols-1 md:grid-cols-2 gap-2">
3127
<Controller
3228
control={form.control}

0 commit comments

Comments
 (0)