Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat(etl): Improve destination panel UI (#40001)

Riccardo Busetti3182df1c7602
diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/AdvancedSettings.tsx b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/AdvancedSettings.tsx
index 4f3b864f379..47ab32593b5 100644
--- a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/AdvancedSettings.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/AdvancedSettings.tsx
@@ -1,81 +1,98 @@
-import { UseFormReturn } from 'react-hook-form'
+import type { ChangeEvent } from 'react'
+import type { UseFormReturn } from 'react-hook-form'
import {
Accordion_Shadcn_,
AccordionContent_Shadcn_,
AccordionItem_Shadcn_,
AccordionTrigger_Shadcn_,
+ Badge,
FormControl_Shadcn_,
FormField_Shadcn_,
Input_Shadcn_,
} from 'ui'
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
-import { DestinationPanelSchemaType } from './DestinationPanel.schema'
+import type { DestinationPanelSchemaType } from './DestinationPanel.schema'
export const AdvancedSettings = ({ form }: { form: UseFormReturn<DestinationPanelSchemaType> }) => {
const { type } = form.watch()
+ const handleNumberChange =
+ (field: { onChange: (value?: number) => void }) => (e: ChangeEvent<HTMLInputElement>) => {
+ const val = e.target.value
+ field.onChange(val === '' ? undefined : Number(val))
+ }
+
return (
- <Accordion_Shadcn_ type="single" collapsible>
- <AccordionItem_Shadcn_ value="item-1" className="border-none">
- <AccordionTrigger_Shadcn_ className="font-normal gap-2 justify-between text-sm">
- Advanced Settings
- </AccordionTrigger_Shadcn_>
- <AccordionContent_Shadcn_ asChild className="!pb-0">
- <FormField_Shadcn_
- control={form.control}
- name="maxFillMs"
- render={({ field }) => (
- <FormItemLayout
- className="mb-4"
- label="Max fill milliseconds"
- layout="vertical"
- description="The maximum amount of time to fill the data in milliseconds. Leave empty to use default value."
- >
- <FormControl_Shadcn_>
- <Input_Shadcn_
- {...field}
- type="number"
- value={field.value ?? ''}
- onChange={(e) => {
- const val = e.target.value
- field.onChange(val === '' ? undefined : Number(val))
- }}
- placeholder="Leave empty for default"
- />
- </FormControl_Shadcn_>
- </FormItemLayout>
- )}
- />
- {type === 'BigQuery' && (
+ <div className="px-5">
+ <Accordion_Shadcn_ type="single" collapsible>
+ <AccordionItem_Shadcn_ value="item-1" className="border-none">
+ <AccordionTrigger_Shadcn_ className="font-normal gap-2 justify-between text-sm py-3 hover:no-underline">
+ <div className="flex flex-col items-start gap-0.5">
+ <span className="text-sm font-medium">Advanced settings</span>
+ <span className="text-sm text-foreground-lighter font-normal">
+ Optional performance tuning
+ </span>
+ </div>
+ </AccordionTrigger_Shadcn_>
+ <AccordionContent_Shadcn_ className="!pb-0 space-y-6 pt-3">
+ {/* Batch wait time - applies to all destinations */}
<FormField_Shadcn_
control={form.control}
- name="maxStalenessMins"
+ name="maxFillMs"
render={({ field }) => (
<FormItemLayout
- className="mb-4"
- label="Max staleness minutes"
+ label="Batch wait time (milliseconds)"
layout="vertical"
- description="Maximum staleness time allowed in minutes. Leave empty to use default value."
+ description="How long to wait for more changes before sending. Shorter times mean more real-time updates but higher overhead."
>
<FormControl_Shadcn_>
<Input_Shadcn_
{...field}
type="number"
value={field.value ?? ''}
- onChange={(e) => {
- const val = e.target.value
- field.onChange(val === '' ? undefined : Number(val))
- }}
- placeholder="Leave empty for default"
+ onChange={handleNumberChange(field)}
+ placeholder="e.g., 5000 (5 seconds)"
/>
</FormControl_Shadcn_>
</FormItemLayout>
)}
/>
- )}
- </AccordionContent_Shadcn_>
- </AccordionItem_Shadcn_>
- </Accordion_Shadcn_>
+
+ {/* BigQuery-specific: Max staleness */}
+ {type === 'BigQuery' && (
+ <div className="pt-2">
+ <FormField_Shadcn_
+ control={form.control}
+ name="maxStalenessMins"
+ render={({ field }) => (
+ <FormItemLayout
+ label={
+ <div className="flex items-center gap-2">
+ <span>Maximum staleness (minutes)</span>
+ <Badge>BigQuery only</Badge>
+ </div>
+ }
+ layout="vertical"
+ description="Maximum age of cached data before BigQuery reads from base tables at query time. Lower values ensure fresher results but may increase query costs."
+ >
+ <FormControl_Shadcn_>
+ <Input_Shadcn_
+ {...field}
+ type="number"
+ value={field.value ?? ''}
+ onChange={handleNumberChange(field)}
+ placeholder="e.g. 60 (1 hour)"
+ />
+ </FormControl_Shadcn_>
+ </FormItemLayout>
+ )}
+ />
+ </div>
+ )}
+ </AccordionContent_Shadcn_>
+ </AccordionItem_Shadcn_>
+ </Accordion_Shadcn_>
+ </div>
)
}
diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationNameInput.tsx b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationNameInput.tsx
new file mode 100644
index 00000000000..3e9208b371b
--- /dev/null
+++ b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationNameInput.tsx
@@ -0,0 +1,29 @@
+import type { UseFormReturn } from 'react-hook-form'
+
+import { FormControl_Shadcn_, FormField_Shadcn_, Input_Shadcn_ } from 'ui'
+import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
+import type { DestinationPanelSchemaType } from './DestinationPanel.schema'
+
+type DestinationNameInputProps = {
+ form: UseFormReturn<DestinationPanelSchemaType>
+}
+
+export const DestinationNameInput = ({ form }: DestinationNameInputProps) => {
+ return (
+ <FormField_Shadcn_
+ control={form.control}
+ name="name"
+ render={({ field }) => (
+ <FormItemLayout
+ label="Name"
+ layout="vertical"
+ description="A descriptive name to identify this destination"
+ >
+ <FormControl_Shadcn_>
+ <Input_Shadcn_ {...field} placeholder="My destination" />
+ </FormControl_Shadcn_>
+ </FormItemLayout>
+ )}
+ />
+ )
+}
diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationPanel.schema.ts b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationPanel.schema.ts
index 4eaa16f39c7..6050c7bc4c8 100644
--- a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationPanel.schema.ts
+++ b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationPanel.schema.ts
@@ -26,38 +26,44 @@ export const DestinationPanelFormSchema = z
s3SecretAccessKey: z.string().optional(),
s3Region: z.string().optional(),
})
- .refine(
- (data) => {
- if (data.type === 'BigQuery') {
- return (
- data.projectId &&
- data.projectId.length > 0 &&
- data.datasetId &&
- data.datasetId.length > 0 &&
- data.serviceAccountKey &&
- data.serviceAccountKey.length > 0
- )
- } else if (data.type === 'Analytics Bucket') {
- const hasValidNamespace =
- (data.namespace && data.namespace.length > 0) ||
- (data.namespace === 'create-new-namespace' &&
- data.newNamespaceName &&
- data.newNamespaceName.length > 0)
-
- return (
- data.warehouseName &&
- data.warehouseName.length > 0 &&
- hasValidNamespace &&
- data.s3Region &&
- data.s3Region.length > 0
+ .superRefine((data, ctx) => {
+ const addRequiredFieldError = (path: string, message: string) => {
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ message,
+ path: [path],
+ })
+ }
+
+ if (data.type === 'BigQuery') {
+ if (!data.projectId?.length) addRequiredFieldError('projectId', 'Project ID is required')
+ if (!data.datasetId?.length) addRequiredFieldError('datasetId', 'Dataset ID is required')
+ if (!data.serviceAccountKey?.length)
+ addRequiredFieldError('serviceAccountKey', 'Service Account Key is required')
+ } else if (data.type === 'Analytics Bucket') {
+ if (!data.warehouseName?.length) addRequiredFieldError('warehouseName', 'Bucket is required')
+
+ const hasValidNamespace =
+ (data.namespace?.length && data.namespace !== 'create-new-namespace') ||
+ (data.namespace === 'create-new-namespace' && data.newNamespaceName?.length)
+
+ if (!hasValidNamespace) {
+ const isCreatingNew = data.namespace === 'create-new-namespace'
+ addRequiredFieldError(
+ isCreatingNew ? 'newNamespaceName' : 'namespace',
+ isCreatingNew ? 'Namespace name is required' : 'Namespace is required'
)
}
- return true
- },
- {
- message: 'All fields are required for the selected destination type',
- path: ['projectId'],
+
+ if (!data.s3Region?.length) addRequiredFieldError('s3Region', 'S3 Region is required')
+
+ if (!data.s3AccessKeyId?.length)
+ addRequiredFieldError('s3AccessKeyId', 'S3 Access Key ID is required')
+
+ if (data.s3AccessKeyId !== 'create-new' && !data.s3SecretAccessKey?.length) {
+ addRequiredFieldError('s3SecretAccessKey', 'S3 Secret Access Key is required')
+ }
}
- )
+ })
export type DestinationPanelSchemaType = z.infer<typeof DestinationPanelFormSchema>
diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationPanel.tsx b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationPanel.tsx
index a4ef25e9f17..1699b811e59 100644
--- a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationPanel.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationPanel.tsx
@@ -5,9 +5,8 @@ import { useForm } from 'react-hook-form'
import { toast } from 'sonner'
import * as z from 'zod'
-import { useParams } from 'common'
+import { useFlag, useParams } from 'common'
import { getCatalogURI } from 'components/interfaces/Storage/StorageSettings/StorageSettings.utils'
-import { InlineLink } from 'components/ui/InlineLink'
import { getKeys, useAPIKeysQuery } from 'data/api-keys/api-keys-query'
import { useProjectSettingsV2Query } from 'data/config/project-settings-v2-query'
import { useCheckPrimaryKeysExists } from 'data/database/primary-keys-exists-query'
@@ -28,14 +27,6 @@ import {
Button,
DialogSectionSeparator,
Form_Shadcn_,
- FormControl_Shadcn_,
- FormField_Shadcn_,
- Input_Shadcn_,
- Select_Shadcn_,
- SelectContent_Shadcn_,
- SelectGroup_Shadcn_,
- SelectItem_Shadcn_,
- SelectTrigger_Shadcn_,
Sheet,
SheetContent,
SheetDescription,
@@ -44,15 +35,15 @@ import {
SheetSection,
SheetTitle,
} from 'ui'
-import { Admonition } from 'ui-patterns'
-import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
-import { NewPublicationPanel } from '../NewPublicationPanel'
-import { PublicationsComboBox } from '../PublicationsComboBox'
import { ReplicationDisclaimerDialog } from '../ReplicationDisclaimerDialog'
import { AdvancedSettings } from './AdvancedSettings'
+import { DestinationNameInput } from './DestinationNameInput'
import { CREATE_NEW_KEY, CREATE_NEW_NAMESPACE } from './DestinationPanel.constants'
import { DestinationPanelFormSchema as FormSchema, TypeEnum } from './DestinationPanel.schema'
import { AnalyticsBucketFields, BigQueryFields } from './DestinationPanelFields'
+import { DestinationTypeSelection } from './DestinationTypeSelection'
+import { NoDestinationsAvailable } from './NoDestinationsAvailable'
+import { PublicationSelection } from './PublicationSelection'
const formId = 'destination-editor'
@@ -79,8 +70,22 @@ export const DestinationPanel = ({
const { data: project } = useSelectedProjectQuery()
const { setRequestStatus } = usePipelineRequestStatus()
+ // Feature flags for ETL destinations
+ const etlEnableBigQuery = useFlag('etlEnableBigQuery')
+ const etlEnableIceberg = useFlag('etlEnableIceberg')
+
+ // Compute available destinations based on feature flags
+ const availableDestinations = useMemo(() => {
+ const destinations = []
+ if (etlEnableBigQuery) destinations.push({ value: 'BigQuery', label: 'BigQuery' })
+ if (etlEnableIceberg)
+ destinations.push({ value: 'Analytics Bucket', label: 'Analytics Bucket' })
+ return destinations
+ }, [etlEnableBigQuery, etlEnableIceberg])
+
+ const hasNoAvailableDestinations = availableDestinations.length === 0
+
const editMode = !!existingDestination
- const [publicationPanelVisible, setPublicationPanelVisible] = useState(false)
const [showDisclaimerDialog, setShowDisclaimerDialog] = useState(false)
const [pendingFormValues, setPendingFormValues] = useState<z.infer<typeof FormSchema> | null>(
null
@@ -107,7 +112,6 @@ export const DestinationPanel = ({
const {
data: publications = [],
- isLoading: isLoadingPublications,
isSuccess: isSuccessPublications,
refetch: refetchPublications,
} = useReplicationPublicationsQuery({ projectRef, sourceId })
@@ -129,18 +133,19 @@ export const DestinationPanel = ({
const { data: projectSettings } = useProjectSettingsV2Query({ projectRef })
const defaultValues = useMemo(() => {
- // Type guards to safely access union properties
const config = destinationData?.config
const isBigQueryConfig = config && 'big_query' in config
const isIcebergConfig = config && 'iceberg' in config
+ const defaultType = editMode
+ ? isBigQueryConfig
+ ? TypeEnum.enum.BigQuery
+ : TypeEnum.enum['Analytics Bucket']
+ : (availableDestinations[0]?.value as z.infer<typeof TypeEnum>) || TypeEnum.enum.BigQuery
+
return {
// Common fields
- type: (isBigQueryConfig
- ? TypeEnum.enum.BigQuery
- : isIcebergConfig
- ? TypeEnum.enum['Analytics Bucket']
- : TypeEnum.enum.BigQuery) as z.infer<typeof TypeEnum>,
+ type: defaultType,
name: destinationData?.name ?? '',
publicationName: pipelineData?.config.publication_name ?? '',
maxFillMs: pipelineData?.config?.batch?.max_fill_ms,
@@ -159,11 +164,18 @@ export const DestinationPanel = ({
s3Region:
projectSettings?.region ?? (isIcebergConfig ? config.iceberg.supabase.s3_region : ''),
}
- }, [destinationData, pipelineData, catalogToken, projectSettings])
+ }, [
+ destinationData,
+ pipelineData,
+ catalogToken,
+ projectSettings,
+ editMode,
+ availableDestinations,
+ ])
const form = useForm<z.infer<typeof FormSchema>>({
- mode: 'onBlur',
- reValidateMode: 'onBlur',
+ mode: 'onChange',
+ reValidateMode: 'onChange',
resolver: zodResolver(FormSchema),
defaultValues,
})
@@ -191,7 +203,11 @@ export const DestinationPanel = ({
const hasTablesWithNoPrimaryKeys = (checkPrimaryKeysExistsData?.offendingTables ?? []).length > 0
const isSubmitDisabled =
- isSaving || isSelectedPublicationMissing || isLoadingCheck || hasTablesWithNoPrimaryKeys
+ isSaving ||
+ isSelectedPublicationMissing ||
+ (!!selectedPublication && isLoadingCheck) ||
+ hasTablesWithNoPrimaryKeys ||
+ (!editMode && hasNoAvailableDestinations)
// Helper function to handle namespace creation if needed
const resolveNamespace = async (data: z.infer<typeof FormSchema>) => {
@@ -425,143 +441,52 @@ export const DestinationPanel = ({
<SheetHeader>
<SheetTitle>{editMode ? 'Edit destination' : 'Create a new destination'}</SheetTitle>
<SheetDescription>
- {editMode ? null : 'Send data to a new destination'}
+ {editMode
+ ? 'Update the configuration for this destination'
+ : 'A destination is an external platform that automatically receives your database changes in real time.'}
</SheetDescription>
</SheetHeader>
<SheetSection className="flex-grow overflow-auto px-0 py-0">
- <Form_Shadcn_ {...form}>
- <form id={formId} onSubmit={form.handleSubmit(onSubmit)}>
- <FormField_Shadcn_
- control={form.control}
- name="name"
- render={({ field }) => (
- <FormItemLayout
- className="p-5"
- label="Name"
- layout="vertical"
- description="A name you will use to identify this destination"
- >
- <FormControl_Shadcn_>
- <Input_Shadcn_ {...field} placeholder="Name" />
- </FormControl_Shadcn_>
- </FormItemLayout>
- )}
- />
-
- <DialogSectionSeparator />
-
- <div className="p-5">
- <p className="text-sm text-foreground-light mb-4">What data to send</p>
- <FormField_Shadcn_
- control={form.control}
- name="publicationName"
- render={({ field }) => (
- <FormItemLayout
- label="Publication"
- layout="vertical"
- description="A publication is a collection of tables that you want to replicate "
- >
- <FormControl_Shadcn_>
- <PublicationsComboBox
- publications={publicationNames}
- isLoadingPublications={isLoadingPublications}
- isLoadingCheck={!!selectedPublication && isLoadingCheck}
- field={field}
- onNewPublicationClick={() => setPublicationPanelVisible(true)}
- />
- </FormControl_Shadcn_>
- {isSelectedPublicationMissing ? (
- <Admonition type="warning" className="mt-2 mb-0">
- <p className="!leading-normal">
- The publication{' '}
- <strong className="text-foreground">{publicationName}</strong> was
- not found, it may have been renamed or deleted, please select
- another one.
- </p>
- </Admonition>
- ) : hasTablesWithNoPrimaryKeys ? (
- <Admonition type="warning" className="mt-2 mb-0">
- <p className="!leading-normal">
- Replication requires every table in the publication to have a
- primary key to work, which these tables are missing:
- </p>
- <ul className="list-disc pl-6 mb-2">
- {(checkPrimaryKeysExistsData?.offendingTables ?? []).map((x) => {
- const value = `${x.schema}.${x.name}`
- return (
- <li key={value} className="!leading-normal">
- <InlineLink href={`/project/${projectRef}/editor/${x.id}`}>
- {value}
- </InlineLink>
- </li>
- )
- })}
- </ul>
- <p className="!leading-normal">
- Ensure that these tables have primary keys first.
- </p>
- </Admonition>
- ) : null}
- </FormItemLayout>
- )}
- />
- </div>
-
- <DialogSectionSeparator />
-
- <div className="py-5 flex flex-col gap-y-4">
- <p className="px-5 text-sm text-foreground-light">Where to send that data</p>
- <FormField_Shadcn_
- name="type"
- control={form.control}
- render={({ field }) => (
- <FormItemLayout
- label="Type"
- layout="vertical"
- className="px-5"
- description="The type of destination to send the data to"
- >
- <FormControl_Shadcn_>
- <Select_Shadcn_
- value={field.value}
- onValueChange={(value) => {
- setIsFormInteracting(true)
- field.onChange(value)
- }}
- >
- <SelectTrigger_Shadcn_>{field.value}</SelectTrigger_Shadcn_>
- <SelectContent_Shadcn_>
- <SelectGroup_Shadcn_>
- <SelectItem_Shadcn_ value="BigQuery">BigQuery</SelectItem_Shadcn_>
- <SelectItem_Shadcn_ value="Analytics Bucket">
- Analytics Bucket
- </SelectItem_Shadcn_>
- </SelectGroup_Shadcn_>
- </SelectContent_Shadcn_>
- </Select_Shadcn_>
- </FormControl_Shadcn_>
- </FormItemLayout>
- )}
- />
-
- {selectedType === 'BigQuery' ? (
- <BigQueryFields form={form} />
- ) : selectedType === 'Analytics Bucket' ? (
- <AnalyticsBucketFields
- form={form}
- setIsFormInteracting={setIsFormInteracting}
- />
+ {hasNoAvailableDestinations && !editMode ? (
+ <NoDestinationsAvailable />
+ ) : (
+ <Form_Shadcn_ {...form}>
+ <form id={formId} onSubmit={form.handleSubmit(onSubmit)}>
+ <div className="p-5">
+ <p className="text-sm font-medium text-foreground mb-1">
+ Destination details
+ </p>
+ <p className="text-sm text-foreground-light mb-4">
+ Name your destination and choose which data to replicate
+ </p>
+
+ <div className="space-y-4">
+ <DestinationNameInput form={form} />
+ <PublicationSelection form={form} sourceId={sourceId} visible={visible} />
+ </div>
+ </div>
+ <DialogSectionSeparator />
+ <DestinationTypeSelection form={form} editMode={editMode} />
+ {selectedType === 'BigQuery' && etlEnableBigQuery ? (
+ <>
+ <DialogSectionSeparator />
+ <BigQueryFields form={form} />
+ </>
+ ) : selectedType === 'Analytics Bucket' && etlEnableIceberg ? (
+ <>
+ <DialogSectionSeparator />
+ <AnalyticsBucketFields
+ form={form}
+ setIsFormInteracting={setIsFormInteracting}
+ />
+ </>
) : null}
- </div>
-
- <DialogSectionSeparator />
-
- <div className="px-5">
+ <DialogSectionSeparator />
<AdvancedSettings form={form} />
- </div>
- </form>
- </Form_Shadcn_>
+ </form>
+ </Form_Shadcn_>
+ )}
</SheetSection>
<SheetFooter>
@@ -591,12 +516,6 @@ export const DestinationPanel = ({
isLoading={isSaving}
onConfirm={handleDisclaimerConfirm}
/>
-
- <NewPublicationPanel
- visible={publicationPanelVisible}
- sourceId={sourceId}
- onClose={() => setPublicationPanelVisible(false)}
- />
</>
)
}
diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationPanelFields.tsx b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationPanelFields.tsx
index c5c855e8707..283c180190b 100644
--- a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationPanelFields.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationPanelFields.tsx
@@ -1,6 +1,6 @@
import { Eye, EyeOff, Loader2 } from 'lucide-react'
import { useMemo, useState } from 'react'
-import { UseFormReturn } from 'react-hook-form'
+import type { UseFormReturn } from 'react-hook-form'
import { useParams } from 'common'
import { useIsNewStorageUIEnabled } from 'components/interfaces/App/FeaturePreview/FeaturePreviewContext'
@@ -14,7 +14,6 @@ import { useStorageCredentialsQuery } from 'data/storage/s3-access-key-query'
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
import {
Button,
- DialogSectionSeparator,
FormControl_Shadcn_,
FormField_Shadcn_,
Input_Shadcn_,
@@ -31,61 +30,75 @@ import { Admonition } from 'ui-patterns'
import { Input } from 'ui-patterns/DataInputs/Input'
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
import { CREATE_NEW_KEY, CREATE_NEW_NAMESPACE } from './DestinationPanel.constants'
-import { DestinationPanelSchemaType } from './DestinationPanel.schema'
+import type { DestinationPanelSchemaType } from './DestinationPanel.schema'
export const BigQueryFields = ({ form }: { form: UseFormReturn<DestinationPanelSchemaType> }) => {
return (
<>
- <FormField_Shadcn_
- control={form.control}
- name="projectId"
- render={({ field }) => (
- <FormItemLayout
- layout="vertical"
- className="px-5"
- label="Project ID"
- description="Which BigQuery project to send data to"
- >
- <FormControl_Shadcn_>
- <Input_Shadcn_ {...field} placeholder="Project ID" />
- </FormControl_Shadcn_>
- </FormItemLayout>
- )}
- />
+ <div className="px-5 pt-5">
+ <p className="text-sm font-medium text-foreground mb-1">BigQuery settings</p>
+ <p className="text-sm text-foreground-light mb-4">
+ Configure how data is sent to your BigQuery destination
+ </p>
+ </div>
+ <div className="space-y-4 pb-5">
+ <FormField_Shadcn_
+ control={form.control}
+ name="projectId"
+ render={({ field }) => (
+ <FormItemLayout
+ layout="vertical"
+ className="px-5"
+ label="Project ID"
+ description="The Google Cloud project ID where data will be sent"
+ >
+ <FormControl_Shadcn_>
+ <Input_Shadcn_ {...field} placeholder="my-gcp-project" />
+ </FormControl_Shadcn_>
+ </FormItemLayout>
+ )}
+ />
- <FormField_Shadcn_
- control={form.control}
- name="datasetId"
- render={({ field }) => (
- <FormItemLayout label="Project's Dataset ID" layout="vertical" className="px-5">
- <FormControl_Shadcn_>
- <Input_Shadcn_ {...field} placeholder="Dataset ID" />
- </FormControl_Shadcn_>
- </FormItemLayout>
- )}
- />
+ <FormField_Shadcn_
+ control={form.control}
+ name="datasetId"
+ render={({ field }) => (
+ <FormItemLayout
+ label="Dataset ID"
+ layout="vertical"
+ className="px-5"
+ description="The BigQuery dataset where replicated tables will be created"
+ >
+ <FormControl_Shadcn_>
+ <Input_Shadcn_ {...field} placeholder="my_dataset" />
+ </FormControl_Shadcn_>
+ </FormItemLayout>
+ )}
+ />
- <FormField_Shadcn_
- control={form.control}
- name="serviceAccountKey"
- render={({ field }) => (
- <FormItemLayout
- layout="vertical"
- className="px-5"
- label="Service Account Key"
- description="The service account key for BigQuery"
- >
- <FormControl_Shadcn_>
- <TextArea_Shadcn_
- {...field}
- rows={4}
- maxLength={5000}
- placeholder="Service account key"
- />
- </FormControl_Shadcn_>
- </FormItemLayout>
- )}
- />
+ <FormField_Shadcn_
+ control={form.control}
+ name="serviceAccountKey"
+ render={({ field }) => (
+ <FormItemLayout
+ layout="vertical"
+ className="px-5"
+ label="Service Account Key"
+ description="Service account credentials JSON for authenticating with BigQuery"
+ >
+ <FormControl_Shadcn_>
+ <TextArea_Shadcn_
+ {...field}
+ rows={5}
+ maxLength={5000}
+ placeholder='{"type": "service_account", "project_id": "...", ...}'
+ className="font-mono text-xs"
+ />
+ </FormControl_Shadcn_>
+ </FormItemLayout>
+ )}
+ />
+ </div>
</>
)
}
@@ -168,327 +181,333 @@ export const AnalyticsBucketFields = ({
return (
<>
- <FormField_Shadcn_
- control={form.control}
- name="warehouseName"
- render={({ field }) => (
- <FormItemLayout
- label="Bucket"
- layout="vertical"
- className="px-5"
- description="Select a storage Analytics Bucket to use as your warehouse"
- >
- {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) => {
- setIsFormInteracting(true)
- field.onChange(value)
- // [Joshen] Ideally should select the first namespace of the selected bucket
- form.setValue('namespace', '')
- }}
+ <div className="px-5 pt-5">
+ <p className="text-sm font-medium text-foreground mb-1">Analytics Bucket settings</p>
+ <p className="text-sm text-foreground-light mb-4">
+ Configure how data is sent to your Analytics Bucket destination
+ </p>
+ </div>
+ <div className="space-y-4 pb-5">
+ <FormField_Shadcn_
+ control={form.control}
+ name="warehouseName"
+ render={({ field }) => (
+ <FormItemLayout
+ label="Bucket"
+ layout="vertical"
+ className="px-5"
+ 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" />}
>
- <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.id} value={bucket.name}>
- {bucket.name}
- </SelectItem_Shadcn_>
- ))
- )}
- </SelectGroup_Shadcn_>
- </SelectContent_Shadcn_>
- </Select_Shadcn_>
- </FormControl_Shadcn_>
- )}
- </FormItemLayout>
- )}
- />
-
- <FormField_Shadcn_
- control={form.control}
- name="namespace"
- render={({ field }) => (
- <FormItemLayout
- label="Namespace"
- layout="vertical"
- className="px-5"
- description="Select a namespace from your Analytics Bucket"
- >
- {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}
+ Retrieving buckets
+ </Button>
+ ) : isErrorBuckets ? (
+ <Button
+ disabled
+ type="default"
+ className="w-full justify-start"
+ size="small"
+ icon={<WarningIcon />}
>
- <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}
+ Failed to retrieve buckets
+ </Button>
+ ) : (
+ <FormControl_Shadcn_>
+ <Select_Shadcn_
+ value={field.value}
+ onValueChange={(value) => {
+ 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_>
- ))
- )}
- {namespaces.length > 0 && <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>
- )}
- />
+ ) : (
+ analyticsBuckets.map((bucket) => (
+ <SelectItem_Shadcn_ key={bucket.id} value={bucket.name}>
+ {bucket.name}
+ </SelectItem_Shadcn_>
+ ))
+ )}
+ </SelectGroup_Shadcn_>
+ </SelectContent_Shadcn_>
+ </Select_Shadcn_>
+ </FormControl_Shadcn_>
+ )}
+ </FormItemLayout>
+ )}
+ />
- {namespace === CREATE_NEW_NAMESPACE && (
<FormField_Shadcn_
control={form.control}
- name="newNamespaceName"
+ name="namespace"
render={({ field }) => (
<FormItemLayout
- label="New Namespace Name"
+ label="Namespace"
layout="vertical"
className="px-5"
- description="Enter a name for the new namespace"
+ description="The namespace within the bucket where tables will be organized"
>
- <FormControl_Shadcn_>
- <Input_Shadcn_ {...field} placeholder="new_namespace" value={field.value || ''} />
- </FormControl_Shadcn_>
+ {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_>
+ ))
+ )}
+ {namespaces.length > 0 && <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>
)}
/>
- )}
-
- <DialogSectionSeparator />
- <p className="px-5 text-sm text-foreground-light">Credentials</p>
-
- <FormField_Shadcn_
- control={form.control}
- name="catalogToken"
- render={({ field }) => (
- <FormItemLayout
- layout="vertical"
- label="Catalog Token"
- className="px-5"
- 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="vertical" label="S3 Access Key ID" className="px-5">
- {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 />}
+ {namespace === CREATE_NEW_NAMESPACE && (
+ <FormField_Shadcn_
+ control={form.control}
+ name="newNamespaceName"
+ render={({ field }) => (
+ <FormItemLayout
+ label="New Namespace Name"
+ layout="vertical"
+ className="px-5"
+ description="A unique name for the new namespace"
>
- 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_>
+ <FormControl_Shadcn_>
+ <Input_Shadcn_ {...field} placeholder="new_namespace" value={field.value || ''} />
+ </FormControl_Shadcn_>
+ </FormItemLayout>
)}
- </FormItemLayout>
+ />
)}
- />
- {isSuccessKeys && keyNoLongerExists && (
- <div className="px-5">
- <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={
- isStorageV2
- ? `/project/${projectRef}/storage/files/settings`
- : `/project/${projectRef}/storage/settings`
- }
- >
- storage settings
- </InlineLink>
- </p>
- </Admonition>
- </div>
- )}
-
- {s3AccessKeyId === CREATE_NEW_KEY ? (
- <div className="px-5">
- <Admonition type="default" title="A new set of S3 access keys will be created">
- <p className="!leading-normal">
- S3 access keys can be managed in your{' '}
- <InlineLink
- href={
- isStorageV2
- ? `/project/${projectRef}/storage/files/settings`
- : `/project/${projectRef}/storage/settings`
- }
- >
- storage settings
- </InlineLink>
- .
- </p>
- </Admonition>
- </div>
- ) : (
<FormField_Shadcn_
control={form.control}
- name="s3SecretAccessKey"
+ name="catalogToken"
render={({ field }) => (
<FormItemLayout
layout="vertical"
- label="S3 Secret Access Key"
- className="relative px-5"
- description="The corresponding secret access key for the selected key ID"
+ label="Catalog Token"
+ className="px-5"
+ description={
+ <>
+ Automatically retrieved from your project's{' '}
+ <InlineLink href={`/project/${projectRef}/settings/api-keys`}>
+ service role key
+ </InlineLink>
+ </>
+ }
>
- <FormControl_Shadcn_>
- <Input_Shadcn_
- {...field}
- type={showSecretAccessKey ? 'text' : 'password'}
- value={field.value ?? ''}
- />
- </FormControl_Shadcn_>
- <Button
- type="default"
- icon={showSecretAccessKey ? <Eye /> : <EyeOff />}
- className="w-7 absolute right-6 top-[33px]"
- onClick={() => setShowSecretAccessKey(!showSecretAccessKey)}
+ <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="vertical" label="S3 Access Key ID" className="px-5">
+ {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>
+ )}
+ />
+
+ {isSuccessKeys && keyNoLongerExists && (
+ <div className="px-5">
+ <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={
+ isStorageV2
+ ? `/project/${projectRef}/storage/files/settings`
+ : `/project/${projectRef}/storage/settings`
+ }
+ >
+ storage settings
+ </InlineLink>
+ </p>
+ </Admonition>
+ </div>
+ )}
+
+ {s3AccessKeyId === CREATE_NEW_KEY ? (
+ <div className="px-5">
+ <Admonition type="default" title="A new set of S3 access keys will be created">
+ <p className="!leading-normal">
+ S3 access keys can be managed in your{' '}
+ <InlineLink
+ href={
+ isStorageV2
+ ? `/project/${projectRef}/storage/files/settings`
+ : `/project/${projectRef}/storage/settings`
+ }
+ >
+ storage settings
+ </InlineLink>
+ .
+ </p>
+ </Admonition>
+ </div>
+ ) : (
+ <FormField_Shadcn_
+ control={form.control}
+ name="s3SecretAccessKey"
+ render={({ field }) => (
+ <FormItemLayout
+ layout="vertical"
+ label="S3 Secret Access Key"
+ className="relative px-5"
+ description="The secret key corresponding to your selected access key ID"
+ >
+ <FormControl_Shadcn_>
+ <Input_Shadcn_
+ {...field}
+ type={showSecretAccessKey ? 'text' : 'password'}
+ value={field.value ?? ''}
+ />
+ </FormControl_Shadcn_>
+ <Button
+ type="default"
+ icon={showSecretAccessKey ? <Eye /> : <EyeOff />}
+ className="w-7 absolute right-6 top-[33px]"
+ onClick={() => setShowSecretAccessKey(!showSecretAccessKey)}
+ />
+ </FormItemLayout>
+ )}
+ />
+ )}
+ </div>
</>
)
}
diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationTypeSelection.tsx b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationTypeSelection.tsx
new file mode 100644
index 00000000000..d99fb5fc99d
--- /dev/null
+++ b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationTypeSelection.tsx
@@ -0,0 +1,68 @@
+import type { UseFormReturn } from 'react-hook-form'
+
+import { useFlag } from 'common'
+import {
+ FormControl_Shadcn_,
+ FormField_Shadcn_,
+ RadioGroupStacked,
+ RadioGroupStackedItem,
+} from 'ui'
+import type { DestinationPanelSchemaType } from './DestinationPanel.schema'
+
+type DestinationTypeSelectionProps = {
+ form: UseFormReturn<DestinationPanelSchemaType>
+ editMode: boolean
+}
+
+export const DestinationTypeSelection = ({ form, editMode }: DestinationTypeSelectionProps) => {
+ const etlEnableBigQuery = useFlag('etlEnableBigQuery')
+ const etlEnableIceberg = useFlag('etlEnableIceberg')
+
+ return (
+ <div className="px-5 py-5">
+ <p className="text-sm font-medium text-foreground mb-1">Destination type</p>
+ {editMode ? (
+ <p className="text-sm text-foreground-light mb-4">
+ The destination type cannot be changed after creation
+ </p>
+ ) : (
+ <p className="text-sm text-foreground-light mb-4">
+ Choose which platform to send your database changes to
+ </p>
+ )}
+ <FormField_Shadcn_
+ name="type"
+ control={form.control}
+ render={({ field }) => (
+ <FormControl_Shadcn_>
+ <RadioGroupStacked
+ disabled={editMode}
+ value={field.value}
+ onValueChange={(value) => field.onChange(value)}
+ >
+ {((!editMode && etlEnableBigQuery) || (editMode && field.value === 'BigQuery')) && (
+ <RadioGroupStackedItem
+ id="BigQuery"
+ value="BigQuery"
+ label="BigQuery"
+ className="[&>div>div>p]:text-left"
+ description="Send data to Google Cloud's data warehouse for analytics and business intelligence"
+ />
+ )}
+ {((!editMode && etlEnableIceberg) ||
+ (editMode && field.value === 'Analytics Bucket')) && (
+ <RadioGroupStackedItem
+ value="Analytics Bucket"
+ id="Analytics Bucket"
+ label="Analytics Bucket"
+ className="[&>div>div>p]:text-left"
+ description="Send data to Apache Iceberg tables in your Supabase Storage for flexible analytics workflows"
+ />
+ )}
+ </RadioGroupStacked>
+ </FormControl_Shadcn_>
+ )}
+ />
+ </div>
+ )
+}
diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/NoDestinationsAvailable.tsx b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/NoDestinationsAvailable.tsx
new file mode 100644
index 00000000000..a99fa42a52d
--- /dev/null
+++ b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/NoDestinationsAvailable.tsx
@@ -0,0 +1,16 @@
+import { DatabaseZap } from 'lucide-react'
+
+export const NoDestinationsAvailable = () => {
+ return (
+ <div className="flex flex-col items-center justify-center h-full px-8 py-16 text-center">
+ <div className="flex items-center justify-center w-14 h-14 rounded-full bg-surface-300 mb-5">
+ <DatabaseZap size={26} className="text-foreground-light" strokeWidth={1.5} />
+ </div>
+ <h3 className="text-lg font-medium text-foreground mb-2">No destinations available</h3>
+ <p className="text-sm text-foreground-light max-w-lg">
+ Replication destinations are not currently enabled for this project. Contact support to
+ enable real-time data replication to external platforms.
+ </p>
+ </div>
+ )
+}
diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/PublicationSelection.tsx b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/PublicationSelection.tsx
new file mode 100644
index 00000000000..ad2a00a53b1
--- /dev/null
+++ b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/PublicationSelection.tsx
@@ -0,0 +1,109 @@
+import { useMemo, useState } from 'react'
+import type { UseFormReturn } from 'react-hook-form'
+
+import { useParams } from 'common'
+import { InlineLink } from 'components/ui/InlineLink'
+import { useCheckPrimaryKeysExists } from 'data/database/primary-keys-exists-query'
+import { useReplicationPublicationsQuery } from 'data/replication/publications-query'
+import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
+import { FormControl_Shadcn_, FormField_Shadcn_ } from 'ui'
+import { Admonition } from 'ui-patterns'
+import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
+import { NewPublicationPanel } from '../NewPublicationPanel'
+import { PublicationsComboBox } from '../PublicationsComboBox'
+import type { DestinationPanelSchemaType } from './DestinationPanel.schema'
+
+type PublicationSelectionProps = {
+ form: UseFormReturn<DestinationPanelSchemaType>
+ sourceId?: number
+ visible: boolean
+}
+
+export const PublicationSelection = ({ form, sourceId, visible }: PublicationSelectionProps) => {
+ const { ref: projectRef } = useParams()
+ const { data: project } = useSelectedProjectQuery()
+ const { publicationName } = form.watch()
+
+ const [publicationPanelVisible, setPublicationPanelVisible] = useState(false)
+
+ const {
+ data: publications = [],
+ isLoading: isLoadingPublications,
+ isSuccess: isSuccessPublications,
+ } = useReplicationPublicationsQuery({ projectRef, sourceId })
+
+ const publicationNames = useMemo(() => publications?.map((pub) => pub.name) ?? [], [publications])
+ const selectedPublication = publications.find((pub) => pub.name === publicationName)
+ const isSelectedPublicationMissing =
+ isSuccessPublications && !!publicationName && !publicationNames.includes(publicationName)
+
+ const { data: checkPrimaryKeysExistsData, isLoading: isLoadingCheck } = useCheckPrimaryKeysExists(
+ {
+ projectRef: project?.ref,
+ connectionString: project?.connectionString,
+ tables: selectedPublication?.tables ?? [],
+ },
+ { enabled: visible && !!selectedPublication }
+ )
+ const hasTablesWithNoPrimaryKeys = (checkPrimaryKeysExistsData?.offendingTables ?? []).length > 0
+
+ return (
+ <>
+ <FormField_Shadcn_
+ control={form.control}
+ name="publicationName"
+ render={({ field }) => (
+ <FormItemLayout
+ label="Publication"
+ layout="vertical"
+ description="Choose which tables to replicate to this destination"
+ >
+ <FormControl_Shadcn_>
+ <PublicationsComboBox
+ publications={publicationNames}
+ isLoadingPublications={isLoadingPublications}
+ isLoadingCheck={!!selectedPublication && isLoadingCheck}
+ field={field}
+ onNewPublicationClick={() => setPublicationPanelVisible(true)}
+ />
+ </FormControl_Shadcn_>
+ {isSelectedPublicationMissing ? (
+ <Admonition type="warning" className="mt-2 mb-0">
+ <p className="!leading-normal">
+ The publication <strong className="text-foreground">{publicationName}</strong> was
+ not found, it may have been renamed or deleted, please select another one.
+ </p>
+ </Admonition>
+ ) : hasTablesWithNoPrimaryKeys ? (
+ <Admonition type="warning" className="mt-2 mb-0">
+ <p className="!leading-normal">
+ Replication requires every table in the publication to have a primary key to work,
+ which these tables are missing:
+ </p>
+ <ul className="list-disc pl-6 mb-2">
+ {(checkPrimaryKeysExistsData?.offendingTables ?? []).map((x) => {
+ const value = `${x.schema}.${x.name}`
+ return (
+ <li key={value} className="!leading-normal">
+ <InlineLink href={`/project/${projectRef}/editor/${x.id}`}>
+ {value}
+ </InlineLink>
+ </li>
+ )
+ })}
+ </ul>
+ <p className="!leading-normal">Ensure that these tables have primary keys first.</p>
+ </Admonition>
+ ) : null}
+ </FormItemLayout>
+ )}
+ />
+
+ <NewPublicationPanel
+ sourceId={sourceId}
+ visible={publicationPanelVisible}
+ onClose={() => setPublicationPanelVisible(false)}
+ />
+ </>
+ )
+}
diff --git a/apps/studio/components/interfaces/Database/Replication/Destinations.tsx b/apps/studio/components/interfaces/Database/Replication/Destinations.tsx
index fe695472be3..5cf36ba1430 100644
--- a/apps/studio/components/interfaces/Database/Replication/Destinations.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/Destinations.tsx
@@ -129,9 +129,10 @@ export const Destinations = () => {
{replicationNotEnabled ? (
<div className="border rounded-md p-4 md:p-12 flex flex-col gap-y-4">
<div className="flex flex-col gap-y-1">
- <h3>Run analysis on your data via integrations with Replication</h3>
+ <h3>Stream data to external destinations in real-time</h3>
<p className="text-sm text-foreground-light">
- Enable replication on your project to send data to your first destination
+ Enable replication to start sending your database changes to data warehouses and
+ analytics platforms
</p>
</div>
<div className="flex gap-x-2">
@@ -189,10 +190,11 @@ export const Destinations = () => {
'flex flex-col px-10 rounded-lg justify-center items-center py-8 mt-4'
)}
>
- <h4>Send data to your first destination</h4>
+ <h4>Create your first destination</h4>
<p className="prose text-sm text-center mt-1 max-w-full">
- Use destinations to improve performance or run analysis on your data via
- integrations like BigQuery
+ Destinations are external platforms where your database changes are automatically
+ sent. Connect to data warehouses like BigQuery or analytics buckets to enable
+ real-time data pipelines.
</p>
<Button
icon={<Plus />}
diff --git a/apps/studio/components/interfaces/Database/Replication/NewPublicationPanel.tsx b/apps/studio/components/interfaces/Database/Replication/NewPublicationPanel.tsx
index e062afeb6b8..c8347316355 100644
--- a/apps/studio/components/interfaces/Database/Replication/NewPublicationPanel.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/NewPublicationPanel.tsx
@@ -1,10 +1,12 @@
import { zodResolver } from '@hookform/resolvers/zod'
-import { useParams } from 'common'
-import { useCreatePublicationMutation } from 'data/replication/create-publication-mutation'
-import { useReplicationTablesQuery } from 'data/replication/tables-query'
import { X } from 'lucide-react'
import { useForm } from 'react-hook-form'
import { toast } from 'sonner'
+import { z } from 'zod'
+
+import { useParams } from 'common'
+import { useCreatePublicationMutation } from 'data/replication/create-publication-mutation'
+import { useReplicationTablesQuery } from 'data/replication/tables-query'
import {
Button,
cn,
@@ -23,7 +25,6 @@ import {
} from 'ui'
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
import { MultiSelector } from 'ui-patterns/multi-select'
-import { z } from 'zod'
interface NewPublicationPanelProps {
visible: boolean
diff --git a/apps/studio/components/interfaces/Database/Replication/PublicationsComboBox.tsx b/apps/studio/components/interfaces/Database/Replication/PublicationsComboBox.tsx
index c0927679aa6..f577f937723 100644
--- a/apps/studio/components/interfaces/Database/Replication/PublicationsComboBox.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/PublicationsComboBox.tsx
@@ -36,20 +36,16 @@ export const PublicationsComboBox = ({
const [selectedPublication, setSelectedPublication] = useState<string>(field?.value || '')
const [searchTerm, setSearchTerm] = useState('')
- useEffect(() => {
- setSelectedPublication(field?.value || '')
- }, [field?.value])
-
- function handleSearchChange(value: string) {
- setSearchTerm(value)
- }
-
function handlePublicationSelect(pub: string) {
setSelectedPublication(pub)
setDropdownOpen(false)
field.onChange(pub)
}
+ useEffect(() => {
+ setSelectedPublication(field?.value || '')
+ }, [field?.value])
+
return (
<Popover_Shadcn_
modal={false}
@@ -87,7 +83,7 @@ export const PublicationsComboBox = ({
<CommandInput_Shadcn_
placeholder="Find publication..."
value={searchTerm}
- onValueChange={handleSearchChange}
+ onValueChange={setSearchTerm}
/>
<CommandList_Shadcn_>
<CommandEmpty_Shadcn_>
@@ -100,7 +96,13 @@ export const PublicationsComboBox = ({
'No publications found'
)}
</CommandEmpty_Shadcn_>
+
<CommandGroup_Shadcn_>
+ {publications.length === 0 && (
+ <p className="text-foreground-lighter text-xs py-3 px-2">
+ No publications available
+ </p>
+ )}
<ScrollArea className={publications.length > 7 ? 'h-[210px]' : ''}>
{publications.map((pub) => (
<CommandItem_Shadcn_
@@ -121,7 +123,9 @@ export const PublicationsComboBox = ({
))}
</ScrollArea>
</CommandGroup_Shadcn_>
+
<CommandSeparator_Shadcn_ />
+
<CommandGroup_Shadcn_>
<CommandItem_Shadcn_
className="cursor-pointer w-full"
diff --git a/apps/studio/components/interfaces/Database/Replication/RowMenu.tsx b/apps/studio/components/interfaces/Database/Replication/RowMenu.tsx
index fa1cfd82834..d20934b379a 100644
--- a/apps/studio/components/interfaces/Database/Replication/RowMenu.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/RowMenu.tsx
@@ -63,29 +63,21 @@ export const RowMenu = ({
? getRequestStatus(pipeline.id)
: PipelineStatusRequestStatus.None
- const hasPipelineAction =
+ // Show actions when not in a transitional state
+ const canPerformActions =
requestStatus === PipelineStatusRequestStatus.None &&
+ statusName !== PipelineStatusName.STARTING &&
[PipelineStatusName.STOPPED, PipelineStatusName.STARTED, PipelineStatusName.FAILED].includes(
statusName as PipelineStatusName
)
- const pipelineActionIcon =
- statusName === PipelineStatusName.STOPPED ? (
- <Play size={14} />
- ) : statusName === PipelineStatusName.STARTED ? (
- <Pause size={14} />
- ) : statusName === PipelineStatusName.FAILED ? (
- <RotateCcw size={14} />
- ) : null
-
- const pipelineActionLabel =
- statusName === PipelineStatusName.STOPPED
- ? 'Start pipeline'
- : statusName === PipelineStatusName.STARTED
- ? 'Stop pipeline'
- : statusName === PipelineStatusName.FAILED
- ? 'Restart pipeline'
- : null
+ // Show both stop and restart for started/failed states
+ const showStopAndRestart =
+ canPerformActions &&
+ (statusName === PipelineStatusName.STARTED || statusName === PipelineStatusName.FAILED)
+
+ // Show only start for stopped state
+ const showStart = canPerformActions && statusName === PipelineStatusName.STOPPED
const onEnablePipeline = async () => {
if (!projectRef) return console.error('Project ref is required')
@@ -160,23 +152,24 @@ export const RowMenu = ({
<DropdownMenuSeparator />
</>
)}
- {hasPipelineAction && (
+ {showStart && (
<>
- <DropdownMenuItem
- className="space-x-2"
- disabled={!PIPELINE_ACTIONABLE_STATES.includes((statusName ?? '') as any)}
- onClick={() => {
- if (statusName === PipelineStatusName.STOPPED) {
- onEnablePipeline()
- } else if (statusName === PipelineStatusName.STARTED) {
- onDisablePipeline()
- } else if (statusName === PipelineStatusName.FAILED) {
- onRestartPipeline()
- }
- }}
- >
- {pipelineActionIcon}
- <p>{pipelineActionLabel}</p>
+ <DropdownMenuItem className="space-x-2" onClick={onEnablePipeline}>
+ <Play size={14} />
+ <p>Start pipeline</p>
+ </DropdownMenuItem>
+ <DropdownMenuSeparator />
+ </>
+ )}
+ {showStopAndRestart && (
+ <>
+ <DropdownMenuItem className="space-x-2" onClick={onRestartPipeline}>
+ <RotateCcw size={14} />
+ <p>Restart pipeline</p>
+ </DropdownMenuItem>
+ <DropdownMenuItem className="space-x-2" onClick={onDisablePipeline}>
+ <Pause size={14} />
+ <p>Stop pipeline</p>
</DropdownMenuItem>
<DropdownMenuSeparator />
</>
diff --git a/apps/studio/components/interfaces/HomeNew/Home.tsx b/apps/studio/components/interfaces/HomeNew/Home.tsx
index 49d80d5c36a..5e00cf6160c 100644
--- a/apps/studio/components/interfaces/HomeNew/Home.tsx
+++ b/apps/studio/components/interfaces/HomeNew/Home.tsx
@@ -1,6 +1,6 @@
-import dayjs from 'dayjs'
import { DndContext, DragEndEvent, PointerSensor, useSensor, useSensors } from '@dnd-kit/core'
import { arrayMove, SortableContext, verticalListSortingStrategy } from '@dnd-kit/sortable'
+import dayjs from 'dayjs'
import { useEffect, useRef } from 'react'
import { IS_PLATFORM, useParams } from 'common'
diff --git a/apps/studio/components/ui/Forms/FormHeader.tsx b/apps/studio/components/ui/Forms/FormHeader.tsx
index aa7da61dd0e..ee6cc8388dd 100644
--- a/apps/studio/components/ui/Forms/FormHeader.tsx
+++ b/apps/studio/components/ui/Forms/FormHeader.tsx
@@ -23,7 +23,7 @@ export const FormHeader = ({
>
<div className="space-y-1">
<h3 className="text-foreground text-xl prose">{title}</h3>
- {description && <div className="prose text-sm max-w-2xl">{description}</div>}
+ {description && <p className="prose text-sm max-w-2xl">{description}</p>}
</div>
<div className="flex flex-col sm:flex-row md:items-center gap-x-2">
{docsUrl !== undefined && <DocsButton href={docsUrl} />}
diff --git a/apps/studio/pages/project/[ref]/database/replication/index.tsx b/apps/studio/pages/project/[ref]/database/replication/index.tsx
index 9b78e282d03..b47f8257ff4 100644
--- a/apps/studio/pages/project/[ref]/database/replication/index.tsx
+++ b/apps/studio/pages/project/[ref]/database/replication/index.tsx
@@ -26,7 +26,11 @@ const DatabaseReplicationPage: NextPageWithLayout = () => {
<ScaffoldContainer>
<ScaffoldSection>
<div className="col-span-12">
- <FormHeader title="Replication" />
+ <FormHeader
+ className="[&>div>p]:max-w-full"
+ title="Replication"
+ description="Automatically replicate your database changes to external data warehouses and analytics platforms in real-time"
+ />
<Destinations />
</div>
</ScaffoldSection>