: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-catalog): manage warehouse joins from the relationships tab (#75081)
Thiago Salvatorec0b14ee26236
diff --git a/frontend/src/scenes/data-warehouse/viewLinkLogic.tsx b/frontend/src/scenes/data-warehouse/viewLinkLogic.tsxindex c18e1d606ca9..725cf0deb7f0 100644--- a/frontend/src/scenes/data-warehouse/viewLinkLogic.tsx+++ b/frontend/src/scenes/data-warehouse/viewLinkLogic.tsx@@ -672,8 +672,14 @@ export const viewLinkLogic = kea<viewLinkLogicType>([},],}),- subscriptions(({ actions }) => ({+ subscriptions(({ actions, values }) => ({isJoinTableModalOpen: (isOpen) => {+ if (isOpen && values.allTables.length === 0) {+ // Not every surface that opens this modal mounts a logic that loads the+ // database schema (the data catalog doesn't); without it the table and+ // key pickers render empty.+ actions.loadDatabase()+ }if (!isOpen) {actions.clearModalFields()actions.resetViewLink()diff --git a/products/data_catalog/frontend/relationshipsLogic.test.ts b/products/data_catalog/frontend/relationshipsLogic.test.tsindex c87adafc7b05..84d49ce2845f 100644--- a/products/data_catalog/frontend/relationshipsLogic.test.ts+++ b/products/data_catalog/frontend/relationshipsLogic.test.ts@@ -1,8 +1,11 @@import api from 'lib/api'import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'+import { deleteWithUndo } from 'lib/utils/deleteWithUndo'+import { viewLinkLogic } from 'scenes/data-warehouse/viewLinkLogic'import { initKeaTests } from '~/test/init'import { expectLogic } from '~/test/keaTestUtils'+import { DataWarehouseViewLink } from '~/types'import {dataCatalogRelationshipProposalsAcceptCreate,@@ -40,6 +43,10 @@ jest.mock('./generated/api', () => ({dataCatalogRelationshipProposalsRejectCreate: jest.fn(),}))+jest.mock('lib/utils/deleteWithUndo', () => ({+ deleteWithUndo: jest.fn().mockResolvedValue(undefined),+}))+function buildProposal(overrides: Partial<DataCatalogRelationshipProposalApi>): DataCatalogRelationshipProposalApi {return {id: 'proposal-1',@@ -124,8 +131,42 @@ describe('relationshipsLogic', () => {const manual = rows.find((row) => row.key === 'join-join-2')expect(manual?.viaCatalog).toEqual(false)expect(manual?.rowStatus).toEqual('active')+ expect(manual?.joinId).toEqual('join-2')++ const pending = rows.find((row) => row.proposalId === 'pending')+ expect(pending?.rowStatus).toEqual('pending')+ expect(pending?.joinId).toBeNull()+ })++ it('reloads joins when the shared join modal saves', async () => {+ await mountWith([], [])+ ;(api.dataWarehouseViewLinks.list as jest.Mock).mockClear()++ viewLinkLogic.build().actions.submitViewLinkSuccess({} as any)- expect(rows.find((row) => row.proposalId === 'pending')?.rowStatus).toEqual('pending')+ await expectLogic(logic).toDispatchActions(['loadJoins', 'loadJoinsSuccess'])+ expect(api.dataWarehouseViewLinks.list).toHaveBeenCalledTimes(1)+ })++ it('deletes a join against the singular view-link endpoint and reloads', async () => {+ await mountWith([], [{ id: 'join-1', source_table_name: 'events' }])++ logic.actions.deleteJoin({+ id: 'join-1',+ field_name: 'person',+ source_table_name: 'events',+ } as DataWarehouseViewLink)+ await expectLogic(logic).toFinishAllListeners()++ expect(deleteWithUndo).toHaveBeenCalledWith(+ expect.objectContaining({+ endpoint: 'environments/1/warehouse_view_link',+ object: expect.objectContaining({ id: 'join-1' }),+ })+ )+ ;(api.dataWarehouseViewLinks.list as jest.Mock).mockClear()+ ;(deleteWithUndo as jest.Mock).mock.calls[0][0].callback()+ await expectLogic(logic).toDispatchActions(['loadJoins', 'loadJoinsSuccess'])})it('passes the rejection reason through when rejecting', async () => {diff --git a/products/data_catalog/frontend/relationshipsLogic.tsx b/products/data_catalog/frontend/relationshipsLogic.tsxindex 9fbe1b84c0fa..9ec2660166b0 100644--- a/products/data_catalog/frontend/relationshipsLogic.tsx+++ b/products/data_catalog/frontend/relationshipsLogic.tsx@@ -4,6 +4,8 @@ import { urlToAction } from 'kea-router'import api, { ApiConfig, ApiError } from 'lib/api'import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'+import { deleteWithUndo } from 'lib/utils/deleteWithUndo'+import { viewLinkLogic } from 'scenes/data-warehouse/viewLinkLogic'import { urls } from 'scenes/urls'import { DataWarehouseViewLink } from '~/types'@@ -33,6 +35,7 @@ export interface RelationshipRow {reviewedBy: string | nullviaCatalog: booleanproposalId: string | null+ joinId: string | null}function projectId(): string {@@ -48,6 +51,7 @@ export interface relationshipsLogicValues {actionsInFlight: Record<string, boolean>filteredRows: RelationshipRow[]joins: DataWarehouseViewLink[]+ joinsById: Record<string, DataWarehouseViewLink>joinsLoading: booleanpendingCount: numberpendingCountLoading: boolean@@ -62,6 +66,9 @@ export interface relationshipsLogicActions {acceptProposal: (id: string) => {id: string}+ deleteJoin: (join: DataWarehouseViewLink) => {+ join: DataWarehouseViewLink+ }loadJoins: () => anyloadJoinsFailure: (error: string,@@ -131,6 +138,7 @@ export interface relationshipsLogicMeta {__keaTypeGenInternalSelectorTypes: {rows: (proposals: DataCatalogRelationshipProposalApi[], joins: DataWarehouseViewLink[]) => RelationshipRow[]filteredRows: (rows: RelationshipRow[], statusFilter: RelationshipStatusFilter) => RelationshipRow[]+ joinsById: (joins: DataWarehouseViewLink[]) => Record<string, DataWarehouseViewLink>}}@@ -148,6 +156,7 @@ export const relationshipsLogic = kea<relationshipsLogicType>([acceptProposal: (id: string) => ({ id }),rejectProposal: (id: string, rejectionReason: string) => ({ id, rejectionReason }),setActionInFlight: (id: string, inFlight: boolean) => ({ id, inFlight }),+ deleteJoin: (join: DataWarehouseViewLink) => ({ join }),}),loaders(() => ({// Badge count only — never pull the full proposal payloads (unbounded reasoning/evidence)@@ -206,8 +215,6 @@ export const relationshipsLogic = kea<relationshipsLogicType>([.filter((proposal) => proposal.status === 'accepted' && proposal.created_join).forEach((proposal) => acceptedByJoinId.set(proposal.created_join as string, proposal))- const joinIds = new Set(joins.map((join) => join.id))-const joinRows: RelationshipRow[] = joins.map((join) => {const proposal = acceptedByJoinId.get(join.id)return {@@ -225,17 +232,16 @@ export const relationshipsLogic = kea<relationshipsLogicType>([reviewedBy: proposal?.reviewed_by?.email ?? null,viaCatalog: !!proposal,proposalId: null,+ joinId: join.id,}})- // Accepted proposals whose created join isn't in the loaded joins (null, soft-deleted,- // or beyond the paginated response) would otherwise vanish — surface them as active rows.+ // An accepted proposal that never persisted a join would otherwise vanish — surface it+ // as an active row. A proposal whose created join is absent from the loaded joins was+ // deleted (soft delete drops it from the list), and the backend treats it as gone, so+ // it must not reappear as an uneditable active row.const orphanedAcceptedRows: RelationshipRow[] = proposals- .filter(- (proposal) =>- proposal.status === 'accepted' &&- !(proposal.created_join && joinIds.has(proposal.created_join))- )+ .filter((proposal) => proposal.status === 'accepted' && !proposal.created_join).map((proposal) => ({key: `proposal-${proposal.id}`,sourceTableName: proposal.source_table_name,@@ -251,6 +257,7 @@ export const relationshipsLogic = kea<relationshipsLogicType>([reviewedBy: proposal.reviewed_by?.email ?? null,viaCatalog: true,proposalId: proposal.id,+ joinId: null,}))const proposalRows: RelationshipRow[] = proposals@@ -270,6 +277,7 @@ export const relationshipsLogic = kea<relationshipsLogicType>([reviewedBy: proposal.reviewed_by?.email ?? null,viaCatalog: false,proposalId: proposal.id,+ joinId: null,}))return [...joinRows, ...orphanedAcceptedRows, ...proposalRows]@@ -280,6 +288,11 @@ export const relationshipsLogic = kea<relationshipsLogicType>([(rows: RelationshipRow[], statusFilter: RelationshipStatusFilter) =>statusFilter === 'all' ? rows : rows.filter((row) => row.rowStatus === statusFilter),],+ joinsById: [+ (s) => [s.joins],+ (joins: DataWarehouseViewLink[]): Record<string, DataWarehouseViewLink> =>+ Object.fromEntries(joins.map((join) => [join.id, join])),+ ],}),listeners(({ values, actions }) => ({acceptProposal: async ({ id }) => {@@ -317,6 +330,19 @@ export const relationshipsLogic = kea<relationshipsLogicType>([actions.setActionInFlight(id, false)}},+ deleteJoin: async ({ join }) => {+ await deleteWithUndo({+ endpoint: `environments/${projectId()}/warehouse_view_link`,+ object: { id: join.id, name: `${join.field_name} on ${join.source_table_name}` },+ callback: () => actions.loadJoins(),+ })+ },+ // Refresh after the shared join modal saves. Referencing actionTypes builds+ // viewLinkLogic without mounting it, so the catalog scene doesn't eagerly load+ // the database schema; the modal in RelationshipsTab mounts it when visible.+ [viewLinkLogic.actionTypes.submitViewLinkSuccess]: () => {+ actions.loadJoins()+ },})),urlToAction(({ actions }) => ({// Load the full proposals and joins only when the Relationships tab is actually viewed.diff --git a/products/data_catalog/frontend/tabs/RelationshipsTab.tsx b/products/data_catalog/frontend/tabs/RelationshipsTab.tsxindex 99d639e5ec61..2d0d391b2364 100644--- a/products/data_catalog/frontend/tabs/RelationshipsTab.tsx+++ b/products/data_catalog/frontend/tabs/RelationshipsTab.tsx@@ -1,15 +1,18 @@import { useActions, useValues } from 'kea'-import { IconRefresh } from '@posthog/icons'+import { IconPlus, IconRefresh } from '@posthog/icons'import { LemonButton, LemonDialog } from '@posthog/lemon-ui'import { CodeSnippet, Language } from 'lib/components/CodeSnippet/CodeSnippet'+import { More } from 'lib/lemon-ui/LemonButton/More'import { LemonField } from 'lib/lemon-ui/LemonField'import { LemonSegmentedButton } from 'lib/lemon-ui/LemonSegmentedButton'import { LemonTable, LemonTableColumns } from 'lib/lemon-ui/LemonTable'import { LemonTag } from 'lib/lemon-ui/LemonTag'import { LemonTextArea } from 'lib/lemon-ui/LemonTextArea'import { Tooltip } from 'lib/lemon-ui/Tooltip'+import { viewLinkLogic } from 'scenes/data-warehouse/viewLinkLogic'+import { ViewLinkModal } from 'scenes/data-warehouse/ViewLinkModal'import { RelationshipRow, RelationshipStatusFilter, relationshipsLogic } from '../relationshipsLogic'@@ -40,9 +43,11 @@ function TableRefCell({ table, refKey }: { table: string; refKey: string }): JSX}export function RelationshipsTab(): JSX.Element {- const { filteredRows, proposalsLoading, joinsLoading, statusFilter, actionsInFlight } =+ const { filteredRows, proposalsLoading, joinsLoading, statusFilter, actionsInFlight, joinsById } =useValues(relationshipsLogic)- const { setStatusFilter, acceptProposal, rejectProposal, loadProposals, loadJoins } = useActions(relationshipsLogic)+ const { setStatusFilter, acceptProposal, rejectProposal, loadProposals, loadJoins, deleteJoin } =+ useActions(relationshipsLogic)+ const { toggleNewJoinModal, toggleEditJoinModal } = useActions(viewLinkLogic)const confirmReject = (row: RelationshipRow): void => {if (!row.proposalId) {@@ -105,6 +110,23 @@ export function RelationshipsTab(): JSX.Element {key: 'actions',width: 0,render: (_, row) => {+ const join = row.joinId ? joinsById[row.joinId] : null+ if (row.rowStatus === 'active' && join) {+ return (+ <More+ overlay={+ <>+ <LemonButton fullWidth onClick={() => toggleEditJoinModal(join)}>+ Edit+ </LemonButton>+ <LemonButton status="danger" fullWidth onClick={() => deleteJoin(join)}>+ Delete+ </LemonButton>+ </>+ }+ />+ )+ }if (row.rowStatus !== 'pending' || !row.proposalId) {return null}@@ -143,18 +165,29 @@ export function RelationshipsTab(): JSX.Element {options={STATUS_FILTER_OPTIONS}size="small"/>- <LemonButton- type="secondary"- icon={<IconRefresh />}- size="small"- loading={proposalsLoading || joinsLoading}- onClick={() => {- loadProposals()- loadJoins()- }}- >- Reload- </LemonButton>+ <div className="flex gap-2">+ <LemonButton+ type="secondary"+ icon={<IconRefresh />}+ size="small"+ loading={proposalsLoading || joinsLoading}+ onClick={() => {+ loadProposals()+ loadJoins()+ }}+ >+ Reload+ </LemonButton>+ <LemonButton+ type="primary"+ icon={<IconPlus />}+ size="small"+ data-attr="data-catalog-new-join"+ onClick={() => toggleNewJoinModal()}+ >+ New join+ </LemonButton>+ </div></div><LemonTabledata-attr="data-catalog-relationships-table"@@ -170,6 +203,7 @@ export function RelationshipsTab(): JSX.Element {expandedRowRender: (row) => <RelationshipDetail row={row} />,}}/>+ <ViewLinkModal /></div>)}