: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(notebooks): show sql charts by default (#113375)
Marius Andra9e6961dbb032
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 251432b8ff55..9d498d708c3a 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -12339,13 +12339,13 @@ snapshots:scenes-app-notebooks-generated-widgets--before-generation--light:hash: v1.k794b7964.f8eabbbe270e16f6db6253fac4ccc1298d6486f4fcc54d086f39b494e32276bb.byEVF2WvcVULWZ_b-qJMNkCK-hCMqS-EcQNFNyVUVd4scenes-app-notebooks-jupyter-mode--jupyter-mode--dark:- hash: v1.k794b7964.500d117a0845274239aaa147328be81e3b0969bd705e01a3bedf50a4b8449c0c.D1_RR7QodTEFdIymNWjodMuaFsIt_ANlAxbuslyrg7I+ hash: v1.k794b7964.b1b5795dd47e91aa9dde3efaecbf05c9dccefb9b62633c384d18625c7e8b7c53.CxjZTRuVEQ4Y8OjVARnLCxcz0UThrY8iLmEpSYrR8cMscenes-app-notebooks-jupyter-mode--jupyter-mode--light:- hash: v1.k794b7964.698e10eb9014ff662d9bff482eaa1e1f44db22b52430fb09058c8bd9d0fe431f.x1lo_sE5tB-eB6Tt1kv_LSPvUZ_rCXBeRfabQddJcQo+ hash: v1.k794b7964.cf76ee4914da9e36af37dfb32ceb7b2b2ea280e3aef926b2e916e95034c5255b.ym9yp28m4aMZJQY00RJPonAeixJ8Tg47EFuqeYRSdkMscenes-app-notebooks-jupyter-mode--jupyter-mode-off--dark:- hash: v1.k794b7964.6cfc999e14196674801a7a60a292d1afd9a122f9313e63a17c0e6246e00e8c60.nVIT1vEFe7RZqLqVQTxDTK_27vDj0PbwcoeRtMsbDhY+ hash: v1.k794b7964.a49ed133530106e5ac09e61c7b81f637d27bf874290732535ac8470df2272675.rj99mNBmRl8s1d9SjTkuSG7U41uBhcVkEmcZDA-1EvEscenes-app-notebooks-jupyter-mode--jupyter-mode-off--light:- hash: v1.k794b7964.7b1a7d1b2149310b80166e459b1969806c27877659a4561a956dd7bcb0578cf8.RRG-nEHGqDJRNh3ocUan1QYnVeHSgv2Jh8d_UBm3_Ok+ hash: v1.k794b7964.0e9f1961a3321cfad65b7389a8a8a84b89a02f814e88a9f84099f420a5fb72ab.IN_uRp_18l9sAsi36onpxwM-ZZZyXgq2CBwWNivCp_8scenes-app-notebooks-kernel-info--free-compute--dark:hash: v1.k794b7964.e8e81cc18d66dcca3d1cd23cc5017833b040abcaa4a3be85c6161787fed0efcd.OiaNuBz69zbpOxiLQsFYOQuJn_226577RmjJ_GbOdyQscenes-app-notebooks-kernel-info--free-compute--light:diff --git a/frontend/src/scenes/notebooks/Nodes/NotebookNodeSQLV2.tsx b/frontend/src/scenes/notebooks/Nodes/NotebookNodeSQLV2.tsxindex 0afb85c50af7..82d0787dc95b 100644--- a/frontend/src/scenes/notebooks/Nodes/NotebookNodeSQLV2.tsx+++ b/frontend/src/scenes/notebooks/Nodes/NotebookNodeSQLV2.tsx@@ -10,6 +10,7 @@ import { OutputTab } from 'scenes/data-warehouse/editor/outputPaneLogic'import { createPostHogWidgetNode } from 'scenes/notebooks/Nodes/NodeWrapper'import type { NotebookNodeRunTerminalStatus } from 'scenes/notebooks/Notebook/notebookNodeStalenessLogic'+import { applyVisualizationType, columnsFromResponse } from '~/queries/nodes/DataVisualization/dataVisualizationLogic'import { Query } from '~/queries/Query/Query'import { DataVisualizationNode, HogQLQueryResponse, NodeKind } from '~/queries/schema/schema-general'import { ChartDisplayType } from '~/types'@@ -216,14 +217,14 @@ const Component = ({? pageResult.has_more: (result?.has_more ?? (result?.first_page ?? []).length >= SQL_V2_DEFAULT_PAGE_SIZE)const cachedResults = useMemo(() => (result ? toCachedResults(result) : null), [result])- const activeTab = attributes.outputTab === OutputTab.Visualization ? OutputTab.Visualization : OutputTab.Results+ const activeTab = attributes.outputTab === OutputTab.Results ? OutputTab.Results : OutputTab.Visualization// The stored viz config wins, but the source always tracks the node's current code — and the// connection it runs on, so anything the viz layer re-queries lands on the same engine.- const vizQuery = useMemo(- (): DataVisualizationNode => ({+ const vizQuery = useMemo((): DataVisualizationNode => {+ const query: DataVisualizationNode = {kind: NodeKind.DataVisualizationNode,- display: ChartDisplayType.ActionsLineGraph,+ display: ChartDisplayType.Auto,...attributes.vizQuery,source: {kind: NodeKind.HogQLQuery,@@ -231,9 +232,17 @@ const Component = ({connectionId: attributes.connectionId ?? undefined,sendRawQuery: attributes.connectionId ? !!attributes.sendRawQuery || undefined : undefined,},- }),- [attributes.vizQuery, attributes.code, attributes.connectionId, attributes.sendRawQuery]- )+ }+ if (cachedResults) {+ query.chartSettings = applyVisualizationType(+ query,+ query.display ?? ChartDisplayType.Auto,+ columnsFromResponse(cachedResults),+ cachedResults.results.length+ ).chartSettings+ }+ return query+ }, [attributes.vizQuery, attributes.code, attributes.connectionId, attributes.sendRawQuery, cachedResults])// Grow a still-too-short node to fit the result each run lands, so output is readable without// a manual resize. Sized to the rows that came back — a scalar stays compact, a wide result@@ -522,7 +531,7 @@ export const NotebookNodeSQLV2 = createPostHogWidgetNode<NotebookNodeSQLV2Attribdefault: null,},outputTab: {- default: OutputTab.Results,+ default: OutputTab.Visualization,},vizQuery: {default: null,diff --git a/frontend/src/scenes/notebooks/Notebook/NotebookJupyterMode.stories.tsx b/frontend/src/scenes/notebooks/Notebook/NotebookJupyterMode.stories.tsxindex ae883afb3434..d0bfd07caff4 100644--- a/frontend/src/scenes/notebooks/Notebook/NotebookJupyterMode.stories.tsx+++ b/frontend/src/scenes/notebooks/Notebook/NotebookJupyterMode.stories.tsx@@ -1,5 +1,5 @@import { Meta, StoryObj } from '@storybook/react'-import { waitFor } from '@testing-library/dom'+import { fireEvent, waitFor, within } from '@testing-library/dom'import { FEATURE_FLAGS } from 'lib/constants'import { App } from 'scenes/App'@@ -142,5 +142,28 @@ export const JupyterMode: Story = {;[CELLS.load, CELLS.count, CELLS.frame, CELLS.error, CELLS.sql].forEach((nodeId, index) =>logic?.actions.assignExecutionCount(nodeId, index + 1))++ const canvas = within(canvasElement)+ await waitFor(() => {+ if (!canvasElement.querySelector('.DataVisualization')) {+ throw new Error('SQL chart has not rendered by default')+ }+ canvas.getByText('Pageview')+ canvas.getByText('Autocapture')+ })+ fireEvent.click(canvas.getByRole('button', { name: 'Show table' }))+ await waitFor(() => {+ canvas.getByRole('button', { name: 'Show chart' })+ canvas.getByRole('cell', { name: '$pageview' })+ if (canvasElement.querySelector('.DataVisualization')) {+ throw new Error('SQL chart is still visible after switching to the table')+ }+ })+ fireEvent.click(canvas.getByRole('button', { name: 'Show chart' }))+ await waitFor(() => {+ canvas.getByRole('button', { name: 'Show table' })+ canvas.getByText('Pageview')+ canvas.getByText('Autocapture')+ })},}