@@ -51,13 +51,12 @@ const MIDDLEWARE_OPTIONS = [
5151] as const ;
5252
5353const PROBE_METHOD_OPTIONS = [
54- { value : "Sleep" , label : "Sleep" } ,
55- { value : "DNSLog" , label : "DNSLog" } ,
5654 { value : "ResponseBody" , label : "ResponseBody" } ,
55+ { value : "DNSLog" , label : "DNSLog" } ,
56+ { value : "Sleep" , label : "Sleep" } ,
5757] as const ;
5858
5959const DEFAULT_FORM_VALUES = {
60- reqParamName : "payload" ,
6160 sleepServer : "Tomcat" ,
6261 seconds : 5 ,
6362} as const ;
@@ -143,7 +142,9 @@ export default function MainConfigCard({ form, servers }: MainConfigCardProps) {
143142 name = "reqParamName"
144143 render = { ( { field } ) => (
145144 < FormFieldItem >
146- < FormFieldLabel > { t ( "common:paramName" ) } </ FormFieldLabel >
145+ < FormFieldLabel >
146+ { t ( "common:paramName" ) } { t ( "common:optional" ) }
147+ </ FormFieldLabel >
147148 < FormControl >
148149 < Input placeholder = { t ( "placeholders.input" ) } { ...field } />
149150 </ FormControl >
@@ -158,45 +159,28 @@ export default function MainConfigCard({ form, servers }: MainConfigCardProps) {
158159
159160 const CommandTemplateField = useMemo (
160161 ( ) => (
161- < >
162- < div className = "space-y-2 pt-4 border-t mt-4" >
163- < FormField
164- control = { form . control }
165- name = "reqParamName"
166- render = { ( { field } ) => (
167- < FormFieldItem >
168- < FormFieldLabel > { t ( "common:paramName" ) } </ FormFieldLabel >
169- < FormControl >
170- < Input placeholder = { t ( "placeholders.input" ) } { ...field } />
171- </ FormControl >
172- < FormMessage />
173- </ FormFieldItem >
174- ) }
175- />
176- </ div >
177- < div className = "space-y-2" >
178- < FormField
179- control = { form . control }
180- name = "commandTemplate"
181- render = { ( { field } ) => (
182- < FormFieldItem >
183- < FormFieldLabel >
184- { t ( "common:commandTemplate" ) } { t ( "common:optional" ) }
185- </ FormFieldLabel >
186- < FormControl >
187- < Input
188- { ...field }
189- placeholder = { t ( "common:commandTemplate.placeholder" ) }
190- />
191- </ FormControl >
192- < p className = "text-xs text-muted-foreground mt-1" >
193- { t ( "common:commandTemplate.description" ) }
194- </ p >
195- </ FormFieldItem >
196- ) }
197- />
198- </ div >
199- </ >
162+ < div className = "space-y-2" >
163+ < FormField
164+ control = { form . control }
165+ name = "commandTemplate"
166+ render = { ( { field } ) => (
167+ < FormFieldItem >
168+ < FormFieldLabel >
169+ { t ( "common:commandTemplate" ) } { t ( "common:optional" ) }
170+ </ FormFieldLabel >
171+ < FormControl >
172+ < Input
173+ { ...field }
174+ placeholder = { t ( "common:commandTemplate.placeholder" ) }
175+ />
176+ </ FormControl >
177+ < p className = "text-xs text-muted-foreground mt-1" >
178+ { t ( "common:commandTemplate.description" ) }
179+ </ p >
180+ </ FormFieldItem >
181+ ) }
182+ />
183+ </ div >
200184 ) ,
201185 [ form . control , t ] ,
202186 ) ;
@@ -251,35 +235,6 @@ export default function MainConfigCard({ form, servers }: MainConfigCardProps) {
251235 [ form . control , t ] ,
252236 ) ;
253237
254- const renderDynamicFields = useCallback ( ( ) => {
255- const isBodyMethod = watchedProbeMethod === "ResponseBody" ;
256- const needParam =
257- watchedProbeContent === "Command" ||
258- watchedProbeContent === "Bytecode" ||
259- watchedProbeContent === "ScriptEngine" ;
260- const isSleepMethod = watchedProbeMethod === "Sleep" ;
261- const isServerContent = watchedProbeContent === "Server" ;
262-
263- if ( isBodyMethod && needParam ) {
264- if ( watchedProbeContent === "Command" ) {
265- return CommandTemplateField ;
266- }
267- return RequestParamField ;
268- }
269-
270- if ( isSleepMethod && isServerContent ) {
271- return SleepFields ;
272- }
273-
274- return null ;
275- } , [
276- watchedProbeMethod ,
277- watchedProbeContent ,
278- RequestParamField ,
279- SleepFields ,
280- CommandTemplateField ,
281- ] ) ;
282-
283238 const DNSLogSection = useMemo (
284239 ( ) => (
285240 < FormField
@@ -421,6 +376,15 @@ export default function MainConfigCard({ form, servers }: MainConfigCardProps) {
421376 [ form . control , t ] ,
422377 ) ;
423378
379+ const isBodyMethod = watchedProbeMethod === "ResponseBody" ;
380+ const isCommandBody = watchedProbeContent === "Command" ;
381+ const needParam =
382+ isCommandBody ||
383+ watchedProbeContent === "Bytecode" ||
384+ watchedProbeContent === "ScriptEngine" ;
385+ const isSleepMethod = watchedProbeMethod === "Sleep" ;
386+ const isServerContent = watchedProbeContent === "Server" ;
387+
424388 return (
425389 < FormProvider { ...form } >
426390 < Card >
@@ -463,7 +427,9 @@ export default function MainConfigCard({ form, servers }: MainConfigCardProps) {
463427 { watchedProbeMethod === "DNSLog" && DNSLogSection }
464428 { watchedProbeMethod && ContentOptionsSelect }
465429 { SwitchGroup }
466- { renderDynamicFields ( ) }
430+ { isBodyMethod && needParam && RequestParamField }
431+ { isBodyMethod && isCommandBody && CommandTemplateField }
432+ { isSleepMethod && isServerContent && SleepFields }
467433 < Separator />
468434 < FormField
469435 control = { form . control }
0 commit comments