Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

improvement: add 'jump to focused cell' in the dependency viewer (#2578)

Myles Scolnickadbe1a5c6db2
diff --git a/frontend/src/components/dependency-graph/dependency-graph-tree.tsx b/frontend/src/components/dependency-graph/dependency-graph-tree.tsx
index 6fb56be92d..7b1465321f 100644
--- a/frontend/src/components/dependency-graph/dependency-graph-tree.tsx
+++ b/frontend/src/components/dependency-graph/dependency-graph-tree.tsx
@@ -7,6 +7,8 @@ import ReactFlow, {
BackgroundVariant,
type Node,
type Edge,
+ ControlButton,
+ useReactFlow,
} from "reactflow";
import React, {
@@ -31,6 +33,10 @@ import useEvent from "react-use-event-hook";
import { scrollAndHighlightCell } from "../editor/links/cell-link";
import { GraphSelectionPanel } from "./panels";
import { useFitToViewOnDimensionChange } from "./utils/useFitToViewOnDimensionChange";
+import { MapPinIcon } from "lucide-react";
+import { store } from "@/core/state/jotai";
+import { lastFocusedCellIdAtom } from "@/core/cells/focus";
+import { Tooltip } from "../ui/tooltip";
interface Props {
cellIds: CellId[];
@@ -68,6 +74,7 @@ export const DependencyGraphTree: React.FC<PropsWithChildren<Props>> = ({
const [nodes, setNodes, onNodesChange] = useNodesState(initial.nodes);
const [edges, setEdges, onEdgesChange] = useEdgesState(initial.edges);
+ const api = useReactFlow();
const syncChanges = useEvent(
(elements: { nodes: Array<Node<NodeData>>; edges: Edge[] }) => {
@@ -127,7 +134,41 @@ export const DependencyGraphTree: React.FC<PropsWithChildren<Props>> = ({
nodesConnectable={false}
>
<Background color="#ccc" variant={BackgroundVariant.Dots} />
- <Controls position="bottom-right" showInteractive={false} />
+ <Controls position="bottom-right" showInteractive={false}>
+ <Tooltip
+ content="Jump to focused cell"
+ usePortal={false}
+ delayDuration={200}
+ side="left"
+ asChild={false}
+ >
+ <ControlButton
+ onMouseDown={(e) => {
+ // Prevent focus moving to the control button
+ e.preventDefault();
+ }}
+ onClick={() => {
+ const lastFocusedCell = store.get(lastFocusedCellIdAtom);
+ // Zoom the graph to the last focused cell
+ if (lastFocusedCell) {
+ const node = nodes.find(
+ (node) => node.id === lastFocusedCell,
+ );
+ if (node) {
+ api.fitView({
+ padding: 1,
+ duration: 600,
+ nodes: [node],
+ });
+ setSelection({ type: "node", id: lastFocusedCell });
+ }
+ }
+ }}
+ >
+ <MapPinIcon className="size-4" />
+ </ControlButton>
+ </Tooltip>
+ </Controls>
<GraphSelectionPanel
selection={selection}
variables={variables}
diff --git a/frontend/src/components/dependency-graph/panels.tsx b/frontend/src/components/dependency-graph/panels.tsx
index c3bce45480..9a82fd7a52 100644
--- a/frontend/src/components/dependency-graph/panels.tsx
+++ b/frontend/src/components/dependency-graph/panels.tsx
@@ -253,7 +253,10 @@ export const GraphSelectionPanel: React.FC<{
};
return (
- <Panel position="bottom-left" className="max-h-[90%] flex flex-col">
+ <Panel
+ position="bottom-left"
+ className="max-h-[90%] flex flex-col w-[calc(100%-5rem)]"
+ >
<div className="min-h-[100px] shadow-md rounded-md border max-w-[550px] border-primary/40 my-4 min-w-[240px] bg-[var(--slate-1)] text-muted-foreground/80 flex flex-col overflow-y-auto">
{renderSelection()}
</div>
diff --git a/frontend/src/core/cells/focus.ts b/frontend/src/core/cells/focus.ts
index 14a5bafed8..c83071fe56 100644
--- a/frontend/src/core/cells/focus.ts
+++ b/frontend/src/core/cells/focus.ts
@@ -8,7 +8,7 @@ import type { CellConfig, RuntimeState } from "../network/types";
/**
* Holds state for the last focused cell.
*/
-const lastFocusedCellIdAtom = atom<CellId | null>(null);
+export const lastFocusedCellIdAtom = atom<CellId | null>(null);
export function useLastFocusedCellId() {
return useAtomValue(lastFocusedCellIdAtom);