Skip to content

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

Refactor polling logic for Analytics Buckets while syncing with namespace (#40381)

Joshen Lime36ae95eb7d9
diff --git a/apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/constants.ts b/apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/AnalyticsBucketDetails.constants.ts
similarity index 100%
rename from apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/constants.ts
rename to apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/AnalyticsBucketDetails.constants.ts
diff --git a/apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/AnalyticsBucketDetails.utils.ts b/apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/AnalyticsBucketDetails.utils.ts
index cce42b5f44b..e52f59273ea 100644
--- a/apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/AnalyticsBucketDetails.utils.ts
+++ b/apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/AnalyticsBucketDetails.utils.ts
@@ -15,3 +15,10 @@ export const getAnalyticsBucketFDWName = (bucketId: string) => {
export const getAnalyticsBucketFDWServerName = (bucketId: string) => {
return `${snakeCase(bucketId)}_fdw_server`
}
+
+export const getNamespaceTableNameFromPostgresTableName = (table: {
+ name: string
+ schema: string
+}) => {
+ return `${snakeCase(`${table.schema}.${table.name}`)}_changelog`
+}
diff --git a/apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/BucketHeader.tsx b/apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/BucketHeader.tsx
new file mode 100644
index 00000000000..07900b4d9cc
--- /dev/null
+++ b/apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/BucketHeader.tsx
@@ -0,0 +1,62 @@
+import { noop } from 'lodash'
+import Link from 'next/link'
+
+import { useParams } from 'common'
+import { FormattedWrapperTable } from 'components/interfaces/Integrations/Wrappers/Wrappers.utils'
+import {
+ ScaffoldHeader,
+ ScaffoldSectionDescription,
+ ScaffoldSectionTitle,
+} from 'components/layouts/Scaffold'
+import { useReplicationPipelineStatusQuery } from 'data/etl/pipeline-status-query'
+import { Button } from 'ui'
+import { ConnectTablesDialog } from './ConnectTablesDialog'
+import { useAnalyticsBucketAssociatedEntities } from './useAnalyticsBucketAssociatedEntities'
+
+interface BucketHeaderProps {
+ showActions?: boolean
+ namespaces?: {
+ namespace: string
+ schema: string
+ tables: FormattedWrapperTable[]
+ }[]
+ onSuccessConnectTables?: () => void
+}
+
+export const BucketHeader = ({
+ showActions = true,
+ namespaces = [],
+ onSuccessConnectTables = noop,
+}: BucketHeaderProps) => {
+ const { ref: projectRef, bucketId } = useParams()
+
+ const { pipeline } = useAnalyticsBucketAssociatedEntities({ projectRef, bucketId })
+ const { data } = useReplicationPipelineStatusQuery({ projectRef, pipelineId: pipeline?.id })
+ const pipelineStatus = data?.status.name
+ const isPipelineRunning = pipelineStatus === 'started'
+
+ return (
+ <ScaffoldHeader className="pt-0 flex flex-row justify-between items-end gap-x-8">
+ <div>
+ <ScaffoldSectionTitle>Tables</ScaffoldSectionTitle>
+ <ScaffoldSectionDescription>
+ Analytics tables stored in this bucket
+ </ScaffoldSectionDescription>
+ </div>
+ {showActions && (
+ <div className="flex items-center gap-x-2">
+ {!!pipeline && isPipelineRunning && (
+ <Button asChild type="default">
+ <Link href={`/project/${projectRef}/database/etl/${pipeline.replicator_id}`}>
+ View replication
+ </Link>
+ </Button>
+ )}
+ {namespaces.length > 0 && (
+ <ConnectTablesDialog onSuccessConnectTables={onSuccessConnectTables} />
+ )}
+ </div>
+ )}
+ </ScaffoldHeader>
+ )
+}
diff --git a/apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/ConnectTablesDialog.tsx b/apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/ConnectTablesDialog.tsx
index 1ec27e28f3e..68cbd5a1b59 100644
--- a/apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/ConnectTablesDialog.tsx
+++ b/apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/ConnectTablesDialog.tsx
@@ -92,7 +92,7 @@ const PROGRESS_INDICATORS = {
}
interface ConnectTablesDialogProps {
- onSuccessConnectTables: (tables: { schema: string; name: string }[]) => void
+ onSuccessConnectTables: () => void
}
export const ConnectTablesDialog = ({ onSuccessConnectTables }: ConnectTablesDialogProps) => {
@@ -245,7 +245,7 @@ export const ConnectTablesDialogContent = ({
setConnectingStep(PROGRESS_STAGE.START_PIPELINE)
await startPipeline({ projectRef, pipelineId })
- onSuccessConnectTables?.(publicationTables)
+ onSuccessConnectTables?.()
toast.success(`Connected ${values.tables.length} tables to Analytics bucket!`)
form.reset()
onClose()
@@ -287,7 +287,7 @@ export const ConnectTablesDialogContent = ({
setConnectingStep(PROGRESS_STAGE.START_PIPELINE)
await startPipeline({ projectRef, pipelineId: pipeline.id })
- onSuccessConnectTables?.(tablesToBeAdded)
+ onSuccessConnectTables?.()
toast.success('Successfully updated connected tables! Pipeline is being restarted')
onClose()
} catch (error: any) {
diff --git a/apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/NamespaceWithTables/TableRowComponent.tsx b/apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/NamespaceWithTables/TableRowComponent.tsx
index c6d19921169..7661747b52f 100644
--- a/apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/NamespaceWithTables/TableRowComponent.tsx
+++ b/apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/NamespaceWithTables/TableRowComponent.tsx
@@ -1,4 +1,4 @@
-import { snakeCase, uniq } from 'lodash'
+import { uniq } from 'lodash'
import { Loader2, MoreVertical, Pause, Play, Trash } from 'lucide-react'
import Link from 'next/link'
import { useMemo, useState } from 'react'
@@ -34,7 +34,10 @@ import {
TooltipTrigger,
} from 'ui'
import { ConfirmationModal } from 'ui-patterns/Dialogs/ConfirmationModal'
-import { getAnalyticsBucketFDWServerName } from '../AnalyticsBucketDetails.utils'
+import {
+ getAnalyticsBucketFDWServerName,
+ getNamespaceTableNameFromPostgresTableName,
+} from '../AnalyticsBucketDetails.utils'
import { useAnalyticsBucketAssociatedEntities } from '../useAnalyticsBucketAssociatedEntities'
import { useAnalyticsBucketWrapperInstance } from '../useAnalyticsBucketWrapperInstance'
import { inferPostgresTableFromNamespaceTable } from './NamespaceWithTables.utils'
@@ -116,7 +119,7 @@ export const TableRowComponent = ({
// [Joshen ALPHA] Assumption here is that all the namespace tables have _changelog as suffix
// May need to update if that assumption falls short (e.g for those dealing with iceberg APIs directly)
const updatedTables = publication.tables.filter(
- (x) => table.name !== snakeCase(`${x.schema}.${x.name}_changelog`)
+ (x) => table.name !== getNamespaceTableNameFromPostgresTableName(x)
)
await updatePublication({
projectRef,
@@ -142,7 +145,9 @@ export const TableRowComponent = ({
if (!pipeline) return toast.error('Unable to find existing pipeline')
// [Joshen ALPHA] This has potential to be flaky - we should see how we can get the table name and schema better
- const pgTable = tables?.find((t) => snakeCase(`${t.schema}.${t.name}_changelog`) === table.name)
+ const pgTable = tables?.find(
+ (t) => getNamespaceTableNameFromPostgresTableName(t) === table.name
+ )
if (!pgTable) return toast.error('Unable to find corresponding Postgres table')
try {
diff --git a/apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/NamespaceWithTables/index.tsx b/apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/NamespaceWithTables/index.tsx
index e5419936459..1556842da14 100644
--- a/apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/NamespaceWithTables/index.tsx
+++ b/apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/NamespaceWithTables/index.tsx
@@ -1,5 +1,5 @@
import { ChevronRight, Info, Loader2, Plus, RefreshCw } from 'lucide-react'
-import { useMemo, useState } from 'react'
+import { useEffect, useMemo, useState } from 'react'
import { useParams } from 'common'
import type { WrapperMeta } from 'components/interfaces/Integrations/Wrappers/Wrappers.types'
@@ -25,6 +25,7 @@ import {
TooltipContent,
TooltipTrigger,
} from 'ui'
+import { getNamespaceTableNameFromPostgresTableName } from '../AnalyticsBucketDetails.utils'
import { useAnalyticsBucketAssociatedEntities } from '../useAnalyticsBucketAssociatedEntities'
import { TableRowComponent } from './TableRowComponent'
@@ -37,7 +38,6 @@ type NamespaceWithTablesProps = {
wrapperInstance: FDW
wrapperValues: Record<string, string>
wrapperMeta: WrapperMeta
- tablesToPoll: { schema: string; name: string }[]
pollIntervalNamespaceTables: number
setPollIntervalNamespaceTables: (value: number) => void
}
@@ -51,7 +51,6 @@ export const NamespaceWithTables = ({
wrapperInstance,
wrapperValues,
wrapperMeta,
- tablesToPoll,
pollIntervalNamespaceTables,
setPollIntervalNamespaceTables,
}: NamespaceWithTablesProps) => {
@@ -61,7 +60,11 @@ export const NamespaceWithTables = ({
const { publication } = useAnalyticsBucketAssociatedEntities({ projectRef, bucketId })
- const { data: tablesData, isLoading: isLoadingNamespaceTables } = useIcebergNamespaceTablesQuery(
+ const {
+ data: tablesData = [],
+ isLoading: isLoadingNamespaceTables,
+ isSuccess: isSuccessNamespaceTables,
+ } = useIcebergNamespaceTablesQuery(
{
catalogUri: wrapperValues.catalog_uri,
warehouse: wrapperValues.warehouse,
@@ -69,23 +72,30 @@ export const NamespaceWithTables = ({
projectRef,
},
{
- refetchInterval: (data) => {
+ refetchInterval: (data = []) => {
if (pollIntervalNamespaceTables === 0) return false
- if (tablesToPoll.length > 0) {
- const hasMissingTables =
- (data ?? []).filter((t) => !tables.find((table) => table.table.split('.')[1] === t))
- .length > 0
- if (hasMissingTables) {
- setPollIntervalNamespaceTables(0)
- return false
- }
+ const publicationTables = publication?.tables ?? []
+ const isSynced = !publicationTables.some(
+ (x) => !data.includes(getNamespaceTableNameFromPostgresTableName(x))
+ )
+ if (isSynced) {
+ setPollIntervalNamespaceTables(0)
+ return false
}
+
return pollIntervalNamespaceTables
},
}
)
+ const publicationTables = publication?.tables ?? []
+ const publicationTablesNotSyncedToNamespaceTables = publicationTables.filter(
+ (x) => !tablesData.includes(getNamespaceTableNameFromPostgresTableName(x))
+ )
+ const isSyncedPublicationTablesAndNamespaceTables =
+ publicationTablesNotSyncedToNamespaceTables.length === 0
+
const { mutateAsync: importForeignSchema, isLoading: isImportingForeignSchema } =
useFDWImportForeignSchemaMutation()
@@ -140,6 +150,13 @@ export const NamespaceWithTables = ({
return `fdw_analytics_${namespace.replaceAll('-', '_')}`
}, [schema, namespace])
+ useEffect(() => {
+ if (isSuccessNamespaceTables && !isSyncedPublicationTablesAndNamespaceTables) {
+ setPollIntervalNamespaceTables(4000)
+ }
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [isSuccessNamespaceTables, isSyncedPublicationTablesAndNamespaceTables])
+
return (
<Card>
<CardHeader className="flex flex-row justify-between items-center px-4 py-5 space-y-0">
@@ -179,14 +196,28 @@ export const NamespaceWithTables = ({
)}
</CardTitle>
- <div className="flex flex-row gap-x-2">
- {tablesToPoll.length > 0 && (
- <div className="flex items-center gap-x-2 ml-6 text-foreground-lighter">
- <Loader2 size={14} className="animate-spin" />
- <p className="text-sm">
- Connecting {tablesToPoll.length} table{tablesToPoll.length > 1 ? 's' : ''}
- </p>
- </div>
+ <div className="flex flex-row gap-x-6">
+ {pollIntervalNamespaceTables > 0 && (
+ <Tooltip>
+ <TooltipTrigger>
+ <div className="flex items-center gap-x-2 text-foreground-lighter">
+ <Loader2 size={14} className="animate-spin" />
+ <p className="text-sm">
+ Connecting {publicationTablesNotSyncedToNamespaceTables.length} table
+ {publicationTablesNotSyncedToNamespaceTables.length > 1 ? 's' : ''}
+ </p>
+ </div>
+ </TooltipTrigger>
+ <TooltipContent side="bottom" align="end">
+ <p className="mb-1">Waiting for namespace table to be created for:</p>
+ <ul className="list-disc pl-6">
+ {publicationTablesNotSyncedToNamespaceTables.map((x) => {
+ const value = `${x.schema}.${x.name}`
+ return <li key={value}>{value}</li>
+ })}
+ </ul>
+ </TooltipContent>
+ </Tooltip>
)}
{missingTables.length > 0 && (
<Button
@@ -202,7 +233,7 @@ export const NamespaceWithTables = ({
</div>
</CardHeader>
- {tablesToPoll.length > 0 && <LoadingLine loading />}
+ {pollIntervalNamespaceTables > 0 && <LoadingLine loading />}
<Table>
<TableHeader>
diff --git a/apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/SimpleConfigurationDetails.tsx b/apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/SimpleConfigurationDetails.tsx
index 4235fbaa115..5bad19aa723 100644
--- a/apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/SimpleConfigurationDetails.tsx
+++ b/apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/SimpleConfigurationDetails.tsx
@@ -10,7 +10,7 @@ import {
import { InlineLink } from 'components/ui/InlineLink'
import { DOCS_URL } from 'lib/constants'
import { Card } from 'ui'
-import { DESCRIPTIONS, LABELS, OPTION_ORDER } from './constants'
+import { DESCRIPTIONS, LABELS, OPTION_ORDER } from './AnalyticsBucketDetails.constants'
import { CopyEnvButton } from './CopyEnvButton'
import { DecryptedReadOnlyInput } from './DecryptedReadOnlyInput'
import { useAnalyticsBucketWrapperInstance } from './useAnalyticsBucketWrapperInstance'
@@ -27,7 +27,7 @@ export const SimpleConfigurationDetails = ({ bucketName }: { bucketName?: string
return (
<ScaffoldSection isFullWidth>
- <ScaffoldHeader className="flex flex-row justify-between items-end gap-x-8">
+ <ScaffoldHeader className="flex flex-row justify-between items-end gap-x-8 pt-0">
<div>
<ScaffoldSectionTitle>Connection details</ScaffoldSectionTitle>
<ScaffoldSectionDescription>
diff --git a/apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/index.tsx b/apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/index.tsx
index 1138c60358f..dfa989439f3 100644
--- a/apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/index.tsx
+++ b/apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/index.tsx
@@ -14,9 +14,7 @@ import {
import { useSelectedBucket } from 'components/interfaces/Storage/StorageExplorer/useSelectedBucket'
import {
ScaffoldContainer,
- ScaffoldHeader,
ScaffoldSection,
- ScaffoldSectionDescription,
ScaffoldSectionTitle,
} from 'components/layouts/Scaffold'
import AlertError from 'components/ui/AlertError'
@@ -34,8 +32,9 @@ import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
import { DOCS_URL } from 'lib/constants'
import { Button, Card, CardContent } from 'ui'
import { Admonition } from 'ui-patterns/admonition'
-import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader'
+import { GenericTableLoader } from 'ui-patterns/ShimmeringLoader'
import { DeleteAnalyticsBucketModal } from '../DeleteAnalyticsBucketModal'
+import { BucketHeader } from './BucketHeader'
import { ConnectTablesDialog } from './ConnectTablesDialog'
import { NamespaceWithTables } from './NamespaceWithTables'
import { SimpleConfigurationDetails } from './SimpleConfigurationDetails'
@@ -61,17 +60,15 @@ export const AnalyticBucketDetails = () => {
// updating connected tables until namespaces are updated
// Namespace would just be the schema (Which is currently limited to public)
// Wrapper table would be {schema}_{table}_changelog
- const [tablesToPoll, setTablesToPoll] = useState<{ schema: string; name: string }[]>([])
const [pollIntervalNamespaces, setPollIntervalNamespaces] = useState(0)
const [pollIntervalNamespaceTables, setPollIntervalNamespaceTables] = useState(0)
const { mutateAsync: startPipeline, isLoading: isStartingPipeline } = useStartPipelineMutation()
/** The wrapper instance is the wrapper that is installed for this Analytics bucket. */
- const { data: wrapperInstance, isLoading } = useAnalyticsBucketWrapperInstance({
- bucketId: bucket?.id,
- })
- const { pipeline } = useAnalyticsBucketAssociatedEntities({
+ const { data: wrapperInstance, isLoading: isLoadingWrapperInstance } =
+ useAnalyticsBucketWrapperInstance({ bucketId: bucket?.id })
+ const { publication, pipeline } = useAnalyticsBucketAssociatedEntities({
projectRef,
bucketId: bucket?.id,
})
@@ -79,7 +76,7 @@ export const AnalyticBucketDetails = () => {
{ projectRef, pipelineId: pipeline?.id },
{
refetchInterval: (data) => {
- if (data?.status.name !== 'started') return 2000
+ if (data?.status.name !== 'started') return 4000
else return false
},
}
@@ -91,7 +88,7 @@ export const AnalyticBucketDetails = () => {
const wrapperValues = convertKVStringArrayToJson(wrapperInstance?.server_options ?? [])
const integration = INTEGRATIONS.find((i) => i.id === 'iceberg_wrapper' && i.type === 'wrapper')
const wrapperMeta = (integration?.type === 'wrapper' && integration.meta) as WrapperMeta
- const state = isLoading
+ const state = isLoadingWrapperInstance
? 'loading'
: extensionState === 'installed'
? wrapperInstance
@@ -110,29 +107,40 @@ export const AnalyticBucketDetails = () => {
})
const wrappersExtension = extensionsData?.find((ext) => ext.name === 'wrappers')
- const { data: namespacesData, isLoading: isLoadingNamespaces } = useIcebergNamespacesQuery(
+ const {
+ data: namespacesData = [],
+ error: namespacesError,
+ isLoading: isLoadingNamespaces,
+ isSuccess: isSuccessNamespaces,
+ isError: isErrorNamespaces,
+ } = useIcebergNamespacesQuery(
{
projectRef,
catalogUri: wrapperValues.catalog_uri,
warehouse: wrapperValues.warehouse,
},
{
- refetchInterval: (data) => {
+ refetchInterval: (data = []) => {
if (pollIntervalNamespaces === 0) return false
- if (tablesToPoll.length > 0) {
- const schemas = [...new Set(tablesToPoll.map((x) => x.schema))]
- const hasSchemaMissingFromNamespace = !schemas.some((x) => (data ?? []).includes(x))
- if (!hasSchemaMissingFromNamespace) {
- setPollIntervalNamespaces(0)
- return false
- }
+ const publicationTableSchemas = publication?.tables.map((x) => x.schema) ?? []
+ const isSynced = !publicationTableSchemas.some((x) => !data.includes(x))
+ if (isSynced) {
+ setPollIntervalNamespaces(0)
+ return false
}
+
return pollIntervalNamespaces
},
}
)
+ const publicationTableSchemas = (publication?.tables ?? []).map((x) => x.schema)
+ const isSyncedPublicationTableSchemasAndNamespaces = !publicationTableSchemas.some(
+ (x) => !namespacesData.includes(x)
+ )
+ const isPollingForData = pollIntervalNamespaces > 0 || pollIntervalNamespaceTables > 0
+
const namespaces = useMemo(() => {
const fdwNamespaces = wrapperTables.map((t) => t.table.split('.')[0]) as string[]
const namespaces = uniq([...fdwNamespaces, ...(namespacesData ?? [])])
@@ -150,10 +158,10 @@ export const AnalyticBucketDetails = () => {
}, [wrapperTables, namespacesData])
useEffect(() => {
- if (pollIntervalNamespaces === 0 && pollIntervalNamespaceTables === 0) {
- setTablesToPoll([])
+ if (isSuccessNamespaces && !isSyncedPublicationTableSchemasAndNamespaces) {
+ setPollIntervalNamespaces(4000)
}
- }, [pollIntervalNamespaces, pollIntervalNamespaceTables])
+ }, [isSuccessNamespaces, isSyncedPublicationTableSchemasAndNamespaces])
return (
<>
@@ -165,65 +173,45 @@ export const AnalyticBucketDetails = () => {
</ScaffoldContainer>
) : (
<ScaffoldContainer bottomPadding>
- {state === 'loading' && (
+ {state === 'loading' ? (
<ScaffoldSection isFullWidth>
- <GenericSkeletonLoader />
+ <BucketHeader showActions={false} />
+ <GenericTableLoader headers={['Name']} />
</ScaffoldSection>
- )}
- {state === 'not-installed' && (
+ ) : state === 'not-installed' ? (
<ExtensionNotInstalled
bucketName={bucket?.id}
projectRef={project?.ref!}
wrapperMeta={wrapperMeta}
wrappersExtension={wrappersExtension!}
/>
- )}
- {state === 'needs-upgrade' && (
+ ) : state === 'needs-upgrade' ? (
<ExtensionNeedsUpgrade
bucketName={bucket?.id}
projectRef={project?.ref!}
wrapperMeta={wrapperMeta}
wrappersExtension={wrappersExtension!}
/>
- )}
-
- {state === 'added' && wrapperInstance && (
+ ) : state === 'missing' ? (
+ <WrapperMissing bucketName={bucket?.id} />
+ ) : state === 'added' && wrapperInstance ? (
<>
<ScaffoldSection isFullWidth>
- <ScaffoldHeader className="pt-0 flex flex-row justify-between items-end gap-x-8">
- <div>
- <ScaffoldSectionTitle>Tables</ScaffoldSectionTitle>
- <ScaffoldSectionDescription>
- Analytics tables stored in this bucket
- </ScaffoldSectionDescription>
- </div>
- <div className="flex items-center gap-x-2">
- {!!pipeline && isPipelineRunning && (
- <Button asChild type="default">
- <Link
- href={`/project/${projectRef}/database/etl/${pipeline.replicator_id}`}
- >
- View replication
- </Link>
- </Button>
- )}
- {namespaces.length > 0 && (
- <ConnectTablesDialog
- onSuccessConnectTables={(tables) => {
- setTablesToPoll(tables)
- setPollIntervalNamespaces(4000)
- setPollIntervalNamespaceTables(4000)
- }}
- />
- )}
- </div>
- </ScaffoldHeader>
+ <BucketHeader
+ namespaces={namespaces}
+ onSuccessConnectTables={() => {
+ setPollIntervalNamespaces(4000)
+ setPollIntervalNamespaceTables(4000)
+ }}
+ />
- {isLoadingNamespaces || isLoading ? (
- <GenericSkeletonLoader />
+ {isLoadingNamespaces || isLoadingWrapperInstance ? (
+ <GenericTableLoader headers={['Name']} />
+ ) : isErrorNamespaces ? (
+ <AlertError subject="Failed to retrieve namespaces" error={namespacesError} />
) : namespaces.length === 0 ? (
<>
- {tablesToPoll.length > 0 ? (
+ {isPollingForData ? (
<aside className="border border-dashed w-full bg-surface-100 rounded-lg px-4 py-10 flex flex-col gap-y-3 items-center text-center gap-1 text-balance">
<Loader2
size={24}
@@ -231,10 +219,7 @@ export const AnalyticBucketDetails = () => {
className="animate-spin text-foreground-muted"
/>
<div className="flex flex-col items-center text-center">
- <h3>
- Connecting {tablesToPoll.length} table
- {tablesToPoll.length > 1 ? 's' : ''} to bucket
- </h3>
+ <h3>Connecting table(s) to bucket</h3>
<p className="text-foreground-light text-sm">
Tables will be shown here once the connection is complete
</p>
@@ -250,8 +235,7 @@ export const AnalyticBucketDetails = () => {
</p>
</div>
<ConnectTablesDialog
- onSuccessConnectTables={(tables) => {
- setTablesToPoll(tables)
+ onSuccessConnectTables={() => {
setPollIntervalNamespaces(4000)
setPollIntervalNamespaceTables(4000)
}}
@@ -320,7 +304,6 @@ export const AnalyticBucketDetails = () => {
wrapperInstance={wrapperInstance}
wrapperValues={wrapperValues}
wrapperMeta={wrapperMeta}
- tablesToPoll={tablesToPoll}
pollIntervalNamespaceTables={pollIntervalNamespaceTables}
setPollIntervalNamespaceTables={setPollIntervalNamespaceTables}
/>
@@ -332,8 +315,7 @@ export const AnalyticBucketDetails = () => {
<SimpleConfigurationDetails bucketName={bucket?.id} />
</>
- )}
- {state === 'missing' && <WrapperMissing bucketName={bucket?.id} />}
+ ) : null}
<ScaffoldSection isFullWidth className="flex flex-col gap-y-4">
<header>
diff --git a/apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/useAnalyticsBucketWrapperInstance.tsx b/apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/useAnalyticsBucketWrapperInstance.tsx
index 75f534fe51b..795b2b81011 100644
--- a/apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/useAnalyticsBucketWrapperInstance.tsx
+++ b/apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/useAnalyticsBucketWrapperInstance.tsx
@@ -44,6 +44,6 @@ export const useAnalyticsBucketWrapperInstance = (
return {
data: icebergWrapper,
meta: icebergWrapperMeta,
- isLoading: isLoadingProject || isLoadingFDWs,
+ isLoading: isLoadingProject || isLoadingFDWs || !bucketId,
}
}
diff --git a/apps/studio/data/etl/start-pipeline-mutation.ts b/apps/studio/data/etl/start-pipeline-mutation.ts
index f613a0c44d3..ffa74e096b8 100644
--- a/apps/studio/data/etl/start-pipeline-mutation.ts
+++ b/apps/studio/data/etl/start-pipeline-mutation.ts
@@ -43,9 +43,24 @@ export const useStartPipelineMutation = ({
mutationFn: (vars) => startPipeline(vars),
async onSuccess(data, variables, context) {
const { projectRef, pipelineId } = variables
+
await queryClient.invalidateQueries({
queryKey: replicationKeys.pipelinesStatus(projectRef, pipelineId),
})
+
+ // [Joshen] We're manually updating the query client here as the pipeline status is async
+ // So setting it so starting while letting long poll update the actual status thereafter
+ queryClient.setQueriesData(
+ {
+ queryKey: replicationKeys.pipelinesStatus(projectRef, pipelineId),
+ exact: true,
+ },
+ (prev) => {
+ if (!prev) return prev
+ return { ...prev, status: { name: 'starting' } }
+ }
+ )
+
await onSuccess?.(data, variables, context)
},
async onError(data, variables, context) {
diff --git a/packages/ui-patterns/src/ShimmeringLoader/index.tsx b/packages/ui-patterns/src/ShimmeringLoader/index.tsx
index 17457b88c71..af582426138 100644
--- a/packages/ui-patterns/src/ShimmeringLoader/index.tsx
+++ b/packages/ui-patterns/src/ShimmeringLoader/index.tsx
@@ -1,4 +1,4 @@
-import { cn } from 'ui'
+import { Card, cn, Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from 'ui'
export interface ShimmeringLoader {
className?: string
@@ -6,7 +6,7 @@ export interface ShimmeringLoader {
animationDelay?: number
}
-const ShimmeringLoader = ({
+export const ShimmeringLoader = ({
className,
delayIndex = 0,
animationDelay = 150,
@@ -26,7 +26,7 @@ interface GenericSkeletonLoaderProps {
className?: string
}
-const GenericSkeletonLoader = ({ className }: GenericSkeletonLoaderProps) => (
+export const GenericSkeletonLoader = ({ className }: GenericSkeletonLoaderProps) => (
<div className={cn(className, 'space-y-2')}>
<ShimmeringLoader />
<ShimmeringLoader className="w-3/4" />
@@ -34,5 +34,35 @@ const GenericSkeletonLoader = ({ className }: GenericSkeletonLoaderProps) => (
</div>
)
-export { GenericSkeletonLoader }
+export const GenericTableLoader = ({
+ headers,
+ numRows = 3,
+}: {
+ headers: (string | null)[]
+ numRows?: number
+}) => {
+ return (
+ <Card>
+ <Table>
+ <TableHeader>
+ <TableRow>
+ {headers.map((h, i) => (
+ <TableHead key={`${h}_${i}`}>{h}</TableHead>
+ ))}
+ </TableRow>
+ </TableHeader>
+ <TableBody>
+ {new Array(numRows).fill(0).map((_, i) => (
+ <TableRow key={`row_${i}`}>
+ <TableCell colSpan={headers.length}>
+ <ShimmeringLoader />
+ </TableCell>
+ </TableRow>
+ ))}
+ </TableBody>
+ </Table>
+ </Card>
+ )
+}
+
export default ShimmeringLoader