: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): edit cell titles on a single click (#106957)
Marius Andraf264381e2aea
diff --git a/docs/internal/generated-notebook-widgets.md b/docs/internal/generated-notebook-widgets.mdindex 344404f5a52f..326345c1e338 100644--- a/docs/internal/generated-notebook-widgets.md+++ b/docs/internal/generated-notebook-widgets.md@@ -154,6 +154,7 @@ Saved result reads remain available if the execution flags are disabled, subjectLoading a saved result does not execute a cell or mark dependent cells stale. If a saved run is unavailable, the preview stays visible and the cell offers a rerun.New notebooks place the typing caret in the title, including when opened through the command menu. Enter continues into the notebook body.+Click a cell's title or choose **Edit title** from its **More actions** menu to rename it without collapsing its panels. Enter or leaving the field saves; Escape cancels. The cell-type label toggles both panels, and the pencil toggles filters or the editor.The notebook's inline **Ask AI** uses LangGraph and receives widget authoring instructions when `notebook-generated-widgets` is enabled for the user.The bookmark toggle **Keep question with answer** is on by default, retaining the question and the submitting user's name above the answer. Turning it off saves `keepQuestion={false}` on that prompt.**Ask AI** is disabled until the organization approves AI data processing, including submission from saved prompt blocks.diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex e96279a0f5ad..a2e2fcd0423a 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -1457,9 +1457,9 @@ snapshots:components-markdown-notebook--headings-and-inline-formatting--light:hash: v1.k794b7964.be66956dde43302b0949635004901409dbb83c5aa238eedf0fff11259c3d0866.LMoCDLzrRGxJvUSGkhIBm8bk0sGPj3MIFOrAU5joD6wcomponents-markdown-notebook--invalid-component-props--dark:- hash: v1.k794b7964.9d65623b0cb2f2bcb8bbfde3e51c0cfc747028083c616d206379e805f81e388b.zthxB0ksZEjF823R41lOueqXNNaFojZb9vDQ5b1XAEs+ hash: v1.k794b7964.f47ab2306196df10800db3cb9dde827bec876ced8cac8cbe68cf399aeebd288f.AC_3u7uTRkGT1i7_XB22W4K-hF1QZNC6J81h_w8V1p0components-markdown-notebook--invalid-component-props--light:- hash: v1.k794b7964.dd6009f7833c93d42a2b94146e01a37d7405b488acd02f09d22ec60e8e06b3e0.HUJI6z64GSUKu6s3XHT6vBU_U6HyQIs1oY0lp3XGHoo+ hash: v1.k794b7964.a5ea6d150ca373ce61c6379619cc94838e7ef816d90a3229c38649e558772093.goH8usQMCh2a7yGUE2q1aHMlPBZ0tDXoofeJj2QNK0Qcomponents-markdown-notebook--lists-and-links--dark:hash: v1.k794b7964.6406692c418e6eb26b31ecca9bdb4a84382ea8ed3b4a31925e19b0c98a9958df.s5nbAvJpus5_pFfEPpqTm85_ilb7XIT-wYlQUX9K4gUcomponents-markdown-notebook--lists-and-links--light:diff --git a/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.test.ts b/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.test.tsindex 1d7670d5b544..daae7c445271 100644--- a/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.test.ts+++ b/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.test.ts@@ -9450,7 +9450,7 @@ After component`,)})- it('toggles both component panels from the title button', () => {+ it('collapses and restores component panels from the cell-type label', () => {const markdown = `<Query query={{"kind":"DataTableNode","source":{"kind":"EventsQuery"}}} />`const onChange = jest.fn()const { container, rerender } = render(createElement(MarkdownNotebook, { value: markdown, onChange }))@@ -9505,7 +9505,7 @@ After component`,)})- it('opens the default component panels from the title button without remembered panel state', () => {+ it('opens the default component panels from the cell-type label without remembered panel state', () => {const markdown = `<Query hideFilters hideResults query={{"kind":"DataTableNode","source":{"kind":"EventsQuery"}}} />`const onChange = jest.fn()const { container } = render(createElement(MarkdownNotebook, { value: markdown, onChange }))@@ -9653,9 +9653,7 @@ After component`,onChange,}))- fireEvent.doubleClick(- container.querySelector('.MarkdownNotebook__component-toolbar-title--button') as HTMLElement- )+ fireEvent.click(container.querySelector('.MarkdownNotebook__component-toolbar-title--button') as HTMLElement)const titleInput = container.querySelector('input.MarkdownNotebook__component-toolbar-title--input') as HTMLInputElement@@ -9677,9 +9675,7 @@ After component`,onChange,}))- fireEvent.doubleClick(- container.querySelector('.MarkdownNotebook__component-toolbar-title--button') as HTMLElement- )+ fireEvent.click(container.querySelector('.MarkdownNotebook__component-toolbar-title--button') as HTMLElement)const titleInput = container.querySelector('input.MarkdownNotebook__component-toolbar-title--input') as HTMLInputElement@@ -9721,9 +9717,7 @@ After component`,const { container } = render(createElement(MarkdownNotebook, { value: '<SummaryCard id="summary-id" />', registry }))- fireEvent.doubleClick(- container.querySelector('.MarkdownNotebook__component-toolbar-title--button') as HTMLElement- )+ fireEvent.click(container.querySelector('.MarkdownNotebook__component-toolbar-title--button') as HTMLElement)const titleInput = container.querySelector('input.MarkdownNotebook__component-toolbar-title--input') as HTMLInputElement@@ -9737,7 +9731,7 @@ After component`,it('does not suggest the query body or schema kinds as the title placeholder', () => {const getPlaceholder = (): string => {if (!container.querySelector('input.MarkdownNotebook__component-toolbar-title--input')) {- fireEvent.doubleClick(+ fireEvent.click(container.querySelector('.MarkdownNotebook__component-toolbar-title--button') as HTMLElement)}@@ -9765,7 +9759,7 @@ After component`,expect(placeholder).toEqual('Add a title')})- it('collapses single-mode component tags locally from the title button', () => {+ it('collapses single-mode component tags locally from the cell-type label', () => {const registry = createMarkdownNotebookRegistry([{tagName: 'SummaryCard',@@ -9839,7 +9833,7 @@ After component`,])const getTitleInput = (): HTMLInputElement => {if (!container.querySelector('input.MarkdownNotebook__component-toolbar-title--input')) {- fireEvent.doubleClick(+ fireEvent.click(container.querySelector('.MarkdownNotebook__component-toolbar-title--button') as HTMLElement)}@@ -9943,7 +9937,7 @@ After component`,expect(fallback?.querySelector('pre')).toBeNull()})- it('collapses unknown component tags locally from the title button', () => {+ it('collapses unknown component tags locally from the cell-type label', () => {const onChange = jest.fn()const { container } = render(createElement(MarkdownNotebook, { value: `<Tag foo="bar" />`, onChange }))const getTitleButton = (): HTMLButtonElement =>diff --git a/frontend/src/lib/components/MarkdownNotebook/NotebookComponentShell.test.tsx b/frontend/src/lib/components/MarkdownNotebook/NotebookComponentShell.test.tsxindex 1cd1a00ef30c..7d8731701516 100644--- a/frontend/src/lib/components/MarkdownNotebook/NotebookComponentShell.test.tsx+++ b/frontend/src/lib/components/MarkdownNotebook/NotebookComponentShell.test.tsx@@ -1,6 +1,6 @@-import { fireEvent, render, screen, within } from '@testing-library/react'+import { cleanup, fireEvent, render, screen, within } from '@testing-library/react'import userEvent from '@testing-library/user-event'-import { useContext, useEffect, useMemo } from 'react'+import { useContext, useEffect, useMemo, useState } from 'react'import { createPortal } from 'react-dom'import { useComponentPanelState } from './componentPanelContext'@@ -9,7 +9,7 @@ import { NotebookComponentRunStatusContext } from './componentRunStatus'import { NotebookComponentToolbarExtrasContext } from './componentToolbarExtras'import { NotebookComponentShell } from './NotebookComponentShell'import { createMarkdownNotebookRegistry } from './registry'-import { NotebookComponentRenderProps } from './types'+import { NotebookComponentBlockNode, NotebookComponentRenderProps } from './types'function PanelStateProbe(): JSX.Element {const panelState = useComponentPanelState()@@ -103,6 +103,73 @@ const RUN_SHORTCUTS: [string, { metaKey?: boolean; ctrlKey?: boolean; shiftKey?:]describe('NotebookComponentShell', () => {+ afterEach(cleanup)++ it.each([+ ['create', undefined, 'Weekly activity', 'Enter', 'Weekly activity'],+ ['rename', 'Original title', 'Updated title', 'Tab', 'Updated title'],+ ['cancel', 'Original title', 'Discarded title', 'Escape', 'Original title'],+ ['clear', 'Original title', '', 'Enter', undefined],+ ])('%s a title without collapsing the cell', async (action, initialTitle, draft, key, expectedTitle) => {+ const registry = createMarkdownNotebookRegistry([+ { tagName: 'Probe', label: 'Probe', category: 'Test', ViewComponent: PanelStateProbe },+ ])+ const setLocalComponentPanels = jest.fn()+ const rememberComponentPanels = jest.fn()+ const toggleComponentPanel = jest.fn()+ function EditableTitleProbe(): JSX.Element {+ const [node, setNode] = useState<NotebookComponentBlockNode>({+ id: 'probe-node',+ type: 'component',+ tagName: 'Probe',+ props: initialTitle ? { title: initialTitle } : {},+ })+ return (+ <NotebookComponentShell+ node={node}+ mode="edit"+ componentPanels={{ filters: false, results: true }}+ persistComponentPanelVisibility={false}+ isSelected={false}+ registry={registry}+ toggleComponentPanel={toggleComponentPanel}+ setLocalComponentPanels={setLocalComponentPanels}+ rememberComponentPanels={rememberComponentPanels}+ setBlockRef={jest.fn()}+ updateNode={(_nodeId, updater) =>+ setNode((current) => updater(current) as NotebookComponentBlockNode)+ }+ deleteNode={jest.fn()}+ deleteSelectedNotebookBlocks={jest.fn(() => false)}+ insertParagraphAfterNode={jest.fn()}+ moveFocusToAdjacentNode={jest.fn(() => false)}+ />+ )+ }++ render(<EditableTitleProbe />)+ if (action === 'rename') {+ await userEvent.click(screen.getByLabelText('More actions'))+ await userEvent.click(screen.getByText('Edit title'))+ } else {+ await userEvent.click(screen.getByText(initialTitle ?? 'Add a title'))+ }+ const input = screen.getByLabelText('Component title')+ expect(document.activeElement).toBe(input)+ await userEvent.clear(input)+ if (draft) {+ await userEvent.type(input, draft)+ }+ await userEvent.keyboard(`{${key}}`)++ expect(screen.queryByLabelText('Component title')).toBeNull()+ expect(screen.getByText(expectedTitle ?? 'Add a title')).toBeTruthy()+ expect(screen.getByTestId('panel-state').textContent).toBe('edit-closed view-open')+ expect(setLocalComponentPanels).not.toHaveBeenCalled()+ expect(rememberComponentPanels).not.toHaveBeenCalled()+ expect(toggleComponentPanel).not.toHaveBeenCalled()+ })+it('provides markdown component panel state to rendered components', () => {const registry = createMarkdownNotebookRegistry([{@@ -316,6 +383,7 @@ describe('NotebookComponentShell', () => {expect(screen.getByLabelText('More actions')).toBeTruthy()await userEvent.click(screen.getByLabelText('More actions'))expect(screen.queryByText('Change view')).toBeNull()+ expect(screen.queryByText('Edit title')).toBeNull()expect(screen.getByText('Refresh')).toBeTruthy()viewRender.unmount()})@@ -479,6 +547,7 @@ describe('NotebookComponentShell', () => {fireEvent.doubleClick(titleButton)expect(container.querySelector('.MarkdownNotebook__component-toolbar-title--input')).toBeNull()+ expect(screen.queryByLabelText('More actions')).toBeNull()fireEvent.click(screen.getByText('Enabled'))expect(toggleStatus).toHaveBeenCalledTimes(1)diff --git a/frontend/src/lib/components/MarkdownNotebook/NotebookComponentShell.tsx b/frontend/src/lib/components/MarkdownNotebook/NotebookComponentShell.tsxindex 465841648322..fea662838e99 100644--- a/frontend/src/lib/components/MarkdownNotebook/NotebookComponentShell.tsx+++ b/frontend/src/lib/components/MarkdownNotebook/NotebookComponentShell.tsx@@ -6,7 +6,6 @@ import {ReactNode,memo,useCallback,- useEffect,useMemo,useRef,useState,@@ -131,7 +130,7 @@ export function NotebookComponentShell({((mode === 'view' && !isViewModeCanvas) || componentPanels.results) &&!(showEditPanel && definition?.exclusiveEditPanel)const showModeActions = mode === 'edit' && !!definition && !definition.hideModeActions- // Edit mode already covers folding via the eye/title, so collapse only shows where those+ // Edit mode already covers folding via the eye/type label, so collapse only shows where those// controls don't render: read-only canvases.const showCollapseToggle = isViewModeCanvas && !!definition && !definition.hideModeActionsconst canToggleComponentPanels = mode === 'edit'@@ -168,6 +167,8 @@ export function NotebookComponentShell({}),[componentPanels, showEditPanel, showViewPanel])+ const [titleDraft, setTitleDraft] = useState<string | null>(null)+ const [isEditingTitle, setIsEditingTitle] = useState(false)const toolbarMenuItems = withoutNotebookMenuIcons([showResourceLink? {@@ -182,6 +183,7 @@ export function NotebookComponentShell({targetBlank: true,}: null,+ mode === 'edit' && isTitleEditable ? { label: 'Edit title', onClick: () => setIsEditingTitle(true) } : null,...(mode === 'edit'? (toolbarExtras?.actions.map((action) => ({label: action.text,@@ -194,20 +196,6 @@ export function NotebookComponentShell({mode === 'edit' && onBtw ? { label: 'BTW', onClick: onBtw, disabledReason: askAIDisabledReason } : null,])const hasToolbarMenu = toolbarMenuItems.some(Boolean)- const [titleDraft, setTitleDraft] = useState<string | null>(null)- const [isEditingTitle, setIsEditingTitle] = useState(false)- // A browser fires two `click`s before `dblclick`. Defer the title's collapse so a rename- // (double-click) can cancel it, otherwise renaming would collapse then restore the panels- // (a flicker) and persist the node twice.- const titleCollapseTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null)- useEffect(- () => () => {- if (titleCollapseTimerRef.current) {- clearTimeout(titleCollapseTimerRef.current)- }- },- []- )// Escape blurs the input, which fires commitTitle synchronously before the titleDraft// state update lands — this ref lets commitTitle see the cancel intent in that same tickconst cancellingTitleRef = useRef(false)@@ -453,18 +441,6 @@ export function NotebookComponentShell({event.preventDefault()event.stopPropagation()}- const handleTitleClick = (): void => {- if (!canToggleComponentPanels) {- return- }- if (titleCollapseTimerRef.current) {- clearTimeout(titleCollapseTimerRef.current)- }- titleCollapseTimerRef.current = setTimeout(() => {- titleCollapseTimerRef.current = null- toggleAllComponentPanels()- }, 250)- }return (<div@@ -550,21 +526,11 @@ export function NotebookComponentShell({onKeyDown={handleTitleKeyDown}/>) : isTitleEditable ? (- // Clicking the title collapses the whole cell (same as hiding both panels);- // double-click renames. No extra control is added to the toolbar.<buttontype="button"className="MarkdownNotebook__component-toolbar-title MarkdownNotebook__component-toolbar-title--button"title={resolvedTitle ?? titlePlaceholder}- aria-expanded={hasOpenComponentPanel}- onClick={handleTitleClick}- onDoubleClick={() => {- if (titleCollapseTimerRef.current) {- clearTimeout(titleCollapseTimerRef.current)- titleCollapseTimerRef.current = null- }- setIsEditingTitle(true)- }}+ onClick={() => setIsEditingTitle(true)}>{resolvedTitle ?? (<span className="MarkdownNotebook__component-toolbar-title-placeholder">@@ -579,7 +545,7 @@ export function NotebookComponentShell({className="MarkdownNotebook__component-toolbar-title MarkdownNotebook__component-toolbar-title--button"title={resolvedTitle ?? titlePlaceholder}aria-expanded={hasOpenComponentPanel}- onClick={handleTitleClick}+ onClick={toggleAllComponentPanels}>{resolvedTitle ?? titlePlaceholder}</button>