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): show insights as selected (#57231)

Alex Lider33c2a337b3e1
diff --git a/frontend/src/scenes/notebooks/Nodes/NodeWrapper.scss b/frontend/src/scenes/notebooks/Nodes/NodeWrapper.scss
index 1147b22522e6..05f31061247d 100644
--- a/frontend/src/scenes/notebooks/Nodes/NodeWrapper.scss
+++ b/frontend/src/scenes/notebooks/Nodes/NodeWrapper.scss
@@ -61,10 +61,6 @@
}
}
- &--selected {
- --border-color: var(--border-bold);
- }
-
&--auto-hide-metadata {
--border-color: transparent;
@@ -106,6 +102,17 @@
}
}
+.ProseMirror.ProseMirror-focused {
+ .NotebookNode--selected {
+ --border-color: var(--border-bold);
+ }
+
+ .NotebookNode--in-selection .NotebookNode__box {
+ border-color: Highlight;
+ box-shadow: 0 0 0 1px Highlight;
+ }
+}
+
.NotebookNodeTitle {
padding: 0.25rem;
overflow: hidden;
diff --git a/frontend/src/scenes/notebooks/Nodes/NodeWrapper.tsx b/frontend/src/scenes/notebooks/Nodes/NodeWrapper.tsx
index 4438f12b36f3..e425730f9be3 100644
--- a/frontend/src/scenes/notebooks/Nodes/NodeWrapper.tsx
+++ b/frontend/src/scenes/notebooks/Nodes/NodeWrapper.tsx
@@ -529,7 +529,7 @@ export function createPostHogWidgetNode<T extends CustomNotebookNodeAttributes>(
const jsonAttr = (name: string): Record<string, any> => ({
parseHTML: (element: HTMLElement) => {
const raw = element.getAttribute(name)
- return raw === null ? null : JSON.parse(raw)
+ return raw ? JSON.parse(raw) : null
},
renderHTML: (attrs: Record<string, any>) => {
const value = attrs[name]
diff --git a/frontend/src/scenes/notebooks/Notebook/Editor.tsx b/frontend/src/scenes/notebooks/Notebook/Editor.tsx
index d55676aafbb0..dfa6582126d2 100644
--- a/frontend/src/scenes/notebooks/Notebook/Editor.tsx
+++ b/frontend/src/scenes/notebooks/Notebook/Editor.tsx
@@ -65,6 +65,7 @@ import { notebookCollabLogic } from './notebookCollabLogic'
import { NotebookDefaultBlockOnEnter } from './NotebookDefaultBlockOnEnter'
import { notebookLogic } from './notebookLogic'
import { NotebookTrailingParagraph } from './NotebookTrailingParagraph'
+import { RangeSelectedNodes } from './RangeSelectedNodes'
import { RemotePresenceExtension } from './RemotePresenceExtension'
import { SlashCommandsExtension } from './SlashCommands'
import { TableMenu } from './TableMenu'
@@ -173,6 +174,7 @@ export function Editor(): JSX.Element {
NotebookNodeCustomerJourney,
NotebookTrailingParagraph,
NotebookDefaultBlockOnEnter,
+ RangeSelectedNodes,
]
if (useCollab) {
diff --git a/frontend/src/scenes/notebooks/Notebook/RangeSelectedNodes.ts b/frontend/src/scenes/notebooks/Notebook/RangeSelectedNodes.ts
new file mode 100644
index 000000000000..d01ba00eb81d
--- /dev/null
+++ b/frontend/src/scenes/notebooks/Notebook/RangeSelectedNodes.ts
@@ -0,0 +1,44 @@
+import { Extension } from '@tiptap/core'
+import { Plugin, PluginKey } from '@tiptap/pm/state'
+import { Decoration, DecorationSet } from '@tiptap/pm/view'
+
+// This plugin decorates atom blocks (insights, sql, python, etc.)
+// so they can pick up the same highlight as a directly-selected node.
+const pluginKey = new PluginKey('rangeSelectedNodes')
+
+export const RangeSelectedNodes = Extension.create({
+ name: 'rangeSelectedNodes',
+
+ addProseMirrorPlugins() {
+ return [
+ new Plugin({
+ key: pluginKey,
+ props: {
+ decorations(state) {
+ const { from, to, empty } = state.selection
+ if (empty) {
+ return DecorationSet.empty
+ }
+ const decorations: Decoration[] = []
+ state.doc.nodesBetween(from, to, (node, pos) => {
+ if (!node.isAtom || !node.isBlock) {
+ return true
+ }
+ const nodeFrom = pos
+ const nodeTo = pos + node.nodeSize
+ if (from <= nodeFrom && nodeTo <= to) {
+ decorations.push(
+ Decoration.node(nodeFrom, nodeTo, {
+ class: 'NotebookNode--in-selection',
+ })
+ )
+ }
+ return false
+ })
+ return DecorationSet.create(state.doc, decorations)
+ },
+ },
+ }),
+ ]
+ },
+})