import { PermissionAction } from '@supabase/shared-types/out/constants' import { Search } from 'lucide-react' import { useState } from 'react' import { toast } from 'sonner' import { useParams } from 'common' import Table from 'components/to-be-cleaned/Table' import AlertError from 'components/ui/AlertError' import NoPermission from 'components/ui/NoPermission' import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader' import { useSecretsDeleteMutation } from 'data/secrets/secrets-delete-mutation' import { ProjectSecret, useSecretsQuery } from 'data/secrets/secrets-query' import { useCheckPermissions } from 'hooks/misc/useCheckPermissions' import { Badge, Separator } from 'ui' import { Input } from 'ui-patterns/DataInputs/Input' import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal' import AddNewSecretForm from './AddNewSecretForm' import EdgeFunctionSecret from './EdgeFunctionSecret' const EdgeFunctionSecrets = () => { const { ref: projectRef } = useParams() const [searchString, setSearchString] = useState('') const [selectedSecret, setSelectedSecret] = useState() const canReadSecrets = useCheckPermissions(PermissionAction.SECRETS_READ, '*') const canUpdateSecrets = useCheckPermissions(PermissionAction.SECRETS_WRITE, '*') const { data, error, isLoading, isSuccess, isError } = useSecretsQuery({ projectRef: projectRef, }) const { mutate: deleteSecret, isLoading: isDeleting } = useSecretsDeleteMutation({ onSuccess: () => { toast.success(`Successfully deleted ${selectedSecret?.name}`) setSelectedSecret(undefined) }, }) const secrets = searchString.length > 0 ? data?.filter((secret) => secret.name.toLowerCase().includes(searchString.toLowerCase())) ?? [] : data ?? [] return ( <> {isLoading && } {isError && } {isSuccess && ( <> {!canUpdateSecrets ? ( ) : (
)} {canUpdateSecrets && !canReadSecrets ? ( ) : canReadSecrets ? (
setSearchString(e.target.value)} icon={} />
Name, Digest{' '} SHA256 , Updated at, , ]} body={ secrets.length > 0 ? ( secrets.map((secret) => ( setSelectedSecret(secret)} /> )) ) : secrets.length === 0 && searchString.length > 0 ? (

No results found

Your search for "{searchString}" did not return any results

) : (

No secrets created

There are no secrets associated with your project yet

) } /> ) : null} )} setSelectedSecret(undefined)} onConfirm={() => { if (selectedSecret !== undefined) { deleteSecret({ projectRef, secrets: [selectedSecret.name] }) } }} >

Before removing this secret, ensure none of your Edge Functions are actively using it. This action cannot be undone.

) } export default EdgeFunctionSecrets