Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(data-warehouse): give the resync button user feedback (#65283)

Jovan Sakovic06088ff29f10
diff --git a/products/data_warehouse/frontend/scenes/SchemaScene/ConfigurationTab.tsx b/products/data_warehouse/frontend/scenes/SchemaScene/ConfigurationTab.tsx
index 418e365ea8ba..64bcfa0c6f70 100644
--- a/products/data_warehouse/frontend/scenes/SchemaScene/ConfigurationTab.tsx
+++ b/products/data_warehouse/frontend/scenes/SchemaScene/ConfigurationTab.tsx
@@ -82,7 +82,7 @@ export function ConfigurationTab({
onViewSyncHistory,
}: ConfigurationTabProps): JSX.Element {
const logic = schemaSceneLogic({ sourceId, schemaId: schema.id })
- const { isProjectTime, refreshingSchemas } = useValues(logic)
+ const { isProjectTime, refreshingSchemas, resyncingSchema } = useValues(logic)
const { setIsProjectTime, updateSchema, reloadSchema, resyncSchema, cancelSchema, deleteTable, refreshSchemas } =
useActions(logic)
@@ -128,6 +128,7 @@ export function ConfigurationTab({
source={source}
schema={schema}
resyncSchema={resyncSchema}
+ resyncingSchema={resyncingSchema}
deleteTable={deleteTable}
/>
)
@@ -882,11 +883,13 @@ function DangerZoneSection({
source,
schema,
resyncSchema,
+ resyncingSchema,
deleteTable,
}: {
source: ExternalDataSource | null
schema: ExternalDataSourceSchema
resyncSchema: (schema: ExternalDataSourceSchema) => void
+ resyncingSchema: boolean
deleteTable: (schema: ExternalDataSourceSchema) => void
}): JSX.Element {
const hasFullCdcResync = schema.sync_type === 'cdc'
@@ -953,6 +956,7 @@ function DangerZoneSection({
secondaryButton: { children: 'Cancel', type: 'tertiary' },
})
}}
+ loading={resyncingSchema}
disabledReason={disabledReason}
>
Full resync
@@ -965,6 +969,7 @@ function DangerZoneSection({
type="secondary"
status="danger"
onClick={() => resyncSchema(schema)}
+ loading={resyncingSchema}
disabledReason={disabledReason}
>
Delete table and resync
diff --git a/products/data_warehouse/frontend/scenes/SchemaScene/schemaSceneLogic.test.ts b/products/data_warehouse/frontend/scenes/SchemaScene/schemaSceneLogic.test.ts
new file mode 100644
index 000000000000..c4daf6bc50d8
--- /dev/null
+++ b/products/data_warehouse/frontend/scenes/SchemaScene/schemaSceneLogic.test.ts
@@ -0,0 +1,80 @@
+import { expectLogic } from 'kea-test-utils'
+
+import api from 'lib/api'
+
+import { initKeaTests } from '~/test/init'
+import { ExternalDataSchemaStatus, ExternalDataSchemaWithSource } from '~/types'
+
+import { schemaSceneLogic } from './schemaSceneLogic'
+
+jest.mock('lib/api')
+
+const makeSchema = (overrides: Partial<ExternalDataSchemaWithSource> = {}): ExternalDataSchemaWithSource =>
+ ({
+ id: 'schema-1',
+ name: 'public.events',
+ label: null,
+ should_sync: true,
+ incremental: true,
+ sync_type: 'incremental',
+ status: ExternalDataSchemaStatus.Completed,
+ source: { source_type: 'Postgres' },
+ ...overrides,
+ }) as ExternalDataSchemaWithSource
+
+describe('schemaSceneLogic', () => {
+ let logic: ReturnType<typeof schemaSceneLogic.build>
+
+ beforeEach(() => {
+ initKeaTests()
+ jest.spyOn(api.externalDataSchemas, 'get').mockResolvedValue(makeSchema())
+
+ logic = schemaSceneLogic({ sourceId: 'source-1', schemaId: 'schema-1' })
+ logic.mount()
+ })
+
+ afterEach(() => {
+ logic?.unmount()
+ jest.restoreAllMocks()
+ })
+
+ it('resyncSchema toggles the loading flag around the request and resyncs by id', async () => {
+ await expectLogic(logic).toFinishAllListeners()
+
+ let resolveResync: (() => void) | null = null
+ const resyncSpy = jest
+ .spyOn(api.externalDataSchemas, 'resync')
+ .mockReturnValue(new Promise<void>((resolve) => (resolveResync = () => resolve())))
+
+ logic.actions.resyncSchema(makeSchema())
+ expect(logic.values.resyncingSchema).toBe(true)
+ expect(resyncSpy).toHaveBeenCalledWith('schema-1')
+
+ resolveResync!()
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(logic.values.resyncingSchema).toBe(false)
+ })
+
+ it('clears the loading flag even when the resync request fails', async () => {
+ await expectLogic(logic).toFinishAllListeners()
+
+ jest.spyOn(api.externalDataSchemas, 'resync').mockRejectedValue(new Error('boom'))
+
+ logic.actions.resyncSchema(makeSchema())
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(logic.values.resyncingSchema).toBe(false)
+ })
+
+ it('optimistically marks the schema as running when a resync starts', async () => {
+ await expectLogic(logic).toFinishAllListeners()
+
+ // Keep the request pending so the optimistic status is observable before loadSchema refetches.
+ jest.spyOn(api.externalDataSchemas, 'resync').mockReturnValue(new Promise<void>(() => {}))
+
+ logic.actions.resyncSchema(makeSchema())
+
+ expect(logic.values.schema?.status).toBe(ExternalDataSchemaStatus.Running)
+ })
+})
diff --git a/products/data_warehouse/frontend/scenes/SchemaScene/schemaSceneLogic.ts b/products/data_warehouse/frontend/scenes/SchemaScene/schemaSceneLogic.ts
index 3bd951dcbab9..05c258528026 100644
--- a/products/data_warehouse/frontend/scenes/SchemaScene/schemaSceneLogic.ts
+++ b/products/data_warehouse/frontend/scenes/SchemaScene/schemaSceneLogic.ts
@@ -66,6 +66,7 @@ export const schemaSceneLogic = kea<schemaSceneLogicType>([
_setCurrentSection: (section: SchemaConfigurationSection) => ({ section }),
setIsProjectTime: (isProjectTime: boolean) => ({ isProjectTime }),
setRefreshingSchemas: (refreshing: boolean) => ({ refreshing }),
+ setResyncingSchema: (resyncing: boolean) => ({ resyncing }),
updateSchema: (schema: ExternalDataSourceSchema) => ({ schema }),
reloadSchema: (schema: ExternalDataSourceSchema) => ({ schema }),
resyncSchema: (schema: ExternalDataSourceSchema) => ({ schema }),
@@ -134,6 +135,13 @@ export const schemaSceneLogic = kea<schemaSceneLogicType>([
refreshSchemas: () => true,
},
],
+ resyncingSchema: [
+ false as boolean,
+ {
+ resyncSchema: () => true,
+ setResyncingSchema: (_, { resyncing }) => resyncing,
+ },
+ ],
})),
selectors({
schema: [(s) => [s.schemaData], (schemaData): ExternalDataSourceSchema | null => schemaData],
@@ -224,9 +232,11 @@ export const schemaSceneLogic = kea<schemaSceneLogicType>([
try {
await api.externalDataSchemas.resync(schema.id)
posthog.capture('schema resynced', { sourceType: values.source?.source_type })
+ lemonToast.success(`Resync started for ${schema.label ?? schema.name}`)
} catch (e: any) {
- lemonToast.error(e?.message || 'Cant refresh schema at this time')
+ lemonToast.error(e?.message || "Couldn't start resync")
} finally {
+ actions.setResyncingSchema(false)
actions.loadSchema()
}
},