: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): Fixes people node in markdown notebooks, enables filtering (#65214)
Sinan Kucukkoselera61b958b27e2
diff --git a/frontend/src/lib/components/MarkdownNotebook/InsertMenu.tsx b/frontend/src/lib/components/MarkdownNotebook/InsertMenu.tsxindex d3b4cbca3ffa..5393fc9a0d3a 100644--- a/frontend/src/lib/components/MarkdownNotebook/InsertMenu.tsx+++ b/frontend/src/lib/components/MarkdownNotebook/InsertMenu.tsx@@ -3,6 +3,10 @@ import { ReactNode, type CSSProperties, useEffect, useRef } from 'react'import { IconCode, IconDatabase, IconGraph, IconList, IconPencil, IconSparkles } from '@posthog/icons'+import { Scene } from 'scenes/sceneTypes'++import { ProductKey } from '~/queries/schema/schema-general'+import {INSERT_MENU_GAP,INSERT_MENU_MAX_HEIGHT,@@ -314,7 +318,19 @@ export function buildInsertCommands(label: 'People',category: 'Data',icon: <IconList />,- run: (targetNodeId) => insertRegisteredComponent(targetNodeId, 'Person'),+ run: (targetNodeId) =>+ insertComponent(targetNodeId, 'Query', {+ query: {+ kind: 'DataTableNode',+ source: {+ kind: 'ActorsQuery',+ select: ['person_display_name -- Person', 'id', 'created_at'],+ // ActorsQuery hits ClickHouse, which requires a product query tag.+ // Match the notebook query tagging convention (see NotebookSQLEditor).+ tags: { productKey: ProductKey.NOTEBOOKS, scene: Scene.Notebook },+ },+ },+ }),},{key: 'data-session-recordings',diff --git a/frontend/src/lib/components/MarkdownNotebook/NotebookComponentShell.tsx b/frontend/src/lib/components/MarkdownNotebook/NotebookComponentShell.tsxindex 5c416fc9f7a7..052fb16dc737 100644--- a/frontend/src/lib/components/MarkdownNotebook/NotebookComponentShell.tsx+++ b/frontend/src/lib/components/MarkdownNotebook/NotebookComponentShell.tsx@@ -1,7 +1,7 @@import clsx from 'clsx'import { KeyboardEvent, ReactNode, memo, useState } from 'react'-import { IconDatabase, IconEye, IconGraph, IconHide, IconList, IconPencil, IconTrash } from '@posthog/icons'+import { IconDatabase, IconEye, IconGraph, IconHide, IconList, IconPencil, IconPeople, IconTrash } from '@posthog/icons'import { LemonButton } from '@posthog/lemon-ui'import { PostHogErrorBoundary } from '@posthog/react'@@ -459,6 +459,9 @@ export function getQueryComponentTitleDisplay(if (sourceKind === 'EventsQuery') {return { label: 'Events', tone: 'data', icon: <IconList /> }}+ if (sourceKind === 'ActorsQuery') {+ return { label: 'People', tone: 'data', icon: <IconPeople /> }+ }return {label: definition?.label ?? node.tagName,diff --git a/frontend/src/lib/components/MarkdownNotebook/utils.ts b/frontend/src/lib/components/MarkdownNotebook/utils.tsindex 2f4cf4613815..657a8051b7c5 100644--- a/frontend/src/lib/components/MarkdownNotebook/utils.ts+++ b/frontend/src/lib/components/MarkdownNotebook/utils.ts@@ -5,6 +5,7 @@ import {NotebookInlineMark,NotebookInlineNode,NotebookListItem,+ NotebookPropValue,} from './types'export function hashString(value: string): string {@@ -292,6 +293,20 @@ export function isNotebookPropValue(value: unknown): value is NotebookComponentPreturn false}+// Project a value onto the serializable NotebookPropValue space — the same JSON.stringify+// normalization markdown serialization applies — dropping nested `undefined` (e.g. an absent+// `label`/`group_type_index` on a person-property filter inside a query). Counterpart to the+// isNotebookPropValue guard: where the guard rejects dirty values, this cleans them. Returns+// `undefined` for values JSON can't represent (top-level `undefined`, functions, symbols), so+// callers can omit the key entirely.+export function toSerializablePropValue(value: unknown): NotebookPropValue | undefined {+ const serialized = JSON.stringify(value)+ if (serialized === undefined) {+ return undefined+ }+ return JSON.parse(serialized) as NotebookPropValue+}+function sortProps(props: NotebookComponentProps): NotebookComponentProps {return Object.keys(props).sort()diff --git a/frontend/src/scenes/notebooks/Notebook/markdownNotebookRegistry.test.tsx b/frontend/src/scenes/notebooks/Notebook/markdownNotebookRegistry.test.tsxindex ad9978414571..8ad7543c8e02 100644--- a/frontend/src/scenes/notebooks/Notebook/markdownNotebookRegistry.test.tsx+++ b/frontend/src/scenes/notebooks/Notebook/markdownNotebookRegistry.test.tsx@@ -8,6 +8,7 @@ import {getEditableNodeAttributeKeys,getMarkdownNodeAttributeLabel,getSerializableAttributeInputValue,+ getSerializableProps,} from './markdownNotebookRegistry'describe('markdownNotebookRegistry', () => {@@ -74,4 +75,62 @@ describe('markdownNotebookRegistry', () => {'not-a-number')})++ describe('getSerializableProps', () => {+ it('preserves a query whose nested filter carries undefined fields, stripping the undefined', () => {+ // Regression: a completed person-property filter from the DataTable arrives with absent+ // label/group_type_index as `undefined`. Previously the whole `query` prop was dropped,+ // so the People table never re-queried when a filter was added.+ const result = getSerializableProps({+ query: {+ kind: 'DataTableNode',+ source: {+ kind: 'ActorsQuery',+ properties: [+ { type: 'person', key: 'email', operator: 'exact', value: '[email protected]', label: undefined },+ ],+ },+ },+ })++ expect(result.query).toEqual({+ kind: 'DataTableNode',+ source: {+ kind: 'ActorsQuery',+ properties: [{ type: 'person', key: 'email', operator: 'exact', value: '[email protected]' }],+ },+ })+ })++ it('keeps a fully-serializable filter (e.g. cohort) untouched', () => {+ const query = {+ kind: 'DataTableNode',+ source: {+ kind: 'ActorsQuery',+ properties: [{ type: 'cohort', key: 'id', value: 42, operator: 'in' }],+ },+ }++ expect(getSerializableProps({ query }).query).toEqual(query)+ })++ it.each([+ ['undefined', { a: undefined }, {}],+ ['function', { a: () => undefined }, {}],+ ])('omits the key entirely when the value is not serializable (%s)', (_label, attributes, expected) => {+ expect(getSerializableProps(attributes as any)).toEqual(expected)+ })++ it('preserves primitive, array and nested object props', () => {+ expect(+ getSerializableProps({ id: 'abc', count: 3, enabled: true, items: ['a', 'b'], nested: { x: 1 } } as any)+ ).toEqual({ id: 'abc', count: 3, enabled: true, items: ['a', 'b'], nested: { x: 1 } })+ })++ it('strips undefined nested in an object while keeping its siblings', () => {+ expect(getSerializableProps({ nested: { keep: 'yes', drop: undefined } } as any)).toEqual({+ nested: { keep: 'yes' },+ })+ })+ })})diff --git a/frontend/src/scenes/notebooks/Notebook/markdownNotebookRegistry.tsx b/frontend/src/scenes/notebooks/Notebook/markdownNotebookRegistry.tsxindex 375f88db4730..944624796376 100644--- a/frontend/src/scenes/notebooks/Notebook/markdownNotebookRegistry.tsx+++ b/frontend/src/scenes/notebooks/Notebook/markdownNotebookRegistry.tsx@@ -48,7 +48,7 @@ import {NotebookComponentRegistry,NotebookPropValue,} from 'lib/components/MarkdownNotebook/types'-import { isNotebookPropValue } from 'lib/components/MarkdownNotebook/utils'+import { isNotebookPropValue, toSerializablePropValue } from 'lib/components/MarkdownNotebook/utils'import { NODE_ICONS } from '../nodeIcons'import { NotebookNodeContext } from '../Nodes/NotebookNodeContext'@@ -714,8 +714,13 @@ export function getSerializableAttributeInputValue(export function getSerializableProps(attributes: Partial<NotebookNodeAttributes<any>>): NotebookComponentProps {return Object.entries(attributes).reduce<NotebookComponentProps>((props, [key, value]) => {- if (value !== undefined && isNotebookPropValue(value)) {- props[key] = value as NotebookPropValue+ // Normalize before validating, mirroring the legacy notebook flow(via useSyncedAttributes).+ // Otherwise isNotebookPropValue rejects an object with a single nested `undefined` property and—+ // it gets ignored. e.g. a person-property filter's absent `label`/`group_type_index` inside+ // `query.source.properties` — fails isNotebookPropValue and the whole `query` prop is dropped+ const normalized = toSerializablePropValue(value)+ if (normalized !== undefined && isNotebookPropValue(normalized)) {+ props[key] = normalized}return props}, {})