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.

feat: add toggle to hide reusable functions from dependency graph (#8228)

Ahmad Yasser6981ab792f0e
diff --git a/frontend/src/components/dependency-graph/dependency-graph-tree.tsx b/frontend/src/components/dependency-graph/dependency-graph-tree.tsx
index 3e877deae4..23481a6cce 100644
--- a/frontend/src/components/dependency-graph/dependency-graph-tree.tsx
+++ b/frontend/src/components/dependency-graph/dependency-graph-tree.tsx
@@ -58,6 +58,7 @@ export const DependencyGraphTree: React.FC<PropsWithChildren<Props>> = ({
cellAtoms,
variables,
settings.hidePureMarkdown,
+ settings.hideReusableFunctions,
);
elements = layoutElements({
nodes: elements.nodes,
@@ -94,9 +95,17 @@ export const DependencyGraphTree: React.FC<PropsWithChildren<Props>> = ({
cellAtoms,
variables,
settings.hidePureMarkdown,
+ settings.hideReusableFunctions,
),
);
- }, [cellIds, variables, cellAtoms, syncChanges, settings.hidePureMarkdown]);
+ }, [
+ cellIds,
+ variables,
+ cellAtoms,
+ syncChanges,
+ settings.hidePureMarkdown,
+ settings.hideReusableFunctions,
+ ]);
const [selection, setSelection] = useState<GraphSelection>();
useFitToViewOnDimensionChange();
diff --git a/frontend/src/components/dependency-graph/dependency-graph.tsx b/frontend/src/components/dependency-graph/dependency-graph.tsx
index ef5fa6bf02..bf9f3d3422 100644
--- a/frontend/src/components/dependency-graph/dependency-graph.tsx
+++ b/frontend/src/components/dependency-graph/dependency-graph.tsx
@@ -24,6 +24,7 @@ interface Props {
const graphViewAtom = atom<LayoutDirection>("TB");
const graphViewSettings = atom<GraphSettings>({
hidePureMarkdown: true,
+ hideReusableFunctions: false,
});
export const DependencyGraph: React.FC<Props> = (props) => {
diff --git a/frontend/src/components/dependency-graph/elements.ts b/frontend/src/components/dependency-graph/elements.ts
index db02545d03..bd8e10cf1f 100644
--- a/frontend/src/components/dependency-graph/elements.ts
+++ b/frontend/src/components/dependency-graph/elements.ts
@@ -2,6 +2,7 @@
import type { Atom } from "jotai";
import { type Edge, MarkerType, type Node, type NodeProps } from "reactflow";
+import { getNotebook } from "@/core/cells/cells";
import type { CellId } from "@/core/cells/ids";
import type { CellData } from "@/core/cells/types";
import { store } from "@/core/state/jotai";
@@ -29,6 +30,7 @@ interface ElementsBuilder {
cellAtoms: Atom<CellData>[],
variables: Variables,
hidePureMarkdown: boolean,
+ hideReusableFunctions: boolean,
) => { nodes: Node<NodeData>[]; edges: Edge[] };
}
@@ -76,6 +78,7 @@ export class VerticalElementsBuilder implements ElementsBuilder {
cellAtoms: Atom<CellData>[],
variables: Variables,
_hidePureMarkdown: boolean,
+ _hideReusableFunctions: boolean,
) {
let prevY = 0;
const nodes: Node<NodeData>[] = [];
@@ -143,6 +146,7 @@ export class TreeElementsBuilder implements ElementsBuilder {
cellAtoms: Atom<CellData>[],
variables: Variables,
hidePureMarkdown: boolean,
+ hideReusableFunctions: boolean,
) {
const nodes: Node<NodeData>[] = [];
const edges: Edge[] = [];
@@ -171,18 +175,25 @@ export class TreeElementsBuilder implements ElementsBuilder {
}
}
- for (const [cellId, cellAtom] of Arrays.zip(cellIds, cellAtoms)) {
- // Show every cell
- if (!hidePureMarkdown) {
- nodes.push(this.createNode(cellId, cellAtom));
- }
+ const cellRuntime = getNotebook().cellRuntime;
+ for (const [cellId, cellAtom] of Arrays.zip(cellIds, cellAtoms)) {
+ const code = store.get(cellAtom).code.trim();
const hasEdge = nodesWithEdges.has(cellId);
- const isMarkdown = store.get(cellAtom).code.trim().startsWith("mo.md");
- // Show only cells with edges or non-markdown cells
- if (hasEdge || !isMarkdown) {
- nodes.push(this.createNode(cellId, cellAtom));
+ const isMarkdown = code.startsWith("mo.md");
+ const runtime = cellRuntime[cellId];
+ const isReusable = runtime?.serialization?.toLowerCase() === "valid";
+
+ // Apply filters
+ if (hidePureMarkdown && isMarkdown && !hasEdge) {
+ continue;
+ }
+ if (hideReusableFunctions && isReusable && !hasEdge) {
+ continue;
}
+
+ // Show every cell that wasn't filtered out
+ nodes.push(this.createNode(cellId, cellAtom));
}
return { nodes, edges };
diff --git a/frontend/src/components/dependency-graph/panels.tsx b/frontend/src/components/dependency-graph/panels.tsx
index 33b3604f9f..6cca2c1c83 100644
--- a/frontend/src/components/dependency-graph/panels.tsx
+++ b/frontend/src/components/dependency-graph/panels.tsx
@@ -43,7 +43,8 @@ export const GraphToolbar: React.FC<Props> = memo(
onSettingsChange({ ...settings, [key]: value });
};
- const checkboxId = useId();
+ const markdownCheckboxId = useId();
+ const functionsCheckboxId = useId();
const settingsButton = (
<Popover>
@@ -54,16 +55,31 @@ export const GraphToolbar: React.FC<Props> = memo(
</PopoverTrigger>
<PopoverContent className="w-auto p-2 text-muted-foreground">
<div className="font-semibold pb-4">Settings</div>
- <div className="flex items-center gap-2">
- <Checkbox
- data-testid="hide-pure-markdown-checkbox"
- id={checkboxId}
- checked={settings.hidePureMarkdown}
- onCheckedChange={(checked) =>
- handleSettingChange("hidePureMarkdown", Boolean(checked))
- }
- />
- <Label htmlFor={checkboxId}>Hide pure markdown</Label>
+ <div className="flex flex-col gap-2">
+ <div className="flex items-center gap-2">
+ <Checkbox
+ data-testid="hide-pure-markdown-checkbox"
+ id={markdownCheckboxId}
+ checked={settings.hidePureMarkdown}
+ onCheckedChange={(checked) =>
+ handleSettingChange("hidePureMarkdown", Boolean(checked))
+ }
+ />
+ <Label htmlFor={markdownCheckboxId}>Hide pure markdown</Label>
+ </div>
+ <div className="flex items-center gap-2">
+ <Checkbox
+ data-testid="hide-reusable-functions-checkbox"
+ id={functionsCheckboxId}
+ checked={settings.hideReusableFunctions}
+ onCheckedChange={(checked) =>
+ handleSettingChange("hideReusableFunctions", Boolean(checked))
+ }
+ />
+ <Label htmlFor={functionsCheckboxId}>
+ Hide reusable functions
+ </Label>
+ </div>
</div>
</PopoverContent>
</Popover>
diff --git a/frontend/src/components/dependency-graph/types.ts b/frontend/src/components/dependency-graph/types.ts
index d3c6e8ad0d..c8ad8996bd 100644
--- a/frontend/src/components/dependency-graph/types.ts
+++ b/frontend/src/components/dependency-graph/types.ts
@@ -17,4 +17,5 @@ export type GraphSelection =
export interface GraphSettings {
hidePureMarkdown: boolean;
+ hideReusableFunctions: boolean;
}