: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
fix(data-warehouse): flag already-connected sources in the catalog (#105994)
Tom Owersccf5624d5418
diff --git a/products/data_warehouse/frontend/scenes/NewSourceScene/SourceCatalog.tsx b/products/data_warehouse/frontend/scenes/NewSourceScene/SourceCatalog.tsxindex b5715544b9b3..62872f1133a1 100644--- a/products/data_warehouse/frontend/scenes/NewSourceScene/SourceCatalog.tsx+++ b/products/data_warehouse/frontend/scenes/NewSourceScene/SourceCatalog.tsx@@ -65,6 +65,11 @@ const SourceTile = memo(function SourceTile({</>) : (<div className="flex flex-wrap items-center gap-1">+ {item.existingSource && (+ <Tooltip title="You already have a source of this type. Connecting another one needs a table name prefix so its tables don't clash.">+ <LemonTag type="completion">Already connected</LemonTag>+ </Tooltip>+ )}{item.selfManaged && (<Tooltip title="Self-managed: your files stay in your own bucket and PostHog queries them there. The managed version copies the data into PostHog on a schedule."><LemonTag type="muted">Self-managed</LemonTag>diff --git a/products/data_warehouse/frontend/scenes/NewSourceScene/sourceCatalogLogic.ts b/products/data_warehouse/frontend/scenes/NewSourceScene/sourceCatalogLogic.tsindex 8a8991e156dd..cd9ff96a8222 100644--- a/products/data_warehouse/frontend/scenes/NewSourceScene/sourceCatalogLogic.ts+++ b/products/data_warehouse/frontend/scenes/NewSourceScene/sourceCatalogLogic.ts@@ -1,5 +1,5 @@import FuseClass from 'fuse.js'-import { MakeLogicType, actions, connect, kea, listeners, path, props, reducers, selectors } from 'kea'+import { MakeLogicType, actions, afterMount, connect, kea, listeners, path, props, reducers, selectors } from 'kea'import posthog from 'posthog-js'import { lemonToast } from '@posthog/lemon-ui'@@ -20,8 +20,10 @@ import {SourceConfigResponseApi,} from 'products/warehouse_sources/frontend/generated/api.schemas'+import type { PaginatedResponse } from '../../../../../frontend/src/lib/api'import type { FeatureFlagsSet } from '../../../../../frontend/src/lib/logic/featureFlagLogic'-import type { ManualLinkSourceType, UserType } from '../../../../../frontend/src/types'+import type { ExternalDataSource, ManualLinkSourceType, UserType } from '../../../../../frontend/src/types'+import { sourcesDataLogic } from '../../shared/logics/sourcesDataLogic'import { availableSourcesLogic } from './availableSourcesLogic'import {FILE_UPLOAD_FORMATS,@@ -114,6 +116,7 @@ export interface sourceCatalogLogicValues {name: stringtype: ManualLinkSourceType}[] // sourceWizardLogic+ dataWarehouseSources: PaginatedResponse<ExternalDataSource> | null // sourcesDataLogicuser: UserType | null // userLogiccatalogFuse: FusecatalogItems: CatalogItem[]@@ -128,6 +131,9 @@ export interface sourceCatalogLogicValues {// Generated by kea-typegen. Update if you're an agent, ignore if you're human.export interface sourceCatalogLogicActions {+ loadSources: () => {+ value: true+ } // sourcesDataLogichideSourceRequest: () => {value: true}@@ -164,6 +170,7 @@ export interface sourceCatalogLogicMeta {type: ManualLinkSourceType}[],featureFlags: FeatureFlagsSet,+ dataWarehouseSources: PaginatedResponse<ExternalDataSource> | null,arg: ExternalDataSourceTypeEnumApi[] | undefined) => CatalogItem[]categoriesWithCounts: (catalogItems: CatalogItem[]) => CatalogCategory[]@@ -225,7 +232,12 @@ export const sourceCatalogLogic = kea<sourceCatalogLogicType>([['featureFlags'],userLogic,['user'],+ // Which source types the project already has, so a tile can say so before the user+ // works through OAuth and table selection for a connection that then needs a prefix.+ sourcesDataLogic,+ ['dataWarehouseSources'],],+ actions: [sourcesDataLogic, ['loadSources']],})),actions({setSearch: (search: string) => ({ search }),@@ -267,6 +279,7 @@ export const sourceCatalogLogic = kea<sourceCatalogLogicType>([s.availableSources,s.manualConnectors,s.featureFlags,+ s.dataWarehouseSources,(_, p: SourceCatalogLogicProps) => p.allowedSources,],(@@ -276,8 +289,14 @@ export const sourceCatalogLogic = kea<sourceCatalogLogicType>([type: import('~/types').ManualLinkSourceType}[],featureFlags: import('lib/logic/featureFlagLogic').FeatureFlagsSet,+ dataWarehouseSources: PaginatedResponse<ExternalDataSource> | null,allowedSources: ExternalDataSourceTypeEnumApi[] | undefined): CatalogItem[] => {+ // SourceConfigResponseApi declares `existingSource`, but the /wizard payload this+ // selector reads never populates it, so derive it from the project's source list.+ const connectedTypes = new Set(+ (dataWarehouseSources?.results ?? []).map((source: ExternalDataSource) => source.source_type)+ )const managed = Object.values(availableSources ?? {}).filter((c) => !allowedSources || allowedSources.includes(c.name)).flatMap((connector: SourceConfigResponseApi): CatalogItem[] => {@@ -302,7 +321,7 @@ export const sourceCatalogLogic = kea<sourceCatalogLogicType>([status,releaseStatus,disabledReason: connector.disabledReason,- existingSource: connector.existingSource ?? undefined,+ existingSource: connectedTypes.has(connector.name) || undefined,name: connector.name,label: connector.label ?? connector.name,keywords: connector.keywords ?? [],@@ -487,4 +506,11 @@ export const sourceCatalogLogic = kea<sourceCatalogLogicType>([lemonToast.success('Thanks! Your source request has been submitted.')},})),+ afterMount(({ actions, values }) => {+ // The catalog can be opened without passing the sources list first (a deep link, or the+ // pipeline new-source page), and nothing else on those pages loads it.+ if (values.dataWarehouseSources === null) {+ actions.loadSources()+ }+ }),])diff --git a/products/data_warehouse/frontend/scenes/NewSourceScene/tests/sourceCatalogLogic.test.ts b/products/data_warehouse/frontend/scenes/NewSourceScene/tests/sourceCatalogLogic.test.tsindex 006e20bf9c5a..de2101735313 100644--- a/products/data_warehouse/frontend/scenes/NewSourceScene/tests/sourceCatalogLogic.test.ts+++ b/products/data_warehouse/frontend/scenes/NewSourceScene/tests/sourceCatalogLogic.test.ts@@ -1,11 +1,14 @@+import { PaginatedResponse } from 'lib/api'import { FEATURE_FLAGS } from 'lib/constants'import { featureFlagLogic } from 'lib/logic/featureFlagLogic'import { useMocks } from '~/mocks/jest'import { initKeaTests } from '~/test/init'+import { ExternalDataSource } from '~/types'import type { SourceConfigResponseApi } from 'products/warehouse_sources/frontend/generated/api.schemas'+import { sourcesDataLogic } from '../../../shared/logics/sourcesDataLogic'import { availableSourcesLogic } from '../availableSourcesLogic'import { sourceCatalogLogic } from '../sourceCatalogLogic'@@ -42,6 +45,13 @@ const AVAILABLE_SOURCES: Record<string, SourceConfigResponseApi> = {} as unknown as SourceConfigResponseApi,}+const CONNECTED_SOURCES = {+ results: [{ id: 'abc', source_type: 'Stripe' }],+ count: 1,+ next: null,+ previous: null,+} as unknown as PaginatedResponse<ExternalDataSource>+describe('sourceCatalogLogic', () => {let unmountAvailableSources: () => voidlet unmountLogic: () => void@@ -50,6 +60,7 @@ describe('sourceCatalogLogic', () => {useMocks({get: {'/api/environments/:team_id/external_data_sources/wizard/': AVAILABLE_SOURCES,+ '/api/environments/:team_id/external_data_sources/': CONNECTED_SOURCES,},})initKeaTests()@@ -210,6 +221,17 @@ describe('sourceCatalogLogic', () => {})+ it('flags the source types the project already has', () => {+ const logic = sourceCatalogLogic()+ sourcesDataLogic.actions.loadSourcesSuccess(CONNECTED_SOURCES)++ // Stripe is already connected, so its tile has to say so before the user works through+ // the whole flow only to be told a table prefix is needed.+ const byName = Object.fromEntries(logic.values.catalogItems.map((item) => [item.name, item]))+ expect(byName.Stripe.existingSource).toBe(true)+ expect(byName.Mango.existingSource).toBeUndefined()+ })+it('leaves the incoming webhook source out of a catalog restricted to warehouse sources', () => {const logic = sourceCatalogLogic({ allowedSources: ['Stripe'] })const unmountRestricted = logic.mount()