import { noop } from 'lodash' import { Plus } from 'lucide-react' import { Input, SelectContent_Shadcn_, SelectGroup_Shadcn_, SelectItem_Shadcn_, SelectTrigger_Shadcn_, Select_Shadcn_, } from 'ui' import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext' import { usePgSodiumKeysQuery } from 'data/pg-sodium-keys/pg-sodium-keys-query' interface EncryptionKeySelectorProps { nameId?: string label?: string labelOptional?: string selectedKeyId?: any error?: string onSelectKey: (keyId: string) => void onUpdateDescription?: (desc: string) => void } const EncryptionKeySelector = ({ 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 ( <>
{label && (
{labelOptional && ( {labelOptional} )}
)} {keys.find((key) => key.id === selectedKeyId)?.name || 'Select an encryption key'} 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