: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): link DAGs to their filtered data ops graph (#73597)
Jovan Sakovic0b0aef93a944
diff --git a/frontend/src/products.tsx b/frontend/src/products.tsxindex 9aee7a2972c9..da5b362bacda 100644--- a/frontend/src/products.tsx+++ b/frontend/src/products.tsx@@ -975,7 +975,17 @@ export const productUrls = {dashboardSubscription: (id: string | number, subscriptionId: string): string =>`/dashboard/${id}/subscriptions/${subscriptionId}`,sharedDashboard: (shareToken: string): string => `/shared_dashboard/${shareToken}`,- dataOps: (tab?: string): string => (tab ? `/data-ops?tab=${tab}` : '/data-ops'),+ dataOps: (tab?: string, dagId?: string): string => {+ const params = new URLSearchParams()+ if (tab) {+ params.set('tab', tab)+ }+ if (dagId) {+ params.set('dag', dagId)+ }+ const query = params.toString()+ return query ? `/data-ops?${query}` : '/data-ops'+ },models: (tab?: ModelsSceneTab): string => `/models${tab ? `/${tab}` : ''}`,nodeDetail: (id: string): string => `/models/${id}`,sources: (): string => '/data-management/sources',diff --git a/frontend/src/scenes/data-warehouse/scene/dataModelingLogic.test.ts b/frontend/src/scenes/data-warehouse/scene/dataModelingLogic.test.tsnew file mode 100644index 000000000000..3282a9ed31cb--- /dev/null+++ b/frontend/src/scenes/data-warehouse/scene/dataModelingLogic.test.ts@@ -0,0 +1,75 @@+import { router } from 'kea-router'+import { expectLogic } from 'kea-test-utils'++import api from 'lib/api'+import { urls } from 'scenes/urls'++import { useMocks } from '~/mocks/jest'+import { initKeaTests } from '~/test/init'++import { dataModelingLogic } from './dataModelingLogic'++describe('dataModelingLogic', () => {+ let logic: ReturnType<typeof dataModelingLogic.build>++ beforeEach(() => {+ localStorage.clear()+ useMocks({+ get: {+ '/api/environments/:team_id/data_modeling_dags/': {+ results: [+ {+ id: 'dag-123',+ name: 'Test DAG',+ description: '',+ sync_frequency: '24hour',+ node_count: 0,+ created_at: '2024-01-01T00:00:00Z',+ updated_at: '2024-01-01T00:00:00Z',+ },+ ],+ },+ '/api/environments/:team_id/data_modeling_nodes/': { results: [] },+ '/api/environments/:team_id/data_modeling_edges/': { results: [] },+ '/api/environments/:team_id/data_modeling_jobs/recent/': [],+ '/api/environments/:team_id/data_modeling_jobs/running/': [],+ },+ })+ initKeaTests()+ })++ afterEach(() => {+ logic?.unmount()+ })++ // The Models scene's DagsTab links here with ?dag=<id> to open a specific DAG's graph — a+ // regression here would silently send that link to the wrong (or persisted) DAG instead.+ it('selects the DAG from a ?dag= URL param and filters node/edge loads by it', async () => {+ const nodesSpy = jest.spyOn(api.dataModelingNodes, 'list')+ const edgesSpy = jest.spyOn(api.dataModelingEdges, 'list')++ router.actions.push(urls.dataOps('modeling', 'dag-123'))+ logic = dataModelingLogic()+ logic.mount()++ expect(logic.values.selectedDagId).toBe('dag-123')+ await expectLogic(logic).toDispatchActions(['loadDataModelingNodesSuccess', 'loadDataModelingEdgesSuccess'])++ expect(nodesSpy).toHaveBeenCalledWith('dag-123')+ expect(edgesSpy).toHaveBeenCalledWith('dag-123')+ })++ it('keeps the persisted DAG selection when the URL has no ?dag= param', () => {+ router.actions.push(urls.dataOps('modeling', 'dag-123'))+ logic = dataModelingLogic()+ logic.mount()+ expect(logic.values.selectedDagId).toBe('dag-123')+ logic.unmount()++ router.actions.push(urls.dataOps('modeling'))+ logic = dataModelingLogic()+ logic.mount()++ expect(logic.values.selectedDagId).toBe('dag-123')+ })+})diff --git a/frontend/src/scenes/data-warehouse/scene/dataModelingLogic.ts b/frontend/src/scenes/data-warehouse/scene/dataModelingLogic.tsindex 85e1a627d0ee..cdcacab74a84 100644--- a/frontend/src/scenes/data-warehouse/scene/dataModelingLogic.ts+++ b/frontend/src/scenes/data-warehouse/scene/dataModelingLogic.ts@@ -11,9 +11,11 @@ import {import { deepEqual as equal } from 'fast-equals'import { MakeLogicType, actions, afterMount, beforeUnmount, kea, listeners, path, reducers, selectors } from 'kea'import { loaders } from 'kea-loaders'+import { urlToAction } from 'kea-router'import type { RefObject } from 'react'import api from 'lib/api'+import { urls } from 'scenes/urls'import {DataModelingDAG,@@ -1086,6 +1088,13 @@ export const dataModelingLogic = kea<dataModelingLogicType>([actions.loadDataModelingEdges()},})),+ urlToAction(({ actions, values }) => ({+ [urls.dataOps()]: (_, searchParams) => {+ if (typeof searchParams.dag === 'string' && searchParams.dag !== values.selectedDagId) {+ actions.setSelectedDagId(searchParams.dag)+ }+ },+ })),afterMount(({ actions }) => {actions.loadDags()actions.loadDataModelingNodes()diff --git a/frontend/src/scenes/models/DagsTab.tsx b/frontend/src/scenes/models/DagsTab.tsxindex 96efe24136a2..3f7b1e492554 100644--- a/frontend/src/scenes/models/DagsTab.tsx+++ b/frontend/src/scenes/models/DagsTab.tsx@@ -11,9 +11,13 @@ import {Tooltip,} from '@posthog/lemon-ui'+import { FEATURE_FLAGS } from 'lib/constants'import { More } from 'lib/lemon-ui/LemonButton/More'import { LemonField } from 'lib/lemon-ui/LemonField'+import { LemonTableLink } from 'lib/lemon-ui/LemonTable/LemonTableLink'+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'import { pluralize } from 'lib/utils/strings'+import { urls } from 'scenes/urls'import { DataModelingDAG, DataModelingSyncInterval } from '~/types'@@ -24,6 +28,9 @@ const DEFAULT_DAG_NAME = 'Default'export function DagsTab(): JSX.Element {const { dags, dagsLoading } = useValues(dagsLogic)const { loadDags, updateDag, deleteDag } = useActions(dagsLogic)+ const { featureFlags } = useValues(featureFlagLogic)+ const dataOpsModelingEnabled =+ !!featureFlags[FEATURE_FLAGS.DATA_MODELING_TAB] && !!featureFlags[FEATURE_FLAGS.DATA_WAREHOUSE_SCENE]useEffect(() => {loadDags()@@ -33,12 +40,19 @@ export function DagsTab(): JSX.Element {{title: 'Name',key: 'name',- render: (_, dag) => (- <div className="flex flex-col">- <span className="font-semibold">{dag.name}</span>- {dag.description && <span className="text-muted text-xs">{dag.description}</span>}- </div>- ),+ render: (_, dag) =>+ dataOpsModelingEnabled ? (+ <LemonTableLink+ to={urls.dataOps('modeling', dag.id)}+ title={dag.name}+ description={dag.description || 'View this DAG in data ops'}+ />+ ) : (+ <div className="flex flex-col">+ <span className="font-semibold">{dag.name}</span>+ {dag.description && <span className="text-muted text-xs">{dag.description}</span>}+ </div>+ ),},{title: 'Models',diff --git a/products/data_warehouse/manifest.tsx b/products/data_warehouse/manifest.tsxindex e1ef4774c959..7f22fffdd10b 100644--- a/products/data_warehouse/manifest.tsx+++ b/products/data_warehouse/manifest.tsx@@ -96,7 +96,17 @@ export const manifest: ProductManifest = {'/data-warehouse/sources/:id/:tab': ({ id, tab }) => urls.dataWarehouseSource(id, tab as SourceSceneTab),},urls: {- dataOps: (tab?: string): string => (tab ? `/data-ops?tab=${tab}` : '/data-ops'),+ dataOps: (tab?: string, dagId?: string): string => {+ const params = new URLSearchParams()+ if (tab) {+ params.set('tab', tab)+ }+ if (dagId) {+ params.set('dag', dagId)+ }+ const query = params.toString()+ return query ? `/data-ops?${query}` : '/data-ops'+ },models: (tab?: ModelsSceneTab): string => `/models${tab ? `/${tab}` : ''}`,nodeDetail: (id: string): string => `/models/${id}`,sources: (): string => '/data-management/sources',