: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): show the warehouse as a run's destination (#111759)
Tom Owersc89ee8610db2
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 36cda1f2199f..8cf358405d85 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -2780,10 +2780,6 @@ snapshots:hash: v1.k794b7964.7850b437d0b757b20409473a16858b9ef875f35021e592521bdf94b2876e85c5.ix5aXJkl2sMIrSYeEmiT_OgH7Eb94qxUEEAt_DvutJkdata-warehouse-jobdestinations--destination-since-deleted--light:hash: v1.k794b7964.1006a4fb83ff9f0134af7e919f30ca873aac4f04b8dfd068eb631717a884d43d.tkCjdAFZpkv34Y6e9vv--B5P7ZPcYHIGZJl6wb26oVc- data-warehouse-jobdestinations--none-recorded--dark:- hash: v1.k794b7964.dea76b53ba18d6bfe40ecb75b1a64fab690266a082624956d99f67a6e0b6ebf8.HDCVy9kwOdoEb5dCIc-6oAUhUJvUKTAjmtL4eVgm3_g- data-warehouse-jobdestinations--none-recorded--light:- hash: v1.k794b7964.08667ab1c9265093c965360b142e49375d4d501fb118aee7685c52400615a6f1.Cm1L_qMrAlW3V_unPXRb8OAryI5Fbw0cbxhxRQBrYSAdata-warehouse-jobdestinations--still-loading--dark:hash: v1.k794b7964.dea76b53ba18d6bfe40ecb75b1a64fab690266a082624956d99f67a6e0b6ebf8.xA22JNcrso3fgiZdWGiwIW94beEQN4ka7hHIwybKxSodata-warehouse-jobdestinations--still-loading--light:@@ -2792,6 +2788,14 @@ snapshots:hash: v1.k794b7964.0a813176ca0b1322fde4f0dc75b7b61e4b0a662caada85f5e13fb29aeeba79a6.BKy4UyuXgDzGGeKZUr630fJLrXSLelURHWq_2t1G3mUdata-warehouse-jobdestinations--two-destinations--light:hash: v1.k794b7964.a59e6d22b31f379e6bbc6dc24d274293efc93df82f73d8c736df90af608f7e74.d1Gued6xNLNHXAJVTNJSBifeJY_VuoKvBjHVWDBe9aY+ data-warehouse-jobdestinations--warehouse-by-default--dark:+ hash: v1.k794b7964.d399de8f69dbd7b97698c047c094b96d9fd6e01656b231b2cf8180c04485cb03.GHMhPYe7iTCJvcb9ch2q9dWIjbGf3j4a1gefUaj18p8+ data-warehouse-jobdestinations--warehouse-by-default--light:+ hash: v1.k794b7964.b5ce51491fcae6e2e4658221c1f8c48a34fe6d0582c90740d3e035606c6e3d6c.RbwnkiTWUN9DSosvSqSA-wtK-bpocNFjPVqzqEcF3AI+ data-warehouse-jobdestinations--warehouse-by-default-with-no-lookup--dark:+ hash: v1.k794b7964.d399de8f69dbd7b97698c047c094b96d9fd6e01656b231b2cf8180c04485cb03.Z4uYciDvlPUvY0A52ffHU0zYzsJ2qcklAfjQHb_UULg+ data-warehouse-jobdestinations--warehouse-by-default-with-no-lookup--light:+ hash: v1.k794b7964.b5ce51491fcae6e2e4658221c1f8c48a34fe6d0582c90740d3e035606c6e3d6c.twtDobN8gDPg0GH-Nnta-8nUCc2EAJ6gSq2z9PgPmT8data-warehouse-jobdestinations--warehouse-only--dark:hash: v1.k794b7964.d399de8f69dbd7b97698c047c094b96d9fd6e01656b231b2cf8180c04485cb03.t3DT8wXet-xFzPBD7EFBpn2_d3IoptfOQSMokIXtp_odata-warehouse-jobdestinations--warehouse-only--light:diff --git a/products/data_warehouse/frontend/shared/components/JobDestinations.stories.tsx b/products/data_warehouse/frontend/shared/components/JobDestinations.stories.tsxindex da4cbebebeb4..8a7e4dbd3531 100644--- a/products/data_warehouse/frontend/shared/components/JobDestinations.stories.tsx+++ b/products/data_warehouse/frontend/shared/components/JobDestinations.stories.tsx@@ -45,13 +45,20 @@ WarehouseOnly.args = {destinationsById: BY_ID,}-// A run from before destinations existed recorded none, so there is nothing to show.-export const NoneRecorded = Template.bind({})-NoneRecorded.args = {+// A run that recorded no ids wrote to the PostHog warehouse alone, so it shows as the warehouse.+export const WarehouseByDefault = Template.bind({})+WarehouseByDefault.args = {destinationIds: [],destinationsById: BY_ID,}+// The same run on a project that has never configured a destination, so there is no row to look up.+export const WarehouseByDefaultWithNoLookup = Template.bind({})+WarehouseByDefaultWithNoLookup.args = {+ destinationIds: [],+ destinationsById: {},+}+// Deleting a destination leaves the runs that used it pointing at nothing.export const DestinationSinceDeleted = Template.bind({})DestinationSinceDeleted.args = {diff --git a/products/data_warehouse/frontend/shared/components/JobDestinations.test.tsx b/products/data_warehouse/frontend/shared/components/JobDestinations.test.tsxnew file mode 100644index 000000000000..6f65289acf86--- /dev/null+++ b/products/data_warehouse/frontend/shared/components/JobDestinations.test.tsx@@ -0,0 +1,62 @@+import '@testing-library/jest-dom'++import { cleanup, render, screen } from '@testing-library/react'++import { ExternalDataDestinationApi } from 'products/warehouse_sources/frontend/generated/api.schemas'++import { JobDestinations } from './JobDestinations'++const WAREHOUSE = {+ id: '01a03e9c-1b76-0000-9079-2a0ee2186dea',+ type: 'PostHogWarehouse',+ name: 'PostHog warehouse',+ config: {},+ integration: null,+ is_posthog_warehouse: true,+} as ExternalDataDestinationApi++const POSTGRES = {+ id: '01a03e9c-1b7c-0000-71ce-5e5d7b04df8f',+ type: 'Postgres',+ name: 'Customer Postgres',+ config: { database: 'analytics', schema: 'customer_sync' },+ integration: 1,+ is_posthog_warehouse: false,+} as ExternalDataDestinationApi++const BY_ID = { [WAREHOUSE.id]: WAREHOUSE, [POSTGRES.id]: POSTGRES }++describe('JobDestinations', () => {+ afterEach(cleanup)++ // The backend snapshots no ids for a run that wrote to the warehouse alone, which is every+ // run on a source nobody has pointed elsewhere. Showing a dash there reads as "went nowhere".+ it.each<[string, Record<string, ExternalDataDestinationApi>]>([+ ['the project has a warehouse row', BY_ID],+ ['the project has never configured a destination', {}],+ ])('shows the warehouse for a run that recorded no destinations when %s', (_, destinationsById) => {+ render(<JobDestinations destinationIds={[]} destinationsById={destinationsById} />)++ expect(screen.getByAltText('PostHog warehouse')).toBeInTheDocument()+ expect(screen.queryByText('—')).not.toBeInTheDocument()+ })++ it('shows a logo for each destination a run recorded', () => {+ render(<JobDestinations destinationIds={[WAREHOUSE.id, POSTGRES.id]} destinationsById={BY_ID} />)++ expect(screen.getByAltText('PostHog warehouse')).toBeInTheDocument()+ expect(screen.getByAltText('Postgres')).toBeInTheDocument()+ })++ it('stays quiet while the destination lookup is still loading', () => {+ render(<JobDestinations destinationIds={[POSTGRES.id]} destinationsById={{}} loading />)++ expect(screen.getByText('—')).toBeInTheDocument()+ })++ it('says how many destinations a run used once they have been deleted', () => {+ render(<JobDestinations destinationIds={['01a03e9c-0000-0000-0000-000000000000']} destinationsById={BY_ID} />)++ expect(screen.getByText('1 removed')).toBeInTheDocument()+ })+})diff --git a/products/data_warehouse/frontend/shared/components/JobDestinations.tsx b/products/data_warehouse/frontend/shared/components/JobDestinations.tsxindex b1eacbfb2502..38d09dc69b42 100644--- a/products/data_warehouse/frontend/shared/components/JobDestinations.tsx+++ b/products/data_warehouse/frontend/shared/components/JobDestinations.tsx@@ -6,7 +6,7 @@ import { DESTINATION_ICON_MAP, destinationTypeLabel } from './DestinationIcon'import { destinationTarget } from './destinationTarget'export interface JobDestinationsProps {- /** Snapshotted on the run when it started. Empty on runs that predate destinations. */+ /** Snapshotted on the run when it started. Empty on a run that wrote to the warehouse alone. */destinationIds: readonly string[]/** Every destination the project has, so ids can be named. Absent until the lookup mounts. */destinationsById?: Record<string, ExternalDataDestinationApi>@@ -14,6 +14,12 @@ export interface JobDestinationsProps {loading?: boolean}+interface Logo {+ key: string+ type: ExternalDataDestinationApi['type']+ title: string+}+function tooltipFor(destination: ExternalDataDestinationApi): string {const target = destinationTarget(destination)return target ? `${destination.name} — ${target}` : destination.name@@ -21,15 +27,9 @@ function tooltipFor(destination: ExternalDataDestinationApi): string {/** Where one run delivered, as a logo each. */export function JobDestinations({ destinationIds, destinationsById = {}, loading }: JobDestinationsProps): JSX.Element {- // A run from before destinations existed wrote to the warehouse and recorded nothing, so it- // has nothing to show rather than nothing to say.- if (destinationIds.length === 0) {- return <span className="text-muted">—</span>- }-const known = destinationIds.map((id) => destinationsById[id]).filter(Boolean)- if (known.length === 0) {+ if (destinationIds.length > 0 && known.length === 0) {// A table renders rows before the lookup logic has mounted, so an id that is not in the// map yet is not the same as one that will never be there.return loading || Object.keys(destinationsById).length === 0 ? (@@ -42,14 +42,27 @@ export function JobDestinations({ destinationIds, destinationsById = {}, loading)}+ // A run records no ids when it wrote to the PostHog warehouse alone: that is what every run+ // did before destinations existed, and what the backend still snapshots for a table nobody+ // has pointed elsewhere. Read from the type rather than a looked-up row, because a project+ // that has never configured a destination has no warehouse row to look up.+ const logos: Logo[] =+ destinationIds.length === 0+ ? [{ key: 'posthog-warehouse', type: 'PostHogWarehouse', title: 'PostHog warehouse' }]+ : known.map((destination) => ({+ key: destination.id,+ type: destination.type,+ title: tooltipFor(destination),+ }))+return (<div className="flex items-center gap-1">- {known.map((destination) => (- <Tooltip key={destination.id} title={tooltipFor(destination)}>+ {logos.map(({ key, type, title }) => (+ <Tooltip key={key} title={title}><span className="flex items-center justify-center size-5"><img- src={DESTINATION_ICON_MAP[destination.type]}- alt={destinationTypeLabel(destination.type)}+ src={DESTINATION_ICON_MAP[type]}+ alt={destinationTypeLabel(type)}className="max-w-full max-h-full"/></span>