@@ -14,6 +14,7 @@ import { client } from "../../client"
1414import { useChangeSettings } from "../../contexts"
1515import { QueryKeys } from "../../queryKeys"
1616import { TContextOptionName } from "../../types"
17+ import { Command } from "../../client/command"
1718
1819const DEFAULT_DEVPOD_AGENT_URL = "https://github.com/loft-sh/devpod/releases/latest/download/"
1920
@@ -40,34 +41,22 @@ export function useContextOptions() {
4041 [ options , updateOption ]
4142 )
4243}
43-
44- export function useSettingsOptions ( ) {
44+ export function useCLIFlagsOption ( ) {
4545 const { settings, set } = useChangeSettings ( )
46- const { mutate : updateOption } = useMutation ( {
47- mutationFn : async ( { value } : { value : string } ) => {
46+ const updateOption = useCallback (
47+ ( value : string ) => {
4848 set ( "additionalCliFlags" , value )
4949 client . setSetting ( "additionalCliFlags" , value )
5050 } ,
51- } )
52-
53- return useMemo (
54- ( ) => ( {
55- settings,
56- updateOption,
57- } ) ,
58- [ settings , updateOption ]
51+ [ set ]
5952 )
60- }
61-
62- export function useCLIFlagsOption ( ) {
63- const { settings, updateOption } = useSettingsOptions ( )
6453 const [ hasFocus , setHasFocus ] = useState ( false )
6554 const inputRef = useRef < HTMLInputElement > ( null )
6655
6756 const handleBlur = useCallback (
6857 ( e : FocusEvent < HTMLInputElement > ) => {
6958 const value = e . target . value . trim ( )
70- updateOption ( { value } )
59+ updateOption ( value )
7160 setHasFocus ( false )
7261 } ,
7362 [ updateOption ]
@@ -96,7 +85,7 @@ export function useCLIFlagsOption() {
9685 < Input
9786 ref = { inputRef }
9887 spellCheck = { false }
99- placeholder = "CLI Additional Flags"
88+ placeholder = "Additional CLI Flags"
10089 defaultValue = { settings . additionalCliFlags }
10190 onBlur = { handleBlur }
10291 onKeyUp = { handleKeyUp }
@@ -129,10 +118,11 @@ export function useCLIFlagsOption() {
129118 ]
130119 )
131120
132- const helpText = useMemo ( ( ) => < > Set the additional CLI Flags to use.</ > , [ ] )
121+ const helpText = useMemo ( ( ) => < > Set additional CLI Flags to use.</ > , [ ] )
133122
134123 return { input, helpText }
135124}
125+
136126export function useAgentURLOption ( ) {
137127 const { options, updateOption } = useContextOptions ( )
138128 const [ hasFocus , setHasFocus ] = useState ( false )
@@ -244,3 +234,80 @@ export function useTelemetryOption() {
244234
245235 return { input, helpText }
246236}
237+
238+ export function useExtraEnvVarsOption ( ) {
239+ const { settings, set } = useChangeSettings ( )
240+ const [ hasFocus , setHasFocus ] = useState ( false )
241+ const inputRef = useRef < HTMLInputElement > ( null )
242+
243+ const handleBlur = useCallback (
244+ ( e : FocusEvent < HTMLInputElement > ) => {
245+ const value = e . target . value . trim ( )
246+ set ( "additionalEnvVars" , value )
247+ Command . ADDITIONAL_ENV_VARS = value
248+ setHasFocus ( false )
249+ } ,
250+ [ set ]
251+ )
252+
253+ const handleKeyUp = useCallback ( ( e : KeyboardEvent < HTMLInputElement > ) => {
254+ if ( e . key !== "Enter" ) return
255+
256+ e . currentTarget . blur ( )
257+ } , [ ] )
258+
259+ const handleFocus = useCallback ( ( ) => {
260+ setHasFocus ( true )
261+ } , [ ] )
262+
263+ const handleClear = useCallback ( ( ) => {
264+ const el = inputRef . current
265+ if ( ! el ) return
266+
267+ el . value = ""
268+ } , [ ] )
269+
270+ const input = useMemo (
271+ ( ) => (
272+ < InputGroup maxWidth = "72" >
273+ < Input
274+ ref = { inputRef }
275+ spellCheck = { false }
276+ placeholder = "Additional Environment Variables"
277+ defaultValue = { settings . additionalEnvVars }
278+ onBlur = { handleBlur }
279+ onKeyUp = { handleKeyUp }
280+ onFocus = { handleFocus }
281+ />
282+ < InputRightElement >
283+ < IconButton
284+ visibility = { hasFocus ? "visible" : "hidden" }
285+ size = "xs"
286+ borderRadius = "full"
287+ icon = { < CloseIcon /> }
288+ aria-label = "clear"
289+ onMouseDown = { ( e ) => {
290+ // needed to prevent losing focus from input
291+ e . stopPropagation ( )
292+ e . preventDefault ( )
293+ } }
294+ onClick = { handleClear }
295+ />
296+ </ InputRightElement >
297+ </ InputGroup >
298+ ) ,
299+ [ settings . additionalEnvVars , handleBlur , handleKeyUp , handleFocus , hasFocus , handleClear ]
300+ )
301+
302+ const helpText = useMemo (
303+ ( ) => (
304+ < >
305+ Set additional environment variables DevPod passes to all commands. Accepts a comma
306+ separated list, e.g. FOO=bar,BAZ=false
307+ </ >
308+ ) ,
309+ [ ]
310+ )
311+
312+ return { input, helpText }
313+ }
0 commit comments