: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(sql-editor): open sidebar insights in edit mode (#111187)
Marius Andra0d76deadfcf5
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 08ba17246fe0..7a0eb7a8aebd 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -4345,9 +4345,9 @@ snapshots:lemon-ui-icons1--shelf-a--light:hash: v1.k794b7964.5ac03ce003c333375b716362f03c7692bca611adffe6be6ef9be3b007e3b2595.YDFXw5WBfM-Nw2sTc3wVkST_yw3Ov7ZZshM8qFYuf-Mlemon-ui-icons1--shelf-b--dark:- hash: v1.k794b7964.c2c95a8a61bb792c13779dc5f22c1e121ad9ae7af8351b30a9ac17b81c291e86.uJxk1G4ss-OPMH5YoVtM8YhU64L_66iieFCsezOpyew+ hash: v1.k794b7964.c7547d871ddbf17a4f99d32c466878c8757d27cf0f22ec6bc8e43ef87c399182.L89ECBrJOTmw8Exi6IL6Hr8id1ix59nzKurtIQ7KHRwlemon-ui-icons1--shelf-b--light:- hash: v1.k794b7964.076c78450d15324c056a0d2797d9540f66d94674478877cb30f641e89960ba73.OVINaoLosPw8FuQQt8HVE9Vb05cIWy4eyYblTAFu3Q8+ hash: v1.k794b7964.8b727af713dae6ff6e31145bdc8366e139ee55c4d714edb1116a3dce8a76c320.RRDoV57noSzwfHYAdS7_PREQ_Vq_mj8htal3TSvLZ1Elemon-ui-icons1--shelf-c--dark:hash: v1.k794b7964.fa38008cc14dfc8829a27ae05a420e0330024a81d22e8cf6c0955c0cd720d06d.0v0ZiDwGLHBsy_I3t3yYKrc-3iWi75dosJJEVP3dldolemon-ui-icons1--shelf-c--light:@@ -4433,9 +4433,9 @@ snapshots:lemon-ui-icons3--shelf-other--light:hash: v1.k794b7964.aa74ffdb695068a942de5b22c9936a4991f16af4382ddaa12e31378b3585b170.u9RiB-521ppS_huOTennJrDeEqFgY9gofGVZjO7vLxAlemon-ui-icons3--shelf-s--dark:- hash: v1.k794b7964.f5b885205bda49d2d4a7dfb24119400a96fa3f31378e2cb1b2c73d195cb608b9.wHnrHZNvVM_8ARljkq6J3vnm_h8nDYwuGffMbIxYuGU+ hash: v1.k794b7964.a8b167acd639c7097fb4c5cbad40433c55c19bce4de3d18ae205b8d1accd043f.515ujTmHn5B--6TLxC2oyxfLkWHPaZypnbG7WtCeR5wlemon-ui-icons3--shelf-s--light:- hash: v1.k794b7964.7d0545daad48cf7bb7a4246f2a05bd433fdafd5aef3de28f13a69689fc8ebec7.VjUvGtR1SoJ5P-iDtmJByEh4GLU-gf31DAjzlhDTo4Q+ hash: v1.k794b7964.ce8ccf62e87ec19989aee4f65f42dacbeccd0b5a6383a1273764fe89170e718d.DEnYFVyuQfJTTQK0aXn4gDwlxFWzWSXIvlsOdD864UQlemon-ui-icons3--shelf-t--dark:hash: v1.k794b7964.5ff1657fdbe447ae9bdfcdd40492d1a9d888cd8100cdd235d06b427f0fdaf089.ti_aYMtJzaNpjmr0bYAdFT7_TQI7f-SnTh31trhz0pQlemon-ui-icons3--shelf-t--light:@@ -9487,9 +9487,9 @@ snapshots:scenes-app-data-warehouse-sql-editor--bi-quick-filters-narrow--light:hash: v1.k794b7964.46ca9e07669ba124d6d051b6b0cf1dbbf30b441533a9eaa064c3492577893e93.KhY5WMXImePUoV5bH-nrNztp1axD08hcOl4kfH-uaYQscenes-app-data-warehouse-sql-editor--edited-insight--dark:- hash: v1.k794b7964.94eba9d351ec4c6b649fc4b09f5d4a69fed2995448c0cc1dac5d63d3df0ad20c.U6hnpHxuk9RKFoPU8bc536a9dTuzluwHE0pF4J0nPYc+ hash: v1.k794b7964.334b216a8359c768613cdec5b99a8a8ee26b6b5fac76397eaed8d6d1401a23c0.0pI7NMTufzUIfDel9Ngmhv3P3sdBu6IgpSj5xYNmYrYscenes-app-data-warehouse-sql-editor--edited-insight--light:- hash: v1.k794b7964.436ab0db5bbe37772a43ac31f23e24089833a5b90524a01059ea0bd56004786c.ztvECim8t2GfzyU0YLjaBdofiHEvt_GJMLPUlzQq3sY+ hash: v1.k794b7964.b92f606e9a4e6fae85bfda61c881a0e357eb64ecffc42b7b0f585c1218a547be.26Nvvp7xA6ADbOxOz5l0KD37TYoyGSiGJ6XQgSn1GXEscenes-app-data-warehouse-sql-editor--edited-view--dark:hash: v1.k794b7964.57136a6dbeab9ac511a2a5e0c7401b23a4cb0ac00d82a2be177b84f74a60ebb0.QicPm3hXLpA9re3ShhfrqX6bKcWmuAvRBCtbRpHrSFQscenes-app-data-warehouse-sql-editor--edited-view--light:@@ -9499,9 +9499,9 @@ snapshots:scenes-app-data-warehouse-sql-editor--lazy-schema--light:hash: v1.k794b7964.746e808509f8aa54b1a216c485d99b2f3c85366daffc3a2c3cb48b56f8512956.Y-ehuWk2tXIBDKsbWcs5nNXWQe63faDn2JUX2wPXp5oscenes-app-data-warehouse-sql-editor--loading-insight--dark:- hash: v1.k794b7964.c5cca89da338912886f2d329a909da87ca3ce5e6f12e0c90ee23c7c8241f768e.XfxPjuo4QbCabh0VgS40-cL0nvbKa4LIqmMHGreN0zI+ hash: v1.k794b7964.6a4654528c452e32987fc4054d950f101350e4e214ef0a0b9cbb53a5c3aff85f.W4xxsumuTbYHqWM4plo-C89kQHxG5_OsgdOwKhELtAMscenes-app-data-warehouse-sql-editor--loading-insight--light:- hash: v1.k794b7964.2d303aecb03d48aa8dacc6e8d6cf8ff68abb8229a4338689b74b6f79d8589ed3.JQsHYIybl3SsiKa9u_elKJhuk1Td__oUl5pjqfEO-OE+ hash: v1.k794b7964.2431f31d5d33b7e87db300430cbab7b2cc70f40786587a09e5b41d42a02a8a5f.x7l4JtfZrwoDUHXEzxtxqbOplVJAY4H69OzVesH80Rkscenes-app-data-warehouse-sql-editor--managed-warehouse-connection--dark:hash: v1.k794b7964.3c4bbe63ff30dee2cdef4a41a06d5a83bedcbaf8fd06bd14e8f7632f5c3d097c.qzBmH7GQm_oM_jCNWuSApX-cI65YcyEnwosDth6tlnEscenes-app-data-warehouse-sql-editor--managed-warehouse-connection--light:@@ -11435,7 +11435,7 @@ snapshots:scenes-app-insights-error-empty-states--validation-error--light:hash: v1.k794b7964.2b012576da17dc343cba68c671217dcfb23f907543fd897d65e42e8793f31958.gL9lf9tk2rIHPSZBxNHmPitiTqUvCG08VR3K9hK7xMoscenes-app-insights-insight-quick-start--default--dark:- hash: v1.k794b7964.9c2221e83fa5d09056672573226c948c5b9cd30716e6eb5e09d1e4ea3e94e336.WkGH5TXIN9Ysp3dVcJiXuGCjwdmC2Zquw_iUGoyj0jc+ hash: v1.k794b7964.f190c463ee799e93ea5d408200712776460a5a9a920977e2b7a85348350fa43b.dcN7n63RW9QEXstFsPgnAaKodbV6piSN7PMhBuHkaGcscenes-app-insights-insight-quick-start--default--light:hash: v1.k794b7964.760bfbe37938f1f855a849f2cf446dbcf8782872258d9efc19cb33aaa20747ce.BSkckjSe-OUU3V1S3QrOnGaJQ7NiAVttPmNCSb37euUscenes-app-insights-loading-messages--loading-messages--dark:@@ -11467,9 +11467,9 @@ snapshots:scenes-app-insights-side-panel-actions--unsaved-insight--light:hash: v1.k794b7964.d1ae4193c6ddd6ec8ec70b8181cd1fa1e33cfa0728d586423355601166b2e8b2.GFGdmioAb_Lqr7qiZik9jLMbbO6yC4abdURWyrSNeOsscenes-app-insights-sqlboxplot--edit-options--dark:- hash: v1.k794b7964.592c80a64be448953a2cbce7666173bb5573eac6252113280bd0be2464a75690.qoIaiLRtDr1k-UVgBSrsWeE4XJfNVuewlseXmvVN9Cg+ hash: v1.k794b7964.bb9343c44dfcb6715d5dd3e75804d343c6f19745c0a94c1bdaa47a537c170534.hwZN8OVxGdrDLJR8bRo0DXfv9sSBhbUnp4ARuI-6Ewwscenes-app-insights-sqlboxplot--edit-options--light:- hash: v1.k794b7964.16fb281af494452f5485f9b4ea02b1be1c97791e8b850e54f2af3dfb9382bf5b.b9EJ6KEYTbd28cG5P1DzricBJFDwYyOro4KyNACKC3A+ hash: v1.k794b7964.1539a8a8d4d19728490331fac7430332d2e1bbac19da9ed11ad6d571976e7864.2fmBRJA-TEOHgC7ODM42naay_EdDGTMjFH9HQFYfbLcscenes-app-insights-sqlboxplot--grouped-series--dark:hash: v1.k794b7964.0062f9e095cb6266619d2886be6973be68c7fc906f50d8b37064390de6757656.frURXaRskPxT8wSqipNvLkFVNmgq3uiSKORwD_fLWDAscenes-app-insights-sqlboxplot--grouped-series--light:diff --git a/frontend/src/layout/panel-layout/ProjectTree/defaultTree.tsx b/frontend/src/layout/panel-layout/ProjectTree/defaultTree.tsxindex 0ac49de16ec7..e70ea30fb61b 100644--- a/frontend/src/layout/panel-layout/ProjectTree/defaultTree.tsx+++ b/frontend/src/layout/panel-layout/ProjectTree/defaultTree.tsx@@ -81,7 +81,7 @@ import {} from '@posthog/icons'import {- IconBracketsChart,+ IconSQL,IconInsightFunnels,IconInsightLifecycle,IconInsightRetention,@@ -313,7 +313,7 @@ const iconTypes: Record<FileSystemIconType, { icon: JSX.Element; iconColor?: Filicon: <IconInsightStickiness />,},'insight/hog': {- icon: <IconBracketsChart />,+ icon: <IconSQL />,},team_activity: {icon: <IconNotification />,diff --git a/frontend/src/layout/panel-layout/ProjectTree/utils.test.ts b/frontend/src/layout/panel-layout/ProjectTree/utils.test.tsindex 7cc841b50ed0..1b59205e7d10 100644--- a/frontend/src/layout/panel-layout/ProjectTree/utils.test.ts+++ b/frontend/src/layout/panel-layout/ProjectTree/utils.test.ts@@ -1,6 +1,7 @@import { renderToStaticMarkup } from 'react-dom/server'import { TreeDataItem } from 'lib/lemon-ui/LemonTree/LemonTree'+import { urls } from 'scenes/urls'import { FileSystemEntry, FileSystemIconType } from '~/queries/schema/schema-general'import { ProjectTreeRef } from '~/types'@@ -205,14 +206,26 @@ describe('project tree utils', () => {})it.each(['trends', 'funnels', 'retention', 'paths', 'lifecycle', 'stickiness', 'hog', undefined, 'unknown'])(- 'renders a saved insight with type %s using its insight icon',+ 'renders a saved insight with type %s using its insight icon and destination',(insightType) => {const [node] = convertFileSystemEntryToTreeDataItem({- imports: [{ id: 'report', path: 'Report', type: 'insight', meta: { insight_type: insightType } }],+ imports: [+ {+ id: 'report',+ ref: 'report1',+ href: '/insights/report1',+ path: 'Report',+ type: 'insight',+ meta: { insight_type: insightType },+ },+ ],folderStates: {},checkedItems: {},root: 'project://',})+ expect(node.record?.href).toEqual(+ insightType === 'hog' ? urls.sqlEditor({ insightShortId: 'report1' }) : '/insights/report1'+ )const expectedType = insightType && insightType !== 'unknown' ? `insight/${insightType}` : 'insight'expect(renderToStaticMarkup(node.icon as JSX.Element)).toEqual(renderToStaticMarkup(iconForType(expectedType as FileSystemIconType))diff --git a/frontend/src/layout/panel-layout/ProjectTree/utils.tsx b/frontend/src/layout/panel-layout/ProjectTree/utils.tsxindex 8a01a3c6080b..875d554e88d9 100644--- a/frontend/src/layout/panel-layout/ProjectTree/utils.tsx+++ b/frontend/src/layout/panel-layout/ProjectTree/utils.tsx@@ -2,6 +2,7 @@ import { IconPlus, IconShortcut } from '@posthog/icons'import { Spinner } from '@posthog/lemon-ui'import { TreeDataItem } from 'lib/lemon-ui/LemonTree/LemonTree'+import { urls } from 'scenes/urls'import { SearchHighlightMultiple } from '~/layout/navigation-3000/components/SearchHighlight'import { RecentResults, SearchResults } from '~/layout/panel-layout/ProjectTree/projectTreeLogic'@@ -214,7 +215,14 @@ export function convertFileSystemEntryToTreeDataItem({name: itemName,displayName,icon: item._loading ? <Spinner /> : item.shortcut || allShortcuts ? wrapWithShortcutIcon(icon) : icon,- record: { ...item, user },+ record: {+ ...item,+ href:+ getFileSystemIconType(item) === 'insight/hog' && item.ref+ ? urls.sqlEditor({ insightShortId: item.ref })+ : item.href,+ user,+ },checked: checkedItems[nodeId],visualOrder: item.visualOrder,}diff --git a/frontend/src/lib/lemon-ui/icons/icons.tsx b/frontend/src/lib/lemon-ui/icons/icons.tsxindex 9b4d96367412..2f4f72533424 100644--- a/frontend/src/lib/lemon-ui/icons/icons.tsx+++ b/frontend/src/lib/lemon-ui/icons/icons.tsx@@ -461,19 +461,20 @@ const LIFECYCLE_RETURNING = 'var(--insight-icon-lifecycle-returning)'const LIFECYCLE_DORMANT = 'var(--insight-icon-lifecycle-dormant)'const LIFECYCLE_RESURRECTING = 'var(--insight-icon-lifecycle-resurrecting)'-/** SQL insights: curly brackets (matching `IconBrackets` from `@posthog/icons`) wrapping a bar chart. */-export function IconBracketsChart(props: LemonIconProps): JSX.Element {- return (- <LemonIconBase {...props}>- <path- fillRule="evenodd"- clipRule="evenodd"- d="M4 4.75C4 3.784 4.784 3 5.75 3h2.5a.75.75 0 0 1 0 1.5h-2.5a.25.25 0 0 0-.25.25V11c0 .372-.116.716-.314 1 .198.284.314.628.314 1v6.25c0 .138.112.25.25.25h2.5a.75.75 0 0 1 0 1.5h-2.5A1.75 1.75 0 0 1 4 19.25V13a.25.25 0 0 0-.25-.25h-1a.75.75 0 0 1 0-1.5h1A.25.25 0 0 0 4 11V4.75Zm11-1a.75.75 0 0 1 .75-.75h2.5c.966 0 1.75.784 1.75 1.75V11c0 .138.112.25.25.25h1a.75.75 0 0 1 0 1.5h-1A.25.25 0 0 0 20 13v6.25A1.75 1.75 0 0 1 18.25 21h-2.5a.75.75 0 0 1 0-1.5h2.5a.25.25 0 0 0 .25-.25V13c0-.372.116-.716.314-1a1.742 1.742 0 0 1-.314-1V4.75a.25.25 0 0 0-.25-.25h-2.5a.75.75 0 0 1-.75-.75Z"- fill="currentColor"- />- <rect x="6.75" y="13.5" width="3" height="4" rx="0.5" style={{ fill: INSIGHT_GREEN }} />- <rect x="10.5" y="10.5" width="3" height="7" rx="0.5" style={{ fill: INSIGHT_PURPLE }} />- <rect x="14.25" y="7.5" width="3" height="10" rx="0.5" style={{ fill: INSIGHT_BLUE }} />+export function IconSQL(props: LemonIconProps): JSX.Element {+ return (+ <LemonIconBase {...props}>+ <text+ x="12"+ y="12"+ textAnchor="middle"+ dominantBaseline="central"+ fontSize="11"+ fontWeight="700"+ className="font-mono fill-[var(--insight-icon-blue)]"+ >+ SQL+ </text></LemonIconBase>)}diff --git a/frontend/src/scenes/data-warehouse/editor/SQLEditor.tsx b/frontend/src/scenes/data-warehouse/editor/SQLEditor.tsxindex 9992a782112e..8e53198e02c6 100644--- a/frontend/src/scenes/data-warehouse/editor/SQLEditor.tsx+++ b/frontend/src/scenes/data-warehouse/editor/SQLEditor.tsx@@ -852,23 +852,39 @@ function SQLEditorSceneTitle(): JSX.Element | null {overlay: (<LemonMenuOverlayitems={[- continueInNotebookMenuItem,{- label: 'Save as new insight...',- disabledReason: saveAsInsightDisabledReason,- onClick: () => saveAsInsight(),+ items: [+ continueInNotebookMenuItem,+ {+ label: 'Save as new insight...',+ disabledReason: saveAsInsightDisabledReason,+ onClick: () => saveAsInsight(),+ },+ {+ label: 'Save as new view...',+ disabledReason:+ saveAsDisabledReason ??+ saveAsViewAccessDisabledReason,+ onClick: () => saveAsView(),+ },+ {+ label: 'Save as endpoint...',+ disabledReason:+ saveAsDisabledReason ??+ saveAsEndpointDisabledReason,+ onClick: () => saveAsEndpoint(),+ },+ ],},{- label: 'Save as new view...',- disabledReason:- saveAsDisabledReason ?? saveAsViewAccessDisabledReason,- onClick: () => saveAsView(),- },- {- label: 'Save as endpoint...',- disabledReason:- saveAsDisabledReason ?? saveAsEndpointDisabledReason,- onClick: () => saveAsEndpoint(),+ items: [+ {+ label: 'Reset view',+ 'data-attr': 'sql-editor-reset-view',+ tooltip: closeObjectTooltip,+ onClick: () => closeEditingObject(),+ },+ ],},]}/>@@ -878,15 +894,6 @@ function SQLEditorSceneTitle(): JSX.Element | null {>Update insight</LemonButton>- <LemonButton- onClick={() => closeEditingObject()}- icon={<IconX />}- type="secondary"- size="small"- noPadding- aria-label="close"- tooltip={closeObjectTooltip}- /></>) : editingMetricName ? (<>diff --git a/frontend/src/scenes/data-warehouse/editor/SQLEditorScene.stories.tsx b/frontend/src/scenes/data-warehouse/editor/SQLEditorScene.stories.tsxindex 9d12de4c2811..67a2c518d06c 100644--- a/frontend/src/scenes/data-warehouse/editor/SQLEditorScene.stories.tsx+++ b/frontend/src/scenes/data-warehouse/editor/SQLEditorScene.stories.tsx@@ -324,7 +324,11 @@ export const EditedInsight: Story = {'aria-disabled','true')- await userEvent.keyboard('{Escape}')+ await expect(canvas.queryByRole('button', { name: /^close$/ })).not.toBeInTheDocument()+ await userEvent.click(menu.getByText('Reset view'))+ await waitFor(() => expect(canvas.queryByRole('button', { name: 'Update insight' })).not.toBeInTheDocument())+ await expect(canvas.getByRole('button', { name: 'Save as insight' })).toBeVisible()+ await expect(sqlEditorLogic({ tabId: 'default' }).values.queryInput).toEqual('SELECT 2')},}diff --git a/frontend/src/scenes/notebooks/nodeIcons.tsx b/frontend/src/scenes/notebooks/nodeIcons.tsxindex 651c55d407fe..105accd3f1f0 100644--- a/frontend/src/scenes/notebooks/nodeIcons.tsx+++ b/frontend/src/scenes/notebooks/nodeIcons.tsx@@ -21,7 +21,7 @@ import {IconWarning,} from '@posthog/icons'-import { IconBracketsChart } from 'lib/lemon-ui/icons'+import { IconSQL } from 'lib/lemon-ui/icons'import { NotebookNodeType } from './types'@@ -33,7 +33,7 @@ export const NODE_ICONS: Partial<Record<NotebookNodeType, JSX.Element>> = {[NotebookNodeType.Dashboard]: <IconPieChart />,[NotebookNodeType.Action]: <IconList />,[NotebookNodeType.Workflow]: <IconUserPaths />,- [NotebookNodeType.SQLV2]: <IconBracketsChart />,+ [NotebookNodeType.SQLV2]: <IconSQL />,[NotebookNodeType.PythonV2]: <IconPython />,[NotebookNodeType.GeneratedWidget]: <IconAI />,[NotebookNodeType.Latex]: <IconSquareRoot />,diff --git a/frontend/src/scenes/saved-insights/insightTypesMetadata.tsx b/frontend/src/scenes/saved-insights/insightTypesMetadata.tsxindex fa08f8cd733b..2d30e12bb122 100644--- a/frontend/src/scenes/saved-insights/insightTypesMetadata.tsx+++ b/frontend/src/scenes/saved-insights/insightTypesMetadata.tsx@@ -21,7 +21,7 @@ import { LemonSelectOptions } from '@posthog/lemon-ui'import { FEATURE_FLAGS, FeatureFlagKey } from 'lib/constants'import {IconAction,- IconBracketsChart,+ IconSQL,IconInsightCalendarHeatmap,IconInsightFunnels,IconInsightLifecycle,@@ -234,7 +234,7 @@ export const QUERY_TYPES_METADATA: Record<NodeKind, InsightTypeMetadata> = {[NodeKind.DataVisualizationNode]: {name: 'SQL',description: 'Slice and dice your data in a table or chart.',- icon: IconBracketsChart,+ icon: IconSQL,inMenu: false,},[NodeKind.SavedInsightNode]: {@@ -258,25 +258,25 @@ export const QUERY_TYPES_METADATA: Record<NodeKind, InsightTypeMetadata> = {[NodeKind.HogQLQuery]: {name: 'SQL',description: 'Direct SQL query.',- icon: IconBracketsChart,+ icon: IconSQL,inMenu: true,},[NodeKind.HogQLMetadata]: {name: 'SQL Metadata',description: 'Metadata for a SQL query.',- icon: IconBracketsChart,+ icon: IconSQL,inMenu: true,},[NodeKind.HogQLAutocomplete]: {name: 'SQL Autocomplete',description: 'Autocomplete for the SQL query editor.',- icon: IconBracketsChart,+ icon: IconSQL,inMenu: false,},[NodeKind.DatabaseSchemaQuery]: {name: 'Database Schema',description: 'Introspect the PostHog database schema.',- icon: IconBracketsChart,+ icon: IconSQL,inMenu: true,},[NodeKind.WebOverviewQuery]: {@@ -743,7 +743,7 @@ export const INSIGHT_TYPES_METADATA: Record<InsightType, InsightTypeMetadata> =[InsightType.SQL]: {name: 'SQL',description: 'Use SQL to query your data.',- icon: IconBracketsChart,+ icon: IconSQL,inMenu: true,tooltipDocLink: 'https://posthog.com/docs/data-warehouse/sql',},