11import { Check , ChevronDown } from 'lucide-react'
2+ import { useState } from 'react'
23import { Button } from '../ui/button'
34import { Popover , PopoverContent , PopoverTrigger } from '../ui/popover'
45import type { FieldValues , Path , UseFormReturn } from 'react-hook-form'
@@ -15,6 +16,7 @@ import { cn } from '@/common/lib/utils'
1516import { useQuery } from '@tanstack/react-query'
1617import { getApiV1BetaSecretsDefaultKeysOptions } from '@/common/api/generated/@tanstack/react-query.gen'
1718import { RefreshButton } from '../refresh-button'
19+ import { delay } from '../../../../../utils/delay'
1820
1921type ConstrainedFieldValues = FieldValues & {
2022 secrets : {
@@ -35,14 +37,15 @@ export function FormComboboxSecretStore<
3537 T extends ConstrainedFieldValues = ConstrainedFieldValues ,
3638> ( { form, name } : { form : UseFormReturn < T > ; name : Path < T > } ) {
3739 const { data, refetch } = useQuery ( getApiV1BetaSecretsDefaultKeysOptions ( ) )
40+ const [ isOpen , setIsOpen ] = useState ( false )
3841
3942 return (
4043 < FormField
4144 control = { form . control }
4245 name = { name }
4346 render = { ( { field } ) => (
4447 < FormItem >
45- < Popover >
48+ < Popover open = { isOpen } onOpenChange = { setIsOpen } >
4649 < PopoverTrigger asChild >
4750 < FormControl >
4851 < Button
@@ -89,11 +92,13 @@ export function FormComboboxSecretStore<
8992 key = { secret . key }
9093 value = { secret . key }
9194 className = "font-mono"
92- onSelect = { ( value ) => {
95+ onSelect = { async ( value ) => {
9396 field . onChange ( {
9497 secret : value ,
9598 isFromStore : true ,
9699 } )
100+ await delay ( 150 )
101+ setIsOpen ( false )
97102 } }
98103 >
99104 { secret . key }
0 commit comments