1
1
// kilocode_change - new file
2
2
import { VSCodeTextField } from "@vscode/webview-ui-toolkit/react"
3
- import { Trans , useTranslation } from "react-i18next"
3
+ import { useTranslation } from "react-i18next"
4
4
import { vscode } from "@/utils/vscode"
5
+ import { useCallback } from "react"
5
6
6
7
interface MaxRequestsInputProps {
7
8
allowedMaxRequests ?: number | undefined
8
9
onValueChange : ( value : number | undefined ) => void
9
- variant ?: "menu" | "settings"
10
10
className ?: string
11
- style ?: React . CSSProperties
12
- testId ?: string
13
11
}
14
12
15
- export function MaxRequestsInput ( {
16
- allowedMaxRequests,
17
- onValueChange,
18
- variant = "settings" ,
19
- className,
20
- style,
21
- testId,
22
- } : MaxRequestsInputProps ) {
13
+ export function MaxRequestsInput ( { allowedMaxRequests, onValueChange, className } : MaxRequestsInputProps ) {
23
14
const { t } = useTranslation ( )
24
15
25
- const handleInput = ( e : any ) => {
26
- const input = e . target as HTMLInputElement
27
- input . value = input . value . replace ( / [ ^ 0 - 9 ] / g, "" )
28
- const value = parseInt ( input . value )
29
- const parsedValue = ! isNaN ( value ) && value > 0 ? value : undefined
30
- onValueChange ( parsedValue )
31
- vscode . postMessage ( { type : "allowedMaxRequests" , value : parsedValue } )
32
- }
16
+ const handleInput = useCallback (
17
+ ( e : any ) => {
18
+ const input = e . target as HTMLInputElement
19
+ input . value = input . value . replace ( / [ ^ 0 - 9 ] / g, "" )
20
+ const value = parseInt ( input . value )
21
+ const parsedValue = ! isNaN ( value ) && value > 0 ? value : undefined
22
+ onValueChange ( parsedValue )
23
+ vscode . postMessage ( { type : "allowedMaxRequests" , value : parsedValue } )
24
+ } ,
25
+ [ onValueChange ] ,
26
+ )
33
27
34
28
const inputValue = ( allowedMaxRequests ?? Infinity ) === Infinity ? "" : allowedMaxRequests ?. toString ( )
35
29
36
- if ( variant === "menu" ) {
37
- return (
38
- < >
39
- < div
40
- style = { {
41
- display : "flex" ,
42
- alignItems : "center" ,
43
- gap : "8px" ,
44
- marginTop : "10px" ,
45
- marginBottom : "8px" ,
46
- color : "var(--vscode-descriptionForeground)" ,
47
- ...style ,
48
- } }
49
- className = { className } >
50
- < span style = { { flexShrink : 1 , minWidth : 0 } } >
51
- < Trans i18nKey = "settings:autoApprove.apiRequestLimit.title" /> :
52
- </ span >
53
- < VSCodeTextField
54
- placeholder = { t ( "settings:autoApprove.apiRequestLimit.unlimited" ) }
55
- value = { inputValue }
56
- onInput = { handleInput }
57
- style = { { flex : 1 } }
58
- data-testid = { testId }
59
- />
60
- </ div >
61
- < div
62
- style = { {
63
- color : "var(--vscode-descriptionForeground)" ,
64
- fontSize : "12px" ,
65
- marginBottom : "10px" ,
66
- } } >
67
- < Trans i18nKey = "settings:autoApprove.apiRequestLimit.description" />
68
- </ div >
69
- </ >
70
- )
71
- }
72
-
73
30
return (
74
- < div
75
- className = { `flex flex-col gap-3 pl-3 border-l-2 border-vscode-button-background ${ className || "" } ` }
76
- style = { style } >
31
+ < div className = { `flex flex-col gap-3 pl-3 border-l-2 border-vscode-button-background ${ className || "" } ` } >
77
32
< div className = "flex items-center gap-4 font-bold" >
78
33
< span className = "codicon codicon-pulse" />
79
34
< div > { t ( "settings:autoApprove.apiRequestLimit.title" ) } </ div >
@@ -84,7 +39,7 @@ export function MaxRequestsInput({
84
39
value = { inputValue }
85
40
onInput = { handleInput }
86
41
style = { { flex : 1 , maxWidth : "200px" } }
87
- data-testid = { testId || "max-requests-input" }
42
+ data-testid = "max-requests-input"
88
43
/>
89
44
</ div >
90
45
< div className = "text-vscode-descriptionForeground text-sm" >
0 commit comments