AnalyticsBucketFields() — supabase Function Reference
Architecture documentation for the AnalyticsBucketFields() function in DestinationPanelFields.tsx from the supabase codebase.
Entity Profile
Relationship Graph
Source Code
apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/DestinationPanelFields.tsx lines 105–481
export const AnalyticsBucketFields = ({
form,
setIsFormInteracting,
onSelectNewBucket,
}: {
form: UseFormReturn<DestinationPanelSchemaType>
setIsFormInteracting: (value: boolean) => void
onSelectNewBucket: () => void
}) => {
const { warehouseName, s3AccessKeyId, namespace } = form.watch()
const [showCatalogToken, setShowCatalogToken] = useState(false)
const [showSecretAccessKey, setShowSecretAccessKey] = useState(false)
const { ref: projectRef } = useParams()
const { can: canReadAPIKeys } = useAsyncCheckPermissions(PermissionAction.SECRETS_READ, '*')
const { data: apiKeys } = useAPIKeysQuery(
{ projectRef, reveal: true },
{ enabled: canReadAPIKeys }
)
const { serviceKey } = getKeys(apiKeys)
const serviceApiKey = serviceKey?.api_key ?? ''
const {
data: keysData,
isSuccess: isSuccessKeys,
isPending: isLoadingKeys,
isError: isErrorKeys,
} = useStorageCredentialsQuery({ projectRef })
const s3Keys = keysData?.data ?? []
const keyNoLongerExists =
(s3AccessKeyId ?? '').length > 0 &&
s3AccessKeyId !== CREATE_NEW_KEY &&
!s3Keys.find((k) => k.access_key === s3AccessKeyId)
const {
data: analyticsBuckets = [],
isPending: isLoadingBuckets,
isError: isErrorBuckets,
} = useAnalyticsBucketsQuery({ projectRef })
const canSelectNamespace = !!warehouseName && !!serviceApiKey
const {
data: namespaces = [],
isPending: isLoadingNamespaces,
isError: isErrorNamespaces,
} = useIcebergNamespacesQuery(
{ projectRef, warehouse: warehouseName },
{ enabled: !!serviceApiKey }
)
return (
<div className="flex flex-col gap-y-6 p-5">
<p className="text-sm font-medium text-foreground">Analytics Bucket settings</p>
<div className="flex flex-col gap-y-4">
<FormField_Shadcn_
control={form.control}
name="warehouseName"
render={({ field }) => (
<FormItemLayout
label="Bucket"
layout="horizontal"
description="The Analytics Bucket where data will be stored"
>
{isLoadingBuckets ? (
<Button
disabled
type="default"
className="w-full justify-between"
size="small"
iconRight={<Loader2 className="animate-spin" />}
>
Retrieving buckets
</Button>
) : isErrorBuckets ? (
<Button
disabled
type="default"
className="w-full justify-start"
size="small"
icon={<WarningIcon />}
>
Failed to retrieve buckets
</Button>
) : (
<FormControl_Shadcn_>
<Select_Shadcn_
value={field.value}
onValueChange={(value) => {
if (value === 'new-bucket') {
onSelectNewBucket()
} else {
setIsFormInteracting(true)
field.onChange(value)
// [Joshen] Ideally should select the first namespace of the selected bucket
form.setValue('namespace', '')
}
}}
>
<SelectTrigger_Shadcn_>
{field.value || 'Select a bucket'}
</SelectTrigger_Shadcn_>
<SelectContent_Shadcn_>
<SelectGroup_Shadcn_>
{analyticsBuckets.length === 0 ? (
<SelectItem_Shadcn_ value="__no_buckets__" disabled>
No buckets available
</SelectItem_Shadcn_>
) : (
analyticsBuckets.map((bucket) => (
<SelectItem_Shadcn_ key={bucket.name} value={bucket.name}>
{bucket.name}
</SelectItem_Shadcn_>
))
)}
<SelectSeparator_Shadcn_ />
<SelectItem_Shadcn_ value="new-bucket">
Create a new bucket
</SelectItem_Shadcn_>
</SelectGroup_Shadcn_>
</SelectContent_Shadcn_>
</Select_Shadcn_>
</FormControl_Shadcn_>
)}
</FormItemLayout>
)}
/>
<FormField_Shadcn_
control={form.control}
name="namespace"
render={({ field }) => (
<FormItemLayout
label="Namespace"
layout="horizontal"
description="The namespace within the bucket where tables will be organized"
>
{isLoadingNamespaces && canSelectNamespace ? (
<Button
disabled
type="default"
className="w-full justify-between"
size="small"
iconRight={<Loader2 className="animate-spin" />}
>
Retrieving namespaces
</Button>
) : isErrorNamespaces ? (
<Button
disabled
type="default"
className="w-full justify-start"
size="small"
icon={<WarningIcon />}
>
Failed to retrieve namespaces
</Button>
) : (
<FormControl_Shadcn_>
<Select_Shadcn_
value={field.value}
onValueChange={(value) => {
setIsFormInteracting(true)
field.onChange(value)
}}
disabled={!canSelectNamespace}
>
<SelectTrigger_Shadcn_>
{!canSelectNamespace
? 'Select a warehouse first'
: field.value === CREATE_NEW_NAMESPACE
? 'Create a new namespace'
: field.value || 'Select a namespace'}
</SelectTrigger_Shadcn_>
<SelectContent_Shadcn_>
<SelectGroup_Shadcn_>
{namespaces.length === 0 ? (
<SelectItem_Shadcn_ value="__no_namespaces__" disabled>
No namespaces available
</SelectItem_Shadcn_>
) : (
namespaces.map((namespace) => (
<SelectItem_Shadcn_ key={namespace} value={namespace}>
{namespace}
</SelectItem_Shadcn_>
))
)}
<SelectSeparator_Shadcn_ />
<SelectItem_Shadcn_ key={CREATE_NEW_NAMESPACE} value={CREATE_NEW_NAMESPACE}>
Create a new namespace
</SelectItem_Shadcn_>
</SelectGroup_Shadcn_>
</SelectContent_Shadcn_>
</Select_Shadcn_>
</FormControl_Shadcn_>
)}
</FormItemLayout>
)}
/>
{namespace === CREATE_NEW_NAMESPACE && (
<FormField_Shadcn_
control={form.control}
name="newNamespaceName"
render={({ field }) => (
<FormItemLayout
label="New Namespace Name"
layout="horizontal"
description="A unique name for the new namespace"
>
<FormControl_Shadcn_>
<Input_Shadcn_ {...field} placeholder="new_namespace" value={field.value || ''} />
</FormControl_Shadcn_>
</FormItemLayout>
)}
/>
)}
<FormField_Shadcn_
control={form.control}
name="catalogToken"
render={({ field }) => (
<FormItemLayout
layout="horizontal"
label="Catalog Token"
description={
<>
Automatically retrieved from your project's{' '}
<InlineLink href={`/project/${projectRef}/settings/api-keys`}>
service role key
</InlineLink>
</>
}
>
<Input
disabled
value={field.value}
type={showCatalogToken ? 'text' : 'password'}
placeholder="Auto-populated"
actions={
serviceApiKey ? (
<div className="flex items-center justify-center">
<Button
type="default"
className="w-7"
icon={showCatalogToken ? <Eye /> : <EyeOff />}
onClick={() => setShowCatalogToken(!showCatalogToken)}
/>
</div>
) : null
}
/>
</FormItemLayout>
)}
/>
<FormField_Shadcn_
control={form.control}
name="s3AccessKeyId"
render={({ field }) => (
<FormItemLayout
layout="horizontal"
label="S3 Access Key ID"
description={
<div className="flex flex-col gap-y-2">
<p>
Access keys are managed in your Storage{' '}
<InlineLink href={`/project/${projectRef}/storage/s3`}>S3 settings</InlineLink>
</p>
{isSuccessKeys && keyNoLongerExists && (
<Admonition type="warning" title="Unable to find access key ID in project">
<p className="!leading-normal">
Please select another key or create a new set, as this destination will not
work otherwise. S3 access keys can be managed in your{' '}
<InlineLink href={`/project/${projectRef}/storage/files/settings`}>
storage settings
</InlineLink>
</p>
</Admonition>
)}
{s3AccessKeyId === CREATE_NEW_KEY && (
<Admonition
type="default"
title="A new set of S3 access keys will be created"
/>
)}
</div>
}
>
{isLoadingKeys ? (
<Button
disabled
type="default"
className="w-full justify-between"
size="small"
iconRight={<Loader2 className="animate-spin" />}
>
Retrieving keys
</Button>
) : isErrorKeys ? (
<Button
disabled
type="default"
className="w-full justify-start"
size="small"
icon={<WarningIcon />}
>
Failed to retrieve keys
</Button>
) : (
<FormControl_Shadcn_>
<Select_Shadcn_ value={field.value} onValueChange={field.onChange}>
<SelectTrigger_Shadcn_>
{field.value === CREATE_NEW_KEY
? 'Create a new key'
: (field.value ?? '').length === 0
? 'Select an access key ID'
: field.value}
</SelectTrigger_Shadcn_>
<SelectContent_Shadcn_>
<SelectGroup_Shadcn_>
{s3Keys.map((key) => (
<SelectItem_Shadcn_ key={key.id} value={key.access_key}>
{key.access_key}
<p className="text-foreground-lighter">{key.description}</p>
</SelectItem_Shadcn_>
))}
<SelectSeparator_Shadcn_ />
<SelectItem_Shadcn_ key={CREATE_NEW_KEY} value={CREATE_NEW_KEY}>
Create a new key
</SelectItem_Shadcn_>
</SelectGroup_Shadcn_>
</SelectContent_Shadcn_>
</Select_Shadcn_>
</FormControl_Shadcn_>
)}
</FormItemLayout>
)}
/>
{s3AccessKeyId !== CREATE_NEW_KEY && (
<FormField_Shadcn_
control={form.control}
name="s3SecretAccessKey"
render={({ field }) => (
<FormItemLayout
layout="horizontal"
label="S3 Secret Access Key"
className="relative"
description="The secret key corresponding to your selected access key ID"
>
<FormControl_Shadcn_>
<Input_Shadcn_
{...field}
type={showSecretAccessKey ? 'text' : 'password'}
value={field.value ?? ''}
placeholder="Provide the secret access key"
/>
</FormControl_Shadcn_>
<Button
type="default"
icon={showSecretAccessKey ? <Eye /> : <EyeOff />}
className="w-7 absolute right-6 top-[4px]"
onClick={() => setShowSecretAccessKey(!showSecretAccessKey)}
/>
</FormItemLayout>
)}
/>
)}
</div>
</div>
)
}
Domain
Subdomains
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free