: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): add a connect page for warehouse destinations (#122828)
Daniel RC468e4a26b9f7
diff --git a/frontend/bin/build-app-url-manifest.mjs b/frontend/bin/build-app-url-manifest.mjsindex b99e94a8eb0f..a535c7b4d702 100644--- a/frontend/bin/build-app-url-manifest.mjs+++ b/frontend/bin/build-app-url-manifest.mjs@@ -60,9 +60,9 @@ const EXCLUDED_HELPERS = new Set(['absolute', 'default', 'project', 'currentProj// Builders whose destination lives in the query string, which the probe drops. Most base-only// entries are still fine (`/surveys` without its `tab` is a real page), but these resolve to a page// that does not show what the builder names, so an entry would be a confident wrong link:-// `tracingOperation` renders its missing-parameter error, and `dashboardTemplates` opens the-// dashboard list without its templates modal.-const EXCLUDED_BUILDERS = new Set(['tracingOperation', 'dashboardTemplates'])+// `tracingOperation` and `warehouseDestinationConnect` render their missing-parameter error, and+// `dashboardTemplates` opens the dashboard list without its templates modal.+const EXCLUDED_BUILDERS = new Set(['tracingOperation', 'dashboardTemplates', 'warehouseDestinationConnect'])// Dropping these builders' fixed query strings opens a different destination.const BUILDERS_WITH_REQUIRED_QUERY = new Set(['aiObservabilityDatasets'])// Flag-gated surfaces for PostHog staff only: a link an agent hands a customer would land on a scene that refuses them.diff --git a/frontend/src/productScenes.tsx b/frontend/src/productScenes.tsxindex 104396720761..4ed8a6e49d02 100644--- a/frontend/src/productScenes.tsx+++ b/frontend/src/productScenes.tsx@@ -100,6 +100,8 @@ export const productScenes: Record<string, () => Promise<any>> = {DataWarehouseSourceSchema: () => import('../../products/data_warehouse/frontend/scenes/SchemaScene/SchemaScene'),WarehouseDestinations: () =>import('../../products/data_warehouse/frontend/scenes/WarehouseDestinationsScene/WarehouseDestinationsScene'),+ WarehouseDestinationConnect: () =>+ import('../../products/data_warehouse/frontend/scenes/DestinationConnectScene/DestinationConnectScene'),EarlyAccessFeatures: () => import('../../products/early_access_features/frontend/EarlyAccessFeatures'),EarlyAccessFeature: () => import('../../products/early_access_features/frontend/EarlyAccessFeature'),EndpointsScene: () => import('../../products/endpoints/frontend/EndpointsScene'),diff --git a/frontend/src/products.tsx b/frontend/src/products.tsxindex 1eac64193f2e..55b9bf93802c 100644--- a/frontend/src/products.tsx+++ b/frontend/src/products.tsx@@ -179,6 +179,7 @@ export const productRoutes: Record<string, [string, string]> = {'/data-management/sources/:id/:tab': ['DataWarehouseSource', 'dataWarehouseSource'],'/data-warehouse/new-source': ['DataWarehouseSourceNew', 'dataWarehouseSourceNew'],'/data-warehouse/connect': ['DataWarehouseSourceConnect', 'dataWarehouseSourceConnect'],+ '/data-warehouse/connect-destination': ['WarehouseDestinationConnect', 'warehouseDestinationConnect'],'/early_access_features': ['EarlyAccessFeatures', 'earlyAccessFeatures'],'/early_access_features/:id': ['EarlyAccessFeature', 'earlyAccessFeature'],'/endpoints': ['EndpointsScene', 'endpoints'],@@ -918,6 +919,7 @@ export const productConfiguration: Record<string, any> = {description: 'Manage where your warehouse sources write the rows they sync.',iconType: 'data_warehouse',},+ WarehouseDestinationConnect: { projectBased: true, name: 'Connect warehouse destination' },EarlyAccessFeatures: {name: 'Early access features',projectBased: true,@@ -1595,6 +1597,8 @@ export const productUrls = {`/data-management/warehouse-destinations?destination=${encodeURIComponent(id)}`,dataWarehouseSourceConnect: (kind?: string): string =>`/data-warehouse/connect${kind ? `?kind=${encodeURIComponent(kind)}` : ''}`,+ warehouseDestinationConnect: (kind?: string): string =>+ `/data-warehouse/connect-destination${kind ? `?kind=${encodeURIComponent(kind)}` : ''}`,earlyAccessFeatures: (): string => '/early_access_features',earlyAccessFeature: (id: string): string => `/early_access_features/${id}`,endpoints: (): string => '/endpoints',@@ -2662,6 +2666,7 @@ export const getTreeItemsProducts = (): FileSystemImport[] => ['DataWarehouseSourceConnect','DataWarehouseSourceSchema','WarehouseDestinations',+ 'WarehouseDestinationConnect',],},{@@ -3552,6 +3557,7 @@ export const getTreeItemsMetadata = (): FileSystemImport[] => ['DataWarehouseSourceConnect','DataWarehouseSourceSchema','WarehouseDestinations',+ 'WarehouseDestinationConnect',],},{@@ -3661,7 +3667,7 @@ export const getTreeItemsMetadata = (): FileSystemImport[] => [href: urls.warehouseDestinations(),flag: FEATURE_FLAGS.WAREHOUSE_MULTI_DESTINATION,sceneKey: 'WarehouseDestinations',- sceneKeys: ['WarehouseDestinations'],+ sceneKeys: ['WarehouseDestinations', 'WarehouseDestinationConnect'],},{path: 'Warehouse properties',diff --git a/frontend/src/scenes/sceneTypes.ts b/frontend/src/scenes/sceneTypes.tsindex 90ca58708fbf..f03ceb7ca4fa 100644--- a/frontend/src/scenes/sceneTypes.ts+++ b/frontend/src/scenes/sceneTypes.ts@@ -209,6 +209,7 @@ export enum Scene {VercelLinkError = 'VercelLinkError',VerifyEmail = 'VerifyEmail',WarehouseDestinations = 'WarehouseDestinations',+ WarehouseDestinationConnect = 'WarehouseDestinationConnect',WarehouseProperties = 'WarehouseProperties',WebAnalytics = 'WebAnalytics',WebAnalyticsPageReports = 'WebAnalyticsPageReports',diff --git a/products/data_warehouse/frontend/scenes/DestinationConnectScene/DestinationConnectScene.tsx b/products/data_warehouse/frontend/scenes/DestinationConnectScene/DestinationConnectScene.tsxnew file mode 100644index 000000000000..97cf8933ec0d--- /dev/null+++ b/products/data_warehouse/frontend/scenes/DestinationConnectScene/DestinationConnectScene.tsx@@ -0,0 +1,94 @@+import { useActions, useValues } from 'kea'++import { LemonButton } from '@posthog/lemon-ui'++import 'lib/components/CyclotronJob/integrations/integrationSetups'+import { getIntegrationSetup } from 'lib/components/CyclotronJob/integrations/integrationSetupRegistry'+import { NotFound } from 'lib/components/NotFound'+import { FEATURE_FLAGS } from 'lib/constants'+import { LemonBanner } from 'lib/lemon-ui/LemonBanner'+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'+import { SceneExport } from 'scenes/sceneTypes'+import { urls } from 'scenes/urls'++import { SceneContent } from '~/layout/scenes/components/SceneContent'+import { SceneTitleSection } from '~/layout/scenes/components/SceneTitleSection'++import { destinationTypeLabel } from '../../shared/components/DestinationIcon'+import { destinationConnectSceneLogic } from './destinationConnectSceneLogic'++export const scene: SceneExport = {+ component: DestinationConnectScene,+ logic: destinationConnectSceneLogic,+}++export function DestinationConnectScene(): JSX.Element {+ const { featureFlags } = useValues(featureFlagLogic)+ const { kind, destinationDefinition, isModalOpen, integrationId } = useValues(destinationConnectSceneLogic)+ const { setModalOpen, setIntegrationId } = useActions(destinationConnectSceneLogic)++ if (!featureFlags[FEATURE_FLAGS.WAREHOUSE_MULTI_DESTINATION]) {+ return <NotFound object="page" caption="Warehouse destinations isn't available for this project yet." />+ }++ const SetupModal = kind ? getIntegrationSetup(kind)?.SetupModal : undefined+ if (!kind || !destinationDefinition || !SetupModal) {+ return (+ <SceneContent>+ <LemonBanner+ type="error"+ action={{ children: 'Open warehouse destinations', to: urls.warehouseDestinations() }}+ >+ {kind+ ? "This link names a connection we don't support."+ : "This link doesn't say which connection to set up."}{' '}+ Add the destination from warehouse destinations instead.+ </LemonBanner>+ </SceneContent>+ )+ }++ const typeLabel = destinationTypeLabel(destinationDefinition.type)++ return (+ <SceneContent>+ <SceneTitleSection+ name={`Connect ${typeLabel} destination`}+ resourceType={{ type: 'data_warehouse' }}+ description={+ integrationId === null+ ? `Enter your ${typeLabel} credentials. PostHog stores them encrypted and never shares them with anyone, including the assistant that sent you here.`+ : undefined+ }+ />+ <div className="max-w-200">+ {integrationId !== null ? (+ <LemonBanner type="success">+ <p className="font-semibold mb-1">{typeLabel} connection saved</p>+ <p className="m-0 text-sm">+ Copy this connection id into your chat: <code>{integrationId}</code>. The assistant uses it+ to create the destination, which doesn't exist yet. Then you can close this tab.+ </p>+ </LemonBanner>+ ) : (+ !isModalOpen && (+ <LemonButton+ type="primary"+ onClick={() => setModalOpen(true)}+ data-attr="warehouse-destination-connect-open"+ >+ Enter credentials+ </LemonButton>+ )+ )}+ </div>+ <SetupModal+ isOpen={isModalOpen && integrationId === null}+ kind={kind}+ // The modals' close button calls onComplete with the click event, so only a number is a saved id.+ onComplete={(id) => (typeof id === 'number' ? setIntegrationId(id) : setModalOpen(false))}+ onClose={() => setModalOpen(false)}+ />+ </SceneContent>+ )+}diff --git a/products/data_warehouse/frontend/scenes/DestinationConnectScene/destinationConnectSceneLogic.test.ts b/products/data_warehouse/frontend/scenes/DestinationConnectScene/destinationConnectSceneLogic.test.tsnew file mode 100644index 000000000000..dc703464aebe--- /dev/null+++ b/products/data_warehouse/frontend/scenes/DestinationConnectScene/destinationConnectSceneLogic.test.ts@@ -0,0 +1,49 @@+import { router } from 'kea-router'+import posthog from 'posthog-js'++import { initKeaTests } from '~/test/init'++import { destinationConnectSceneLogic } from './destinationConnectSceneLogic'++describe('destinationConnectSceneLogic', () => {+ let unmountLogic: () => void++ beforeEach(() => {+ initKeaTests()+ jest.spyOn(posthog, 'capture')+ unmountLogic = destinationConnectSceneLogic.mount()+ })++ afterEach(() => {+ unmountLogic()+ jest.restoreAllMocks()+ })++ it.each([+ ['?kind=snowflake', 'Snowflake'],+ ['?kind=s3-compatible', 'S3'],+ ['?kind=twilio', null],+ ['', null],+ ])('resolves %s to destination type %s and tracks only a supported kind', (search, expectedType) => {+ router.actions.push(`/data-warehouse/connect-destination${search}`)++ expect(destinationConnectSceneLogic.values.destinationDefinition?.type ?? null).toEqual(expectedType)+ const viewed = (posthog.capture as jest.Mock).mock.calls.filter(+ ([event]) => event === 'warehouse destination connect page viewed'+ )+ expect(viewed).toHaveLength(expectedType ? 1 : 0)+ })++ it('keeps the saved connection when only the hash changes', () => {+ router.actions.push('/data-warehouse/connect-destination?kind=snowflake')+ destinationConnectSceneLogic.actions.setIntegrationId(42)++ router.actions.replace('/data-warehouse/connect-destination', { kind: 'snowflake' }, { panel: 'max' })++ expect(destinationConnectSceneLogic.values.integrationId).toEqual(42)+ const viewed = (posthog.capture as jest.Mock).mock.calls.filter(+ ([event]) => event === 'warehouse destination connect page viewed'+ )+ expect(viewed).toHaveLength(1)+ })+})diff --git a/products/data_warehouse/frontend/scenes/DestinationConnectScene/destinationConnectSceneLogic.ts b/products/data_warehouse/frontend/scenes/DestinationConnectScene/destinationConnectSceneLogic.tsnew file mode 100644index 000000000000..e46486977eb3--- /dev/null+++ b/products/data_warehouse/frontend/scenes/DestinationConnectScene/destinationConnectSceneLogic.ts@@ -0,0 +1,134 @@+import { MakeLogicType, actions, kea, listeners, path, reducers, selectors } from 'kea'+import { urlToAction } from 'kea-router'+import posthog from 'posthog-js'++import { Scene } from 'scenes/sceneTypes'+import { urls } from 'scenes/urls'++import { Breadcrumb, IntegrationKind } from '~/types'++import { destinationTypeLabel } from '../../shared/components/DestinationIcon'+import { WAREHOUSE_DESTINATIONS } from '../../shared/destinations/destinationDefinitions'+import type { WarehouseDestinationDefinition } from '../../shared/destinations/types'++// Generated by kea-typegen. Update if you're an agent, ignore if you're human.+export interface destinationConnectSceneLogicValues {+ breadcrumbs: Breadcrumb[]+ destinationDefinition: WarehouseDestinationDefinition | null+ integrationId: number | null+ isModalOpen: boolean+ kind: string | null+}++// Generated by kea-typegen. Update if you're an agent, ignore if you're human.+export interface destinationConnectSceneLogicActions {+ setIntegrationId: (integrationId: number) => {+ integrationId: number+ }+ setKind: (kind: string | null) => {+ kind: string | null+ }+ setModalOpen: (open: boolean) => {+ open: boolean+ }+}++// Generated by kea-typegen. Update if you're an agent, ignore if you're human.+export interface destinationConnectSceneLogicMeta {+ __keaTypeGenInternalSelectorTypes: {+ destinationDefinition: (kind: string | null) => WarehouseDestinationDefinition | null+ breadcrumbs: (destinationDefinition: WarehouseDestinationDefinition | null) => Breadcrumb[]+ }+}++export type destinationConnectSceneLogicType = MakeLogicType<+ destinationConnectSceneLogicValues,+ destinationConnectSceneLogicActions,+ Record<string, any>,+ destinationConnectSceneLogicMeta+>++export const destinationConnectSceneLogic = kea<destinationConnectSceneLogicType>([+ path(['products', 'dataWarehouse', 'destinationConnectSceneLogic']),+ actions({+ setKind: (kind: string | null) => ({ kind }),+ setModalOpen: (open: boolean) => ({ open }),+ setIntegrationId: (integrationId: number) => ({ integrationId }),+ }),+ reducers({+ kind: [+ null as string | null,+ {+ setKind: (_, { kind }) => kind,+ },+ ],+ isModalOpen: [+ true,+ {+ setKind: () => true,+ setModalOpen: (_, { open }) => open,+ },+ ],+ integrationId: [+ null as number | null,+ {+ setKind: () => null,+ setIntegrationId: (_, { integrationId }) => integrationId,+ },+ ],+ }),+ selectors({+ destinationDefinition: [+ (s) => [s.kind],+ (kind: string | null): WarehouseDestinationDefinition | null =>+ kind+ ? (Object.values(WAREHOUSE_DESTINATIONS).find((definition) =>+ definition.integrationKinds.includes(kind as IntegrationKind)+ ) ?? null)+ : null,+ ],+ breadcrumbs: [+ (s) => [s.destinationDefinition],+ (destinationDefinition: WarehouseDestinationDefinition | null): Breadcrumb[] => [+ {+ key: Scene.WarehouseDestinations,+ name: 'Warehouse destinations',+ path: urls.warehouseDestinations(),+ iconType: 'warehouse_destination',+ },+ {+ key: Scene.WarehouseDestinationConnect,+ name: destinationDefinition+ ? `Connect ${destinationTypeLabel(destinationDefinition.type)}`+ : 'Connect destination',+ iconType: 'warehouse_destination',+ },+ ],+ ],+ }),+ listeners(({ values }) => ({+ setKind: () => {+ if (values.destinationDefinition) {+ posthog.capture('warehouse destination connect page viewed', {+ integration_kind: values.kind,+ destination_type: values.destinationDefinition.type,+ })+ }+ },+ setIntegrationId: () => {+ posthog.capture('warehouse destination connection saved', {+ integration_kind: values.kind,+ destination_type: values.destinationDefinition?.type,+ })+ },+ })),+ urlToAction(({ actions, values }) => ({+ [urls.warehouseDestinationConnect()]: (_, searchParams) => {+ // A hash change (the side panel opening) runs this again, and a reset would hide the saved id.+ const kind = searchParams.kind ?? null+ if (kind !== values.kind) {+ actions.setKind(kind)+ }+ },+ })),+])diff --git a/products/data_warehouse/manifest.tsx b/products/data_warehouse/manifest.tsxindex 242ea7d1fdcd..f0e3eb4d13e6 100644--- a/products/data_warehouse/manifest.tsx+++ b/products/data_warehouse/manifest.tsx@@ -63,6 +63,11 @@ export const manifest: ProductManifest = {description: 'Manage where your warehouse sources write the rows they sync.',iconType: 'data_warehouse',},+ WarehouseDestinationConnect: {+ import: () => import('./frontend/scenes/DestinationConnectScene/DestinationConnectScene'),+ projectBased: true,+ name: 'Connect warehouse destination',+ },},routes: {'/data-ops': ['DataOps', 'dataOps'],@@ -83,6 +88,7 @@ export const manifest: ProductManifest = {'/data-management/sources/:id/:tab': ['DataWarehouseSource', 'dataWarehouseSource'],'/data-warehouse/new-source': ['DataWarehouseSourceNew', 'dataWarehouseSourceNew'],'/data-warehouse/connect': ['DataWarehouseSourceConnect', 'dataWarehouseSourceConnect'],+ '/data-warehouse/connect-destination': ['WarehouseDestinationConnect', 'warehouseDestinationConnect'],},redirects: {// Switching projects while in the new-source wizard truncates the URL to bare@@ -155,6 +161,8 @@ export const manifest: ProductManifest = {`/data-management/warehouse-destinations?destination=${encodeURIComponent(id)}`,dataWarehouseSourceConnect: (kind?: string): string =>`/data-warehouse/connect${kind ? `?kind=${encodeURIComponent(kind)}` : ''}`,+ warehouseDestinationConnect: (kind?: string): string =>+ `/data-warehouse/connect-destination${kind ? `?kind=${encodeURIComponent(kind)}` : ''}`,},treeItemsProducts: [{@@ -195,6 +203,7 @@ export const manifest: ProductManifest = {'DataWarehouseSourceConnect','DataWarehouseSourceSchema','WarehouseDestinations',+ 'WarehouseDestinationConnect',],},],@@ -228,7 +237,7 @@ export const manifest: ProductManifest = {href: urls.warehouseDestinations(),flag: FEATURE_FLAGS.WAREHOUSE_MULTI_DESTINATION,sceneKey: 'WarehouseDestinations',- sceneKeys: ['WarehouseDestinations'],+ sceneKeys: ['WarehouseDestinations', 'WarehouseDestinationConnect'],},{path: 'Managed viewsets',@@ -250,6 +259,7 @@ export const manifest: ProductManifest = {'DataWarehouseSourceConnect','DataWarehouseSourceSchema','WarehouseDestinations',+ 'WarehouseDestinationConnect',],},],