import { noop } from 'lodash' import { Plus } from 'lucide-react' import { Input, Listbox, Modal } from 'ui' import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext' import { usePgSodiumKeysQuery } from 'data/pg-sodium-keys/pg-sodium-keys-query' interface EncryptionKeySelectorProps { id?: string nameId?: string label?: string labelOptional?: string selectedKeyId?: any error?: string onSelectKey: (keyId: string) => void onUpdateDescription?: (desc: string) => void } const EncryptionKeySelector = ({ id = 'keyId', nameId = 'keyName', label = 'Encryption key', labelOptional, selectedKeyId, error, onSelectKey = noop, onUpdateDescription = noop, }: EncryptionKeySelectorProps) => { const { project } = useProjectContext() const { data } = usePgSodiumKeysQuery({ projectRef: project?.ref, connectionString: project?.connectionString, }) const keys = data || [] return ( <> } > Create a new Encryption Key {keys.length > 0 && } {keys.map((key) => (

{key.name || 'No name provided'}

ID: {key.id}

))}
{selectedKeyId === 'create-new' && ( onUpdateDescription(event.target.value)} descriptionText="Provide a name for your key for easier identification" /> )} ) } export default EncryptionKeySelector