Skip to content

: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.

feat(notebooks): surface Python cells and named SQL outputs (#99862)

Sinan Kucukkoseler1154a9e2065d
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index bed87fc68074..4afa42596ba3 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -8792,6 +8792,10 @@ snapshots:
hash: v1.k794b7964.434383db5739f05638540be4be2f7671cdb35cca73c32df11f324feb17f3685c.suVpXuPkYmQJtBx6L0JVf4p_bj929kIWSY2fds0lPfw
scenes-app-notebooks-components-notebook-select-button--with-slow-network-response--light:
hash: v1.k794b7964.678b0f73befa0690622fd5eb7a920f5c25919af7a9b516a08756e866b37de352.QhzKGfEQA_MQykTL8uuyOryngt75iNv9BydvL5ckPjQ
+ scenes-app-notebooks-dataframe-hint--on-a-cell-with-no-dataframe-name--dark:
+ hash: v1.k794b7964.099228351b7624d666505094801048a76f10d19b6122bdae57095a2f248a85af.ceSOAt-JxUJXvTOF3O-qcPOyDJfYQy_JxLBIJTITHBU
+ scenes-app-notebooks-dataframe-hint--on-a-cell-with-no-dataframe-name--light:
+ hash: v1.k794b7964.9cb4583e02d3192ab41346398046f32619977f6a4d7d56644245f4018b1c1451.rqbs7lbVXIaK4wH1m1_NFxMizFc2esosnCWk6XB-_VQ
scenes-app-notebooks-kernel-info--free-compute--dark:
hash: v1.k794b7964.9f16845ad724b67d68cd068ab5a2f8ca6fc8ab83e710d6e2f28b113fe09b9171._s-RfNP8c5cc0e10ja9PrgPhUh70q_D7letZIoo0vf8
scenes-app-notebooks-kernel-info--free-compute--light:
diff --git a/frontend/src/lib/components/MarkdownNotebook/InsertMenu.tsx b/frontend/src/lib/components/MarkdownNotebook/InsertMenu.tsx
index 24573a4c2d9c..899b5946bb86 100644
--- a/frontend/src/lib/components/MarkdownNotebook/InsertMenu.tsx
+++ b/frontend/src/lib/components/MarkdownNotebook/InsertMenu.tsx
@@ -153,6 +153,9 @@ export function InsertMenu({
<span className="MarkdownNotebook__insert-item-icon">{command.icon}</span>
) : null}
<span>{renderHighlightedInsertCommandLabel(command.label, query)}</span>
+ {command.badge ? (
+ <span className="MarkdownNotebook__insert-item-badge">{command.badge}</span>
+ ) : null}
</button>
))}
</div>
@@ -520,6 +523,7 @@ export function buildInsertCommands(
description: insertCommand.description ?? definition.description,
aliases: insertCommand.aliases ?? definition.aliases,
icon: insertCommand.icon ?? definition.icon,
+ badge: insertCommand.badge,
run: (targetNodeId) =>
insertRegisteredComponent(
targetNodeId,
diff --git a/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.scss b/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.scss
index 25371f37c6aa..b3a99e720115 100644
--- a/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.scss
+++ b/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.scss
@@ -1122,6 +1122,18 @@ h3.MarkdownNotebook__text-block--heading {
border-radius: 0.1875rem;
}
+.MarkdownNotebook__insert-item-badge {
+ flex: 0 0 auto;
+ padding: 0 0.25rem;
+ margin-left: auto;
+ font-size: 0.6875rem;
+ font-weight: 600;
+ line-height: 1.125rem;
+ color: var(--color-text-secondary);
+ background: var(--color-bg-fill-tertiary);
+ border-radius: 0.1875rem;
+}
+
.MarkdownNotebook__insert-item:hover,
.MarkdownNotebook__insert-item:focus-visible,
.MarkdownNotebook__insert-item--selected {
diff --git a/frontend/src/lib/components/MarkdownNotebook/editorTypes.ts b/frontend/src/lib/components/MarkdownNotebook/editorTypes.ts
index aaa71fb97ca0..8e8bb26d570d 100644
--- a/frontend/src/lib/components/MarkdownNotebook/editorTypes.ts
+++ b/frontend/src/lib/components/MarkdownNotebook/editorTypes.ts
@@ -40,6 +40,9 @@ export type InsertCommand = {
description?: string
aliases?: string[]
icon?: ReactNode
+ /** Short tag drawn after the label, for calling out a cell people have not met yet. Not
+ * searchable: a badge is about the menu, not about what the cell does. */
+ badge?: string
closeOnRun?: boolean
disabled?: boolean
run: (targetNodeId: string) => void
diff --git a/frontend/src/lib/components/MarkdownNotebook/types.ts b/frontend/src/lib/components/MarkdownNotebook/types.ts
index 69ef69a68015..cd9ae4f719a9 100644
--- a/frontend/src/lib/components/MarkdownNotebook/types.ts
+++ b/frontend/src/lib/components/MarkdownNotebook/types.ts
@@ -156,6 +156,7 @@ export type NotebookComponentInsertCommand = {
description?: string
aliases?: string[]
icon?: ReactNode
+ badge?: string
defaultProps?: NotebookComponentProps | (() => NotebookComponentProps)
}
diff --git a/frontend/src/scenes/notebooks/Nodes/NotebookNodePythonV2.tsx b/frontend/src/scenes/notebooks/Nodes/NotebookNodePythonV2.tsx
index fdf21e0d8d08..5565762ef943 100644
--- a/frontend/src/scenes/notebooks/Nodes/NotebookNodePythonV2.tsx
+++ b/frontend/src/scenes/notebooks/Nodes/NotebookNodePythonV2.tsx
@@ -1,14 +1,13 @@
import { useActions, useMountedLogic, useValues } from 'kea'
import { useEffect, useMemo, useRef } from 'react'
-import { IconCornerDownRight } from '@posthog/icons'
-
import { CodeEditorResizeable } from 'lib/monaco/CodeEditorResizable'
import { createPostHogWidgetNode } from 'scenes/notebooks/Nodes/NodeWrapper'
import type { NotebookNodeRunTerminalStatus } from 'scenes/notebooks/Notebook/notebookNodeStalenessLogic'
import { NotebookNodeAttributeProperties, NotebookNodeProps, NotebookNodeType } from '../types'
import { NotebookCellOutputHeader } from './components/NotebookCellOutputHeader'
+import { NotebookCellOutputNameFooter } from './components/NotebookCellOutputNameFooter'
import { NotebookDataframeTable } from './components/NotebookDataframeTable'
import { NotebookRunDownstreamBanner } from './components/NotebookRunDownstreamBanner'
import { NotebookStaleCellBanner } from './components/NotebookStaleCellBanner'
@@ -205,30 +204,10 @@ const Component = ({
<div className="text-xs text-muted font-mono p-2">Run the cell to see execution results.</div>
)}
</div>
- <div
- // Translucent overlay, not a surface token: the shell is surface-primary in light
- // mode but surface-tertiary in dark, so a fixed surface vanishes against one of them.
- className="flex shrink-0 items-center gap-2 text-xs text-muted border-t border-primary bg-fill-highlight-50 p-2"
- onClick={(event) => event.stopPropagation()}
- onMouseDown={(event) => event.stopPropagation()}
- >
- <span className="font-mono mt-0.5">
- <IconCornerDownRight />
- </span>
- <input
- type="text"
- // The dataframe name this cell's result is exposed as to later cells.
- // Optional: left empty, the cell binds nothing and later cells can't read it.
- // Wide enough for the placeholder to sit on one line without clipping. The name
- // carries weight through size and a faintly warm near-black rather than a hue —
- // a saturated color here competes with the accent the app spends on links.
- className="w-56 rounded border border-primary px-1.5 py-0.5 text-sm font-medium font-mono bg-surface-primary text-[oklch(0.27_0.022_345deg)] dark:text-[oklch(0.93_0.014_345deg)] focus:outline-none focus:ring-1 focus:ring-primary"
- value={attributes.returnVariable ?? ''}
- onChange={(event) => updateAttributes({ returnVariable: event.target.value })}
- placeholder="Output dataframe name"
- spellCheck={false}
- />
- </div>
+ <NotebookCellOutputNameFooter
+ returnVariable={attributes.returnVariable ?? ''}
+ onChange={(returnVariable) => updateAttributes({ returnVariable })}
+ />
</div>
)
}
diff --git a/frontend/src/scenes/notebooks/Nodes/NotebookNodeSQLV2.tsx b/frontend/src/scenes/notebooks/Nodes/NotebookNodeSQLV2.tsx
index 29e63adf0958..cc101ba23d83 100644
--- a/frontend/src/scenes/notebooks/Nodes/NotebookNodeSQLV2.tsx
+++ b/frontend/src/scenes/notebooks/Nodes/NotebookNodeSQLV2.tsx
@@ -1,7 +1,5 @@
import { useActions, useMountedLogic, useValues } from 'kea'
-import { useEffect, useMemo, useRef } from 'react'
-
-import { IconCornerDownRight } from '@posthog/icons'
+import { useEffect, useMemo, useRef, useState } from 'react'
import { LemonTabs } from 'lib/lemon-ui/LemonTabs'
import { OutputTab } from 'scenes/data-warehouse/editor/outputPaneLogic'
@@ -14,6 +12,9 @@ import { ChartDisplayType } from '~/types'
import { NotebookNodeAttributeProperties, NotebookNodeProps, NotebookNodeType } from '../types'
import { NotebookCellOutputHeader } from './components/NotebookCellOutputHeader'
+import { NotebookCellOutputNameFooter } from './components/NotebookCellOutputNameFooter'
+import { notebookDataframeHintLogic } from './components/notebookDataframeHintLogic'
+import { NotebookDataframeHintPopover } from './components/NotebookDataframeHintPopover'
import { NotebookDataframeTable } from './components/NotebookDataframeTable'
import { getCellLabel } from './components/NotebookNodeTitle'
import { NotebookRunDownstreamBanner } from './components/NotebookRunDownstreamBanner'
@@ -174,7 +175,24 @@ const Component = ({
title.trim() || getCellLabel(nodeIndex) || 'SQL'
const result = attributes.result ?? null
- const returnVariableError = returnVariableValidationError(attributes.returnVariable ?? '')
+ const returnVariable = attributes.returnVariable ?? ''
+ const returnVariableError = returnVariableValidationError(returnVariable)
+ // A callback ref, not useRef: the hint anchors to this input, and a ref assignment alone
+ // wouldn't re-render the Popover with the element it needs to position against.
+ const [returnVariableInput, setReturnVariableInput] = useState<HTMLInputElement | null>(null)
+ const { reportRunFinished } = useActions(notebookDataframeHintLogic({ shortId: notebookShortId }))
+ const runStatus = attributes.runStatus ?? null
+ const previousRunStatusRef = useRef(runStatus)
+
+ useEffect(() => {
+ const previousRunStatus = previousRunStatusRef.current
+ previousRunStatusRef.current = runStatus
+ // Only a run that finishes while the cell is open. Reopening a notebook restores a
+ // finished result too, and the hint would then point at a cell nobody just ran.
+ if (runStatus === 'done' && previousRunStatus !== 'done') {
+ reportRunFinished(nodeId, !!returnVariable)
+ }
+ }, [runStatus, returnVariable, nodeId, reportRunFinished])
// Page 1 at the default size comes straight from the envelope; other pages re-query CH.
const dataframeResult = useMemo(() => {
if (pageResult) {
@@ -340,28 +358,15 @@ const Component = ({
<div className="text-xs text-muted font-mono p-2">Run the query to see execution results.</div>
)}
</div>
- <div
- // Translucent overlay, not a surface token: the shell is surface-primary in light
- // mode but surface-tertiary in dark, so a fixed surface vanishes against one of them.
- className="flex shrink-0 items-center gap-2 text-xs text-muted border-t border-primary bg-fill-highlight-50 p-2"
- onClick={(event) => event.stopPropagation()}
- onMouseDown={(event) => event.stopPropagation()}
+ <NotebookCellOutputNameFooter
+ returnVariable={returnVariable}
+ onChange={(returnVariable) => updateAttributes({ returnVariable })}
+ inputRef={setReturnVariableInput}
>
- <span className="font-mono mt-0.5">
- <IconCornerDownRight />
- </span>
- <input
- type="text"
- // A dataframe name other SQL nodes reference by table name (`from sql_df`).
- // Optional: left empty, the cell is display-only and exports nothing.
- // Wide enough for the placeholder to sit on one line without clipping. The name
- // carries weight through size and a faintly warm near-black rather than a hue —
- // a saturated color here competes with the accent the app spends on links.
- className="w-56 rounded border border-primary px-1.5 py-0.5 text-sm font-medium font-mono bg-surface-primary text-[oklch(0.27_0.022_345deg)] dark:text-[oklch(0.93_0.014_345deg)] focus:outline-none focus:ring-1 focus:ring-primary"
- value={attributes.returnVariable ?? ''}
- onChange={(event) => updateAttributes({ returnVariable: event.target.value })}
- placeholder="Output dataframe name"
- spellCheck={false}
+ <NotebookDataframeHintPopover
+ nodeId={nodeId}
+ notebookShortId={notebookShortId}
+ referenceElement={returnVariableInput}
/>
{returnVariableError ? <span className="text-danger">{returnVariableError}</span> : null}
{sqlV2ReturnVariableUsage.length > 0 ? (
@@ -379,7 +384,7 @@ const Component = ({
))}
</span>
) : null}
- </div>
+ </NotebookCellOutputNameFooter>
</div>
)
}
diff --git a/frontend/src/scenes/notebooks/Nodes/components/NotebookCellOutputNameFooter.tsx b/frontend/src/scenes/notebooks/Nodes/components/NotebookCellOutputNameFooter.tsx
new file mode 100644
index 000000000000..1807b241d912
--- /dev/null
+++ b/frontend/src/scenes/notebooks/Nodes/components/NotebookCellOutputNameFooter.tsx
@@ -0,0 +1,49 @@
+import { ReactNode } from 'react'
+
+import { IconCornerDownRight } from '@posthog/icons'
+
+/** The bar under a code cell's output that names the dataframe the cell binds. Shared by the SQL
+ * and Python cells, which differ only in what they put after the input. */
+export function NotebookCellOutputNameFooter({
+ returnVariable,
+ onChange,
+ inputRef,
+ children,
+}: {
+ returnVariable: string
+ onChange: (returnVariable: string) => void
+ /** Receives the input element, for a caller that anchors something to it. */
+ inputRef?: (element: HTMLInputElement | null) => void
+ /** Drawn after the input: a validation error, usage links, a hint. */
+ children?: ReactNode
+}): JSX.Element {
+ return (
+ <div
+ // Translucent overlay, not a surface token: the shell is surface-primary in light
+ // mode but surface-tertiary in dark, so a fixed surface vanishes against one of them.
+ className="flex shrink-0 items-center gap-2 text-xs text-muted border-t border-primary bg-fill-highlight-50 p-2"
+ onClick={(event) => event.stopPropagation()}
+ onMouseDown={(event) => event.stopPropagation()}
+ >
+ <span className="font-mono mt-0.5">
+ <IconCornerDownRight />
+ </span>
+ <input
+ type="text"
+ // The dataframe name this cell's result is exposed as to later cells. A SQL cell
+ // references it as a table name (`from sql_df`), a Python cell as a variable.
+ // Optional: left empty, the cell exports nothing and later cells can't read it.
+ // Wide enough for the placeholder to sit on one line without clipping. The name
+ // carries weight through size and a faintly warm near-black rather than a hue,
+ // because a saturated color here competes with the accent the app spends on links.
+ className="w-56 rounded border border-primary px-1.5 py-0.5 text-sm font-medium font-mono bg-surface-primary text-[oklch(0.27_0.022_345deg)] dark:text-[oklch(0.93_0.014_345deg)] focus:outline-none focus:ring-1 focus:ring-primary"
+ value={returnVariable}
+ onChange={(event) => onChange(event.target.value)}
+ placeholder="Output dataframe name"
+ spellCheck={false}
+ ref={inputRef}
+ />
+ {children}
+ </div>
+ )
+}
diff --git a/frontend/src/scenes/notebooks/Nodes/components/NotebookDataframeHintPopover.stories.tsx b/frontend/src/scenes/notebooks/Nodes/components/NotebookDataframeHintPopover.stories.tsx
new file mode 100644
index 000000000000..0a71409e3350
--- /dev/null
+++ b/frontend/src/scenes/notebooks/Nodes/components/NotebookDataframeHintPopover.stories.tsx
@@ -0,0 +1,61 @@
+import { Meta, StoryObj } from '@storybook/react'
+import { useEffect, useState } from 'react'
+
+import { FEATURE_FLAGS } from 'lib/constants'
+
+import { notebookDataframeHintLogic } from './notebookDataframeHintLogic'
+import { NotebookDataframeHintPopover } from './NotebookDataframeHintPopover'
+
+const SHORT_ID = '12345'
+const NODE_ID = 'node-1'
+
+// The SQL cell's footer, reduced to the input the hint anchors to, so the story shows the
+// popover where a reader meets it rather than floating on its own.
+function DataframeHintFooter(): JSX.Element {
+ const [returnVariableInput, setReturnVariableInput] = useState<HTMLInputElement | null>(null)
+
+ useEffect(() => {
+ const logic = notebookDataframeHintLogic({ shortId: SHORT_ID })
+ const unmount = logic.mount()
+ logic.actions.showHint(NODE_ID)
+ return unmount
+ }, [])
+
+ return (
+ <div className="flex items-center gap-2 border-t border-primary bg-fill-highlight-50 p-2 text-xs text-muted">
+ <input
+ type="text"
+ className="w-56 rounded border border-primary bg-surface-primary px-1.5 py-0.5 font-mono text-sm font-medium"
+ placeholder="Output dataframe name"
+ ref={setReturnVariableInput}
+ readOnly
+ />
+ <NotebookDataframeHintPopover
+ nodeId={NODE_ID}
+ notebookShortId={SHORT_ID}
+ referenceElement={returnVariableInput}
+ />
+ </div>
+ )
+}
+
+const meta: Meta<typeof NotebookDataframeHintPopover> = {
+ title: 'Scenes-App/Notebooks/Dataframe hint',
+ component: NotebookDataframeHintPopover,
+ parameters: {
+ featureFlags: [FEATURE_FLAGS.REVAMPED_PY_NOTEBOOKS],
+ testOptions: { waitForLoadersToDisappear: false },
+ },
+}
+export default meta
+
+type Story = StoryObj<typeof NotebookDataframeHintPopover>
+
+export const OnACellWithNoDataframeName: Story = {
+ // Room above the input, which is where the popover opens.
+ render: () => (
+ <div className="pt-40">
+ <DataframeHintFooter />
+ </div>
+ ),
+}
diff --git a/frontend/src/scenes/notebooks/Nodes/components/NotebookDataframeHintPopover.tsx b/frontend/src/scenes/notebooks/Nodes/components/NotebookDataframeHintPopover.tsx
new file mode 100644
index 000000000000..7b49807b4838
--- /dev/null
+++ b/frontend/src/scenes/notebooks/Nodes/components/NotebookDataframeHintPopover.tsx
@@ -0,0 +1,47 @@
+import { useActions, useValues } from 'kea'
+
+import { LemonButton } from 'lib/lemon-ui/LemonButton'
+import { Popover } from 'lib/lemon-ui/Popover'
+
+import { notebookDataframeHintLogic } from './notebookDataframeHintLogic'
+
+export function NotebookDataframeHintPopover({
+ nodeId,
+ notebookShortId,
+ referenceElement,
+}: {
+ nodeId: string
+ notebookShortId: string
+ referenceElement: HTMLElement | null
+}): JSX.Element {
+ const logic = notebookDataframeHintLogic({ shortId: notebookShortId })
+ const { hintNodeId } = useValues(logic)
+ const { dismissHint } = useActions(logic)
+
+ return (
+ <Popover
+ visible={hintNodeId === nodeId && !!referenceElement}
+ referenceElement={referenceElement}
+ placement="top-start"
+ onClickOutside={dismissHint}
+ overlay={
+ <div className="flex max-w-80 flex-col gap-2">
+ <p className="m-0 font-semibold">Store your output to reuse it in a following node</p>
+ <p className="m-0 text-muted">
+ A named output becomes a dataframe later cells can read. SQL nodes read it as a table name.
+ Python nodes read it as a regular variable.
+ </p>
+ <LemonButton
+ type="primary"
+ size="small"
+ className="self-start"
+ data-attr="notebook-dataframe-hint-dismiss"
+ onClick={dismissHint}
+ >
+ Got it
+ </LemonButton>
+ </div>
+ }
+ />
+ )
+}
diff --git a/frontend/src/scenes/notebooks/Nodes/components/notebookDataframeHintLogic.test.ts b/frontend/src/scenes/notebooks/Nodes/components/notebookDataframeHintLogic.test.ts
new file mode 100644
index 000000000000..204f155339e9
--- /dev/null
+++ b/frontend/src/scenes/notebooks/Nodes/components/notebookDataframeHintLogic.test.ts
@@ -0,0 +1,86 @@
+import { MOCK_DEFAULT_USER } from 'lib/api.mock'
+
+import { expectLogic } from 'kea-test-utils'
+
+import { FEATURE_FLAGS } from 'lib/constants'
+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
+import { userLogic } from 'scenes/userLogic'
+
+import { initKeaTests } from '~/test/init'
+import { UserType } from '~/types'
+
+import { NOTEBOOK_DATAFRAME_HINT_SEEN_KEY, notebookDataframeHintLogic } from './notebookDataframeHintLogic'
+
+describe('notebookDataframeHintLogic', () => {
+ let logic: ReturnType<typeof notebookDataframeHintLogic.build>
+
+ const loadUser = (hasSeenProductIntroFor: Record<string, boolean>): void => {
+ userLogic.actions.loadUserSuccess({
+ ...MOCK_DEFAULT_USER,
+ has_seen_product_intro_for: hasSeenProductIntroFor,
+ } as UserType)
+ }
+
+ beforeEach(() => {
+ initKeaTests()
+ featureFlagLogic.mount()
+ featureFlagLogic.actions.setFeatureFlags([FEATURE_FLAGS.REVAMPED_PY_NOTEBOOKS], {
+ [FEATURE_FLAGS.REVAMPED_PY_NOTEBOOKS]: true,
+ })
+ userLogic.mount()
+ logic = notebookDataframeHintLogic({ shortId: 'abc123' })
+ logic.mount()
+ })
+
+ it('opens against the cell that just finished', async () => {
+ loadUser({})
+
+ await expectLogic(logic, () => {
+ logic.actions.reportRunFinished('node-1', false)
+ }).toMatchValues({ hintNodeId: 'node-1' })
+ })
+
+ it.each([
+ ['the cell already names its output', { hasReturnVariable: true, seen: {} }],
+ [
+ 'the user dismissed it before',
+ { hasReturnVariable: false, seen: { [NOTEBOOK_DATAFRAME_HINT_SEEN_KEY]: true } },
+ ],
+ ])('stays closed when %s', async (_label, { hasReturnVariable, seen }) => {
+ loadUser(seen)
+
+ await expectLogic(logic, () => {
+ logic.actions.reportRunFinished('node-1', hasReturnVariable)
+ }).toMatchValues({ hintNodeId: null })
+ })
+
+ it('stays closed until the user has loaded', async () => {
+ userLogic.actions.loadUserSuccess(null)
+
+ await expectLogic(logic, () => {
+ logic.actions.reportRunFinished('node-1', false)
+ }).toMatchValues({ hintNodeId: null })
+ })
+
+ it('keeps the hint on the first cell when a chain finishes several', async () => {
+ loadUser({})
+
+ await expectLogic(logic, () => {
+ logic.actions.reportRunFinished('node-1', false)
+ logic.actions.reportRunFinished('node-2', false)
+ }).toMatchValues({ hintNodeId: 'node-1' })
+ })
+
+ it('records the dismissal against the user, not the browser', async () => {
+ loadUser({})
+ logic.actions.reportRunFinished('node-1', false)
+
+ await expectLogic(logic, () => {
+ logic.actions.dismissHint()
+ })
+ .toDispatchActions([
+ userLogic.actionCreators.updateHasSeenProductIntroFor(NOTEBOOK_DATAFRAME_HINT_SEEN_KEY),
+ ])
+ .toMatchValues({ hintNodeId: null })
+ })
+})
diff --git a/frontend/src/scenes/notebooks/Nodes/components/notebookDataframeHintLogic.ts b/frontend/src/scenes/notebooks/Nodes/components/notebookDataframeHintLogic.ts
new file mode 100644
index 000000000000..83f266c002cf
--- /dev/null
+++ b/frontend/src/scenes/notebooks/Nodes/components/notebookDataframeHintLogic.ts
@@ -0,0 +1,112 @@
+import { MakeLogicType, actions, connect, kea, key, listeners, path, props, reducers, selectors } from 'kea'
+
+import { FEATURE_FLAGS } from 'lib/constants'
+import { FeatureFlagsSet, featureFlagLogic } from 'lib/logic/featureFlagLogic'
+import { userLogic } from 'scenes/userLogic'
+
+import { UserType } from '~/types'
+
+// pinned: persisted per user in `has_seen_product_intro_for`, so renaming it reopens the hint for
+// everyone who already dismissed it.
+export const NOTEBOOK_DATAFRAME_HINT_SEEN_KEY = 'notebooks-sql-dataframe-hint'
+
+export interface NotebookDataframeHintLogicProps {
+ shortId: string
+}
+
+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
+export interface notebookDataframeHintLogicValues {
+ featureFlags: FeatureFlagsSet // featureFlagLogic
+ user: UserType | null // userLogic
+ canShowHint: boolean
+ hintNodeId: string | null
+}
+
+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
+export interface notebookDataframeHintLogicActions {
+ updateHasSeenProductIntroFor: (
+ productKey: string,
+ value?: boolean | undefined
+ ) => {
+ productKey: string
+ value: boolean
+ } // userLogic
+ dismissHint: () => {
+ value: true
+ }
+ reportRunFinished: (
+ nodeId: string,
+ hasReturnVariable: boolean
+ ) => {
+ hasReturnVariable: boolean
+ nodeId: string
+ }
+ showHint: (nodeId: string) => {
+ nodeId: string
+ }
+}
+
+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
+export interface notebookDataframeHintLogicMeta {
+ key: string
+ __keaTypeGenInternalSelectorTypes: {
+ canShowHint: (featureFlags: FeatureFlagsSet, user: UserType | null) => boolean
+ }
+}
+
+export type notebookDataframeHintLogicType = MakeLogicType<
+ notebookDataframeHintLogicValues,
+ notebookDataframeHintLogicActions,
+ NotebookDataframeHintLogicProps,
+ notebookDataframeHintLogicMeta
+>
+
+/** Decides when to point a first-time user at the output dataframe name on a SQL cell, and records
+ * the dismissal against the user rather than the browser. */
+export const notebookDataframeHintLogic = kea<notebookDataframeHintLogicType>([
+ path((key) => ['scenes', 'notebooks', 'Nodes', 'components', 'notebookDataframeHintLogic', key]),
+ props({} as NotebookDataframeHintLogicProps),
+ key((props) => props.shortId),
+ connect(() => ({
+ values: [featureFlagLogic, ['featureFlags'], userLogic, ['user']],
+ actions: [userLogic, ['updateHasSeenProductIntroFor']],
+ })),
+ actions({
+ reportRunFinished: (nodeId: string, hasReturnVariable: boolean) => ({ nodeId, hasReturnVariable }),
+ showHint: (nodeId: string) => ({ nodeId }),
+ dismissHint: true,
+ }),
+ reducers({
+ hintNodeId: [
+ null as string | null,
+ {
+ showHint: (_, { nodeId }) => nodeId,
+ dismissHint: () => null,
+ },
+ ],
+ }),
+ selectors({
+ canShowHint: [
+ (s) => [s.featureFlags, s.user],
+ // An unloaded user is not a user who has seen nothing, so the hint waits rather than
+ // opening once on every page load and closing again when the user arrives.
+ (featureFlags: FeatureFlagsSet, user: UserType | null): boolean =>
+ !!featureFlags[FEATURE_FLAGS.REVAMPED_PY_NOTEBOOKS] &&
+ !!user &&
+ !user.has_seen_product_intro_for?.[NOTEBOOK_DATAFRAME_HINT_SEEN_KEY],
+ ],
+ }),
+ listeners(({ actions, values }) => ({
+ reportRunFinished: ({ nodeId, hasReturnVariable }) => {
+ // A cell that already names its output has nothing left to explain. One hint at a time
+ // too: a chain run finishes several cells, and the popover would hop between them.
+ if (!values.canShowHint || hasReturnVariable || values.hintNodeId) {
+ return
+ }
+ actions.showHint(nodeId)
+ },
+ dismissHint: () => {
+ actions.updateHasSeenProductIntroFor(NOTEBOOK_DATAFRAME_HINT_SEEN_KEY)
+ },
+ })),
+])
diff --git a/frontend/src/scenes/notebooks/Notebook/markdownNotebookRegistry.test.tsx b/frontend/src/scenes/notebooks/Notebook/markdownNotebookRegistry.test.tsx
index 8aefa3bcf3c9..5371597daf4f 100644
--- a/frontend/src/scenes/notebooks/Notebook/markdownNotebookRegistry.test.tsx
+++ b/frontend/src/scenes/notebooks/Notebook/markdownNotebookRegistry.test.tsx
@@ -45,7 +45,10 @@ jest.mock('./MarkdownNotebookEntityPicker', () => ({
// Mirrors how MarkdownNotebook composes its menu, so the assertions cover the list a user sees
// rather than the registry alone: built-in commands are not registry entries, so a node hidden
// from the registry can still reach the menu through a built-in that inserts the same tag.
-function getInsertCommandsByLabel(featureFlags: FeatureFlagsSet, label: string): { key: string; category: string }[] {
+function getInsertCommandsByLabel(
+ featureFlags: FeatureFlagsSet,
+ label: string
+): { key: string; category: string; badge?: string }[] {
const noop = (): void => {}
const commands = omitInsertCommands(
buildInsertCommands(
@@ -64,7 +67,7 @@ function getInsertCommandsByLabel(featureFlags: FeatureFlagsSet, label: string):
return commands
.filter((command) => command.label === label)
- .map((command) => ({ key: command.key, category: command.category }))
+ .map((command) => ({ key: command.key, category: command.category, badge: command.badge }))
}
describe('markdownNotebookRegistry', () => {
@@ -192,6 +195,14 @@ describe('markdownNotebookRegistry', () => {
expectedCommands
)
})
+
+ // Both the group and the badge come from the node's insertCommand override, so this also
+ // covers the badge surviving buildInsertCommands.
+ it('puts Python beside SQL in the top group, badged as new', () => {
+ expect(getInsertCommandsByLabel({ [FEATURE_FLAGS.REVAMPED_PY_NOTEBOOKS]: true }, 'Python')).toEqual([
+ { key: 'component-PythonV2', category: 'Common', badge: 'New' },
+ ])
+ })
})
it('does not make real notebook nodes mutually exclusive in markdown notebooks', () => {
diff --git a/frontend/src/scenes/notebooks/Notebook/markdownNotebookRegistry.tsx b/frontend/src/scenes/notebooks/Notebook/markdownNotebookRegistry.tsx
index 1c7d5ba10802..ac38135bcac7 100644
--- a/frontend/src/scenes/notebooks/Notebook/markdownNotebookRegistry.tsx
+++ b/frontend/src/scenes/notebooks/Notebook/markdownNotebookRegistry.tsx
@@ -253,6 +253,12 @@ export const MARKDOWN_NODE_DEFINITIONS: {
label: 'Python',
ToolbarComponent: NotebookCodeCellRunButton,
insertCommand: {
+ // Sits next to SQL in the menu's top group, because the two cells do the same job in
+ // a notebook. A separate "Code" group sits below the fold, where a person who is not
+ // already looking for Python does not find it. Only the menu grouping moves. The
+ // definition's category still drives the node's styling in the editor.
+ category: COMMON_INSERT_COMMAND_CATEGORY,
+ badge: 'New',
aliases: ['python', 'py'],
defaultProps: () => ({
...getDefaultPropsForNodeType(NotebookNodeType.PythonV2),
diff --git a/frontend/src/scenes/userLogic.ts b/frontend/src/scenes/userLogic.ts
index c35d853464c6..8f6966b29045 100644
--- a/frontend/src/scenes/userLogic.ts
+++ b/frontend/src/scenes/userLogic.ts
@@ -267,10 +267,10 @@ export interface userLogicActions {
teamId: number
}
updateHasSeenProductIntroFor: (
- productKey: ProductKey,
+ productKey: string | ProductKey,
value?: boolean
) => {
- productKey: ProductKey
+ productKey: string
value: boolean
}
updateMemberJoinEmailForAllOrganizations: (
@@ -428,7 +428,12 @@ export const userLogic = kea<userLogicType>([
}),
cancelEmailChangeRequest: true,
setUserScenePersonalisation: (scene: DashboardCompatibleScenes, dashboard: number) => ({ scene, dashboard }),
- updateHasSeenProductIntroFor: (productKey: ProductKey, value: boolean = true) => ({ productKey, value }),
+ // Not only product keys: the map also holds keys composed per team, and keys for surfaces
+ // that are not products, which is what the endpoint accepts.
+ updateHasSeenProductIntroFor: (productKey: ProductKey | string, value: boolean = true) => ({
+ productKey,
+ value,
+ }),
switchTeam: (teamId: string | number, destination?: string) => ({ teamId, destination }),
deleteUser: true,
updateWeeklyDigestForTeam: (teamId: number, enabled: boolean) => ({ teamId, enabled }),
diff --git a/products/mcp_analytics/frontend/firstLook/mcpFirstLookLogic.ts b/products/mcp_analytics/frontend/firstLook/mcpFirstLookLogic.ts
index 4c6742d98e04..062454161ad9 100644
--- a/products/mcp_analytics/frontend/firstLook/mcpFirstLookLogic.ts
+++ b/products/mcp_analytics/frontend/firstLook/mcpFirstLookLogic.ts
@@ -43,10 +43,10 @@ export interface mcpFirstLookLogicValues {
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface mcpFirstLookLogicActions {
updateHasSeenProductIntroFor: (
- productKey: ProductKey,
+ productKey: string,
value?: boolean | undefined
) => {
- productKey: ProductKey
+ productKey: string
value: boolean
} // userLogic
askMax: () => {
diff --git a/products/posthog_ai/frontend/logics/aiOnboardingLogic.ts b/products/posthog_ai/frontend/logics/aiOnboardingLogic.ts
index 00f5b443e1b4..da61876f24bc 100644
--- a/products/posthog_ai/frontend/logics/aiOnboardingLogic.ts
+++ b/products/posthog_ai/frontend/logics/aiOnboardingLogic.ts
@@ -60,10 +60,10 @@ export interface aiOnboardingLogicActions {
seed: ComposerSeed
} // composerSeedLogic
updateHasSeenProductIntroFor: (
- productKey: ProductKey,
+ productKey: string,
value?: boolean | undefined
) => {
- productKey: ProductKey
+ productKey: string
value: boolean
} // userLogic
clickGithubCta: () => {