: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-modeling): zoom to lineage search matches (#102908)
Jovan Sakovic0ae241b88b41
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex e49de55a0a38..650f3ced455e 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -5817,9 +5817,9 @@ snapshots:products-data-modeling-lineage-graph--full--light:hash: v1.k794b7964.5dad2ad87a0457c985581810013a0fa058bb4bb8f0596932bb829bfb46a2e18c.p9m_GryZwVUwkGgah-EvQZUyu1-1-I3sN8Tlu3kSYM4products-data-modeling-lineage-graph--search-focus--dark:- hash: v1.k794b7964.4fb56362fec2b7af59c737389abdfc6e01b3971b08fcc4c2bbc706e2c55fcd91.8jHcM2nb1Otah1aJRj4AgXagv9q_uhbn6yRFNMWBTgo+ hash: v1.k794b7964.83557b90965eed58b573e33d1a1ecb02472e478bd44052a8bf700762e2fe999e.nfjZIFH3OJCiGVyevJLYvQqPTsMKbHNYAGNiBfgqyeEproducts-data-modeling-lineage-graph--search-focus--light:- hash: v1.k794b7964.482002621af8d75dbee2f842b6bb21b814b5494f52dfbeb83db882b4f51ae22f.qEI8JmfvdHP4tQWt0USqKRQxlfoArtQY0PqnQE9Vxvw+ hash: v1.k794b7964.995c9c098971ab98f9f32c46e6a57b1b0e7630e093dad764a0bf68257944a7ee.Mi221xUsgkZxFcp3XfVyNrKo25mtsN8px73JtiB92hYproducts-data-modeling-lineage-graph--single-node--dark:hash: v1.k794b7964.4344045fc1bada8b4f2067de9f83cdb38b5dbe14719e7b4d332c2a7689a5d8cd.NvfJs1mb9VLArjiQdsrspse5hcopmjfyz4HXvwD_MZAproducts-data-modeling-lineage-graph--single-node--light:diff --git a/frontend/src/scenes/models/tabs/ModelsLineageTab.tsx b/frontend/src/scenes/models/tabs/ModelsLineageTab.tsxindex f4a7d79d6db8..f4b0ffd225fa 100644--- a/frontend/src/scenes/models/tabs/ModelsLineageTab.tsx+++ b/frontend/src/scenes/models/tabs/ModelsLineageTab.tsx@@ -1,5 +1,6 @@import { useActions, useValues } from 'kea'import { router } from 'kea-router'+import { useMemo } from 'react'import { IconInfo } from '@posthog/icons'import { LemonButton, LemonInput, Tooltip } from '@posthog/lemon-ui'@@ -30,12 +31,19 @@ export function ModelsLineageTab(): JSX.Element {searchTerm,typeFilter,legendCollapsed,+ parsedSearch,highlightedNodeIds,visibleNodes,visibleEdges,isFiltered,} = useValues(modelsLineageLogic)const { setSearchTerm, setTypeFilter, toggleLegendCollapsed, resetFilters } = useActions(modelsLineageLogic)+ // A fresh Set on every render would restart the graph's fitView animation each keystroke,+ // so keep the identity stable while the underlying selectors are unchanged.+ const focusNodeIds = useMemo(+ () => (parsedSearch.mode === 'search' ? highlightedNodeIds : new Set(visibleNodes.map((node) => node.id))),+ [parsedSearch.mode, highlightedNodeIds, visibleNodes]+ )return (<div className="flex flex-col gap-2">@@ -80,7 +88,7 @@ export function ModelsLineageTab(): JSX.Element {<LineageGraphnodes={visibleNodes}edges={visibleEdges}- focusNodeIds={highlightedNodeIds}+ focusNodeIds={focusNodeIds}variant="canvas"interactiveshowControlsdiff --git a/products/data_modeling/frontend/lineage/LineageGraph.tsx b/products/data_modeling/frontend/lineage/LineageGraph.tsxindex db9204c24f90..262c5b59b1d6 100644--- a/products/data_modeling/frontend/lineage/LineageGraph.tsx+++ b/products/data_modeling/frontend/lineage/LineageGraph.tsx@@ -69,12 +69,19 @@ function LineageGraphContent(props: LineageGraphProps): JSX.Element {)useEffect(() => {- if (!viewportInitialized || !focusNodeIds?.size || !layout) {+ if (!viewportInitialized || !focusNodeIds || !layout) {return}- const nodes = layout.nodes.filter((node) => focusNodeIds.has(node.id))+ // Keep the match readable when a search term identifies one or a few nodes. When the+ // search is cleared, fit the whole graph again instead of leaving the viewport stranded.+ const nodes = focusNodeIds.size > 0 ? layout.nodes.filter((node) => focusNodeIds.has(node.id)) : layout.nodesif (nodes.length > 0) {- void fitView({ nodes, padding: 0.2, maxZoom: 1 })+ void fitView({+ nodes,+ padding: 0.2,+ duration: 400,+ maxZoom: focusNodeIds.size > 0 ? 2 : undefined,+ })}}, [fitView, viewportInitialized, focusNodeIds, layout])