: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(data-warehouse): guide destination users to batch exports (#120405)
Tom Owers6127659ff482
diff --git a/products/data_warehouse/frontend/scenes/WarehouseDestinationsScene/WarehouseDestinationsScene.tsx b/products/data_warehouse/frontend/scenes/WarehouseDestinationsScene/WarehouseDestinationsScene.tsxindex 5761b036e345..f89eba2f66ad 100644--- a/products/data_warehouse/frontend/scenes/WarehouseDestinationsScene/WarehouseDestinationsScene.tsx+++ b/products/data_warehouse/frontend/scenes/WarehouseDestinationsScene/WarehouseDestinationsScene.tsx@@ -14,6 +14,8 @@ import { urls } from 'scenes/urls'import { SceneContent } from '~/layout/scenes/components/SceneContent'import { SceneTitleSection } from '~/layout/scenes/components/SceneTitleSection'+import { ExternalDataDestinationApi } from 'products/warehouse_sources/frontend/generated/api.schemas'+import { DestinationModal } from '../../shared/components/DestinationModal'import { destinationModalLogic } from '../../shared/logics/destinationModalLogic'import { warehouseDestinationsSceneLogic } from './warehouseDestinationsSceneLogic'@@ -28,10 +30,16 @@ export const scene: SceneExport = {export function WarehouseDestinationsScene(): JSX.Element {const { featureFlags } = useValues(featureFlagLogic)- const { destinations, destinationsLoading, loadError, deletingId } = useValues(warehouseDestinationsSceneLogic)- const { loadDestinations, deleteDestination } = useActions(warehouseDestinationsSceneLogic)+ const { destinations, destinationsLoading, loadError, deletingId, hasSources } = useValues(+ warehouseDestinationsSceneLogic+ )+ const { loadDestinations, deleteDestination, destinationCreated } = useActions(warehouseDestinationsSceneLogic)- const modalProps = { modalKey: MODAL_KEY, onSaved: () => loadDestinations() }+ const modalProps = {+ modalKey: MODAL_KEY,+ onSaved: () => loadDestinations(),+ onCreated: (destination: ExternalDataDestinationApi) => destinationCreated(destination),+ }const { openForCreate, openForEdit } = useActions(destinationModalLogic(modalProps))const todayRailNav = useFeatureFlag('TODAY_RAIL_NAV')@@ -55,7 +63,7 @@ export function WarehouseDestinationsScene(): JSX.Element {<SceneContent><SceneTitleSectionname="Warehouse destinations"- description="Destinations are where your warehouse sources write the rows they sync. Pick which ones a source or a single table uses from that source's Destinations tab."+ description="Destinations are where your warehouse sources write the rows they sync. Pick which ones a source or a single table uses from that source's Destinations tab. To export PostHog events to a warehouse, use a batch export."resourceType={{ type: 'data_warehouse' }}actions={todayRailNav ? (@@ -69,6 +77,35 @@ export function WarehouseDestinationsScene(): JSX.Element {}/>+ {hasSources === false && (+ <LemonBanner type="info">+ <div className="flex flex-col gap-2">+ <span>+ Destinations receive data synced from warehouse sources, such as Stripe or Postgres. They do+ not receive your PostHog events. To send events to a warehouse, set up a batch export.+ </span>+ <div className="flex flex-wrap gap-2">+ <LemonButton+ type="secondary"+ size="small"+ to={urls.destinations('batch')}+ data-attr="warehouse-destinations-no-sources-batch-exports"+ >+ Set up a batch export+ </LemonButton>+ <LemonButton+ type="secondary"+ size="small"+ to={urls.dataWarehouseSourceNew()}+ data-attr="warehouse-destinations-no-sources-add-source"+ >+ Add a warehouse source+ </LemonButton>+ </div>+ </div>+ </LemonBanner>+ )}+{loadError ? (<LemonBannertype="error"diff --git a/products/data_warehouse/frontend/scenes/WarehouseDestinationsScene/warehouseDestinationsSceneLogic.ts b/products/data_warehouse/frontend/scenes/WarehouseDestinationsScene/warehouseDestinationsSceneLogic.tsindex 1e0558b22a75..a6299c5c5aba 100644--- a/products/data_warehouse/frontend/scenes/WarehouseDestinationsScene/warehouseDestinationsSceneLogic.ts+++ b/products/data_warehouse/frontend/scenes/WarehouseDestinationsScene/warehouseDestinationsSceneLogic.ts@@ -1,13 +1,16 @@import { MakeLogicType, actions, afterMount, connect, kea, listeners, path, reducers } from 'kea'import { loaders } from 'kea-loaders'+import { router } from 'kea-router'import { LemonDialog } from 'lib/lemon-ui/LemonDialog'import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'import { teamLogic } from 'scenes/teamLogic'+import { urls } from 'scenes/urls'import {externalDataDestinationsDestroy,externalDataDestinationsList,+ externalDataSourcesList,} from 'products/warehouse_sources/frontend/generated/api'import { ExternalDataDestinationApi } from 'products/warehouse_sources/frontend/generated/api.schemas'@@ -17,6 +20,8 @@ export interface warehouseDestinationsSceneLogicValues {deletingId: string | nulldestinations: ExternalDataDestinationApi[] | nulldestinationsLoading: boolean+ hasSources: boolean | null+ hasSourcesLoading: booleanloadError: string | null}@@ -28,6 +33,9 @@ export interface warehouseDestinationsSceneLogicActions {deleteDestination: (destination: ExternalDataDestinationApi) => {destination: ExternalDataDestinationApi}+ destinationCreated: (destination: ExternalDataDestinationApi) => {+ destination: ExternalDataDestinationApi+ }loadDestinations: () => anyloadDestinationsFailure: (error: string,@@ -43,6 +51,21 @@ export interface warehouseDestinationsSceneLogicActions {destinations: ExternalDataDestinationApi[]payload?: any}+ loadHasSources: () => any+ loadHasSourcesFailure: (+ error: string,+ errorObject?: any+ ) => {+ error: string+ errorObject?: any+ }+ loadHasSourcesSuccess: (+ hasSources: boolean,+ payload?: any+ ) => {+ hasSources: boolean+ payload?: any+ }}export type warehouseDestinationsSceneLogicType = MakeLogicType<@@ -65,6 +88,7 @@ export const warehouseDestinationsSceneLogic = kea<warehouseDestinationsSceneLogactions({deleteDestination: (destination: ExternalDataDestinationApi) => ({ destination }),confirmDelete: (destination: ExternalDataDestinationApi) => ({ destination }),+ destinationCreated: (destination: ExternalDataDestinationApi) => ({ destination }),}),loaders(({ values }) => ({destinations: [@@ -78,6 +102,16 @@ export const warehouseDestinationsSceneLogic = kea<warehouseDestinationsSceneLog},},],+ hasSources: [+ // Null until loaded, so the page does not show "no sources" guidance while the check runs.+ null as boolean | null,+ {+ loadHasSources: async () => {+ const response = await externalDataSourcesList(String(values.currentTeamId), { limit: 1 })+ return (response.results ?? []).length > 0+ },+ },+ ],})),reducers({loadError: [@@ -110,6 +144,17 @@ export const warehouseDestinationsSceneLogic = kea<warehouseDestinationsSceneLogsecondaryButton: { children: 'Cancel' },})},+ destinationCreated: () => {+ // A destination receives nothing until a source turns it on, so the toast points at that step.+ const hasSources = values.hasSources !== false+ lemonToast.success('Destination added. Turn it on for a source to start sending data to it.', {+ button: {+ label: hasSources ? 'Go to sources' : 'Add a source',+ action: () => router.actions.push(hasSources ? urls.sources() : urls.dataWarehouseSourceNew()),+ dataAttr: 'warehouse-destinations-created-next-step',+ },+ })+ },confirmDelete: async ({ destination }) => {try {await externalDataDestinationsDestroy(String(values.currentTeamId), destination.id)@@ -124,5 +169,6 @@ export const warehouseDestinationsSceneLogic = kea<warehouseDestinationsSceneLog})),afterMount(({ actions }) => {actions.loadDestinations()+ actions.loadHasSources()}),])diff --git a/products/data_warehouse/frontend/shared/logics/destinationModalLogic.test.ts b/products/data_warehouse/frontend/shared/logics/destinationModalLogic.test.tsindex 35b318e8b559..b2e464c6361e 100644--- a/products/data_warehouse/frontend/shared/logics/destinationModalLogic.test.ts+++ b/products/data_warehouse/frontend/shared/logics/destinationModalLogic.test.ts@@ -1,9 +1,29 @@import { expectLogic } from 'kea-test-utils'+import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'+import { initKeaTests } from '~/test/init'+import { ExternalDataDestinationApi } from 'products/warehouse_sources/frontend/generated/api.schemas'+import { destinationModalLogic } from './destinationModalLogic'+jest.mock('products/warehouse_sources/frontend/generated/api', () => ({+ externalDataDestinationsCreate: jest.fn(),+ externalDataDestinationsDestroy: jest.fn(),+ externalDataDestinationsPartialUpdate: jest.fn(),+}))++const wsApi = jest.requireMock('products/warehouse_sources/frontend/generated/api')++const SAVED = {+ id: 'dest-1',+ name: 'Warehouse copy',+ type: 'Postgres',+ integration: 1,+ config: {},+} as ExternalDataDestinationApi+describe('destinationModalLogic', () => {let logic: ReturnType<typeof destinationModalLogic.build>@@ -81,4 +101,48 @@ describe('destinationModalLogic', () => {expect(logic.values.isDestinationFormValid).toBe(true)})++ it.each([+ { mode: 'create', withOnCreated: true, expectedToast: null, onCreatedCalls: 1 },+ { mode: 'create', withOnCreated: false, expectedToast: 'Destination added', onCreatedCalls: 0 },+ { mode: 'edit', withOnCreated: true, expectedToast: 'Destination updated', onCreatedCalls: 0 },+ ])(+ 'picks the toast and callbacks on $mode (onCreated passed: $withOnCreated)',+ async ({ mode, withOnCreated, expectedToast, onCreatedCalls }) => {+ // The page that passes onCreated shows its own next-step toast, so the generic one must not stack on it.+ wsApi.externalDataDestinationsCreate.mockResolvedValue(SAVED)+ wsApi.externalDataDestinationsPartialUpdate.mockResolvedValue(SAVED)+ const toastSpy = jest.spyOn(lemonToast, 'success')+ const onSaved = jest.fn()+ const onCreated = jest.fn()+ const saveLogic = destinationModalLogic({+ modalKey: `save-${mode}-${withOnCreated}`,+ onSaved,+ onCreated: withOnCreated ? onCreated : undefined,+ })+ saveLogic.mount()++ if (mode === 'create') {+ await expectLogic(saveLogic, () => saveLogic.actions.openForCreate()).toFinishAllListeners()+ } else {+ await expectLogic(saveLogic, () => saveLogic.actions.openForEdit(SAVED)).toFinishAllListeners()+ }+ await expectLogic(saveLogic, () =>+ saveLogic.actions.submitDestinationFormRequest({+ ...saveLogic.values.destinationForm,+ name: 'Warehouse copy',+ })+ ).toFinishAllListeners()++ expect(onSaved).toHaveBeenCalledWith(SAVED)+ expect(onCreated).toHaveBeenCalledTimes(onCreatedCalls)+ if (expectedToast) {+ expect(toastSpy).toHaveBeenCalledWith(expectedToast)+ } else {+ expect(toastSpy).not.toHaveBeenCalled()+ }+ toastSpy.mockRestore()+ saveLogic.unmount()+ }+ )})diff --git a/products/data_warehouse/frontend/shared/logics/destinationModalLogic.ts b/products/data_warehouse/frontend/shared/logics/destinationModalLogic.tsindex 05aec849c322..77805b7206db 100644--- a/products/data_warehouse/frontend/shared/logics/destinationModalLogic.ts+++ b/products/data_warehouse/frontend/shared/logics/destinationModalLogic.ts@@ -31,6 +31,8 @@ export interface DestinationModalLogicProps {/** Distinguishes the source-level modal from the schema-level one so they keep separate form state. */modalKey: stringonSaved: (destination: ExternalDataDestinationApi) => void+ /** Called for a new destination in place of the generic success toast, so the caller can show its own next step. */+ onCreated?: (destination: ExternalDataDestinationApi) => void/** Called after a destination is deleted, so the caller can drop it from its list. */onDeleted?: (destinationId: string) => void}@@ -261,7 +263,13 @@ export const destinationModalLogic = kea<destinationModalLogicType>([? await externalDataDestinationsPartialUpdate(teamId, values.editing.id, payload): await externalDataDestinationsCreate(teamId, payload)- lemonToast.success(values.editing ? 'Destination updated' : 'Destination added')+ if (values.editing) {+ lemonToast.success('Destination updated')+ } else if (props.onCreated) {+ props.onCreated(saved)+ } else {+ lemonToast.success('Destination added')+ }actions.closeModal()props.onSaved(saved)},