Skip to content

refactor: update dependencies and improve graph handling#697

Open
Anchel123 wants to merge 1 commit into
stagingfrom
add-layouts
Open

refactor: update dependencies and improve graph handling#697
Anchel123 wants to merge 1 commit into
stagingfrom
add-layouts

Conversation

@Anchel123
Copy link
Copy Markdown
Contributor

@Anchel123 Anchel123 commented Jun 1, 2026

  • Changed the dependency for @falkordb/canvas to a local file reference.
  • Introduced graphDataToData function to standardize graph data handling across components.
  • Removed cooldownTicks state management and replaced it with animation state in multiple components.
  • Enhanced the Chat component to utilize createMessage for message creation, ensuring unique IDs.
  • Updated the Toolbar component to include animation controls and layout options.
  • Modified the Vite configuration to point to the production API endpoint.

Summary by CodeRabbit

  • New Features

    • Added layout configuration options (force, tree, radial layouts with direction selection) to toolbar
    • Added animation toggle and pin/unpin controls to toolbar
  • Improvements

    • Enhanced node label rendering with multi-line text and improved text contrast
    • Improved path selection logic and graph data conversion
    • Refactored message system with auto-generated IDs for better tracking

- Changed the dependency for @falkordb/canvas to a local file reference.
- Introduced graphDataToData function to standardize graph data handling across components.
- Removed cooldownTicks state management and replaced it with animation state in multiple components.
- Enhanced the Chat component to utilize createMessage for message creation, ensuring unique IDs.
- Updated the Toolbar component to include animation controls and layout options.
- Modified the Vite configuration to point to the production API endpoint.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 1, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

The PR modernizes the code graph canvas system by replacing cooldown-based timing with explicit animation state, reorganizing canvas event configuration, adding auto-increment message IDs, wrapping graph data conversions, and redesigning the toolbar with layout and pin controls while improving node label rendering with better typography and color contrast.

Changes

Animation & Graph Canvas Modernization

Layer / File(s) Summary
Foundation: Local Canvas, Animation State, and Message IDs
app/package.json, app/src/App.tsx, app/src/lib/utils.ts
Canvas dependency switches to local workspace path. Animation state (boolean) replaces cooldownTicks initialization. Message interface gains required id: number field with auto-incrementing createMessage helper in utils.
ForceGraph Configuration: Animation Effect and Event Handlers
app/src/components/ForceGraph.tsx
Props contract changes from cooldownTicks to animation: boolean. New useEffect calls canvas.setAnimation(animation) when animation or load state changes. Canvas event handlers (onNodeClick, onLinkHover, onZoom, etc.) move into single eventHandlers object; autoStopOnSettle: false removed.
Animation State Threading Through Component Hierarchy
app/src/App.tsx, app/src/components/code-graph.tsx, app/src/components/graphView.tsx, app/src/components/toolbar.tsx
Cooldownticks resets removed from graph-fetch and search flows. Animation and setter props thread from App → CodeGraph (desktop/mobile) → GraphView and Toolbar. Chat component no longer receives setCooldownTicks prop.
Graph Data Conversion Wrapper
app/src/App.tsx, app/src/components/code-graph.tsx, app/src/components/chat.tsx
All canvas.setGraphData(...) calls wrapped with graphDataToData() converter across visibility updates, category changes, node expansion/collapse, and path element insertion.
Chat Message System: IDs and Unified Construction
app/src/components/chat.tsx
Messages constructed via createMessage() helper throughout (query, pending, response, path, path-response). React list keys switch from index to message.id for stability. RemoveLastPath rewritten to optionally remove adjacent preceding Query via includeQuery parameter. Path zoom timing changes to 300ms with debug logging; path matching switches from set-based to order-aware node-id comparison.
Toolbar & Node Rendering: Layout Controls and Improved Labels
app/src/components/toolbar.tsx, app/src/components/graphView.tsx
Toolbar replaces cooldown switch with animation toggle (disabled when pinned or non-force layout), adds pin/unpin button, introduces layout dropdown with nested direction submenus for tree/radial modes. GraphView imports NODE_SIZE, text-wrapping, and contrast-color helpers from canvas; adds rendering constants for typography and stroke widths. Node labels rendered as wrapped multi-line text with zoom-level gating, contrast-aware fill color, and dynamic font sizing. handleEngineStop simplified to remove cooldown-related state updates.

Sequence Diagram(s)

sequenceDiagram
  participant Toolbar
  participant CodeGraph
  participant Canvas as Canvas (via<br/>ForceGraph)
  Toolbar->>Toolbar: user toggles animation
  Toolbar->>CodeGraph: setAnimation(boolean)
  CodeGraph->>CodeGraph: update local state
  CodeGraph->>Canvas: pass animation to ForceGraph
  Canvas->>Canvas: setAnimation effect runs
  Canvas->>Canvas: animation state updated
  Note over Canvas: physics engine uses animation flag
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

A rabbit hops through canvas bright,
Animation flows instead of ticks,
Message IDs dance with delight,
Toolbar pins and layouts mix—
The graph now spins with cleaner tricks! 🎨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main changes: refactoring cooldown/animation state management and improving graph data handling across multiple components via standardization utilities and dependency updates.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch add-layouts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.


const isHovered = !!hoverElement && !('source' in hoverElement) && hoverElement.id === node.id
const isSelected = selectedObjects.some(obj => obj.id === node.id) || selectedObj?.id === node.id
const nodeSelected = isSelected || isHovered
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (4)
app/src/components/graphView.tsx (2)

238-240: ⚖️ Poor tradeoff

Consider if zoom threshold is appropriate.

Labels are skipped when zoom < 1, which optimizes performance for large graphs. However, this threshold might hide labels at zoom levels where they're still readable. Consider if 0.5 or 0.75 might be more appropriate, or make it configurable.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/src/components/graphView.tsx` around lines 238 - 240, The label-skipping
threshold uses a hardcoded check (const zoom = ctx.getTransform().a; if (zoom <
1) return;) which may hide labels too aggressively; replace this magic number
with a configurable constant or prop (e.g., ZOOM_LABEL_THRESHOLD / prop like
labelZoomThreshold) and use that in the check (if (zoom < labelZoomThreshold)
return;), expose a sensible default (0.75 or 0.5) and update any relevant
component props or config in the GraphView rendering code so callers can tune
the threshold.

159-162: 💤 Low value

Verify intentional debouncing behavior.

lastClick.current.name is now reset to an empty string in both the double-click and isShowPath paths. This prevents rapid consecutive actions on the same node. Confirm this debouncing is intentional.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/src/components/graphView.tsx` around lines 159 - 162, The change resets
lastClick.current.name to an empty string in both the double-click branch and
the isShowPath branch which effectively disables rapid consecutive actions on
the same node; if this debouncing is not intended, remove the line that clears
lastClick.current.name from the isShowPath branch (keep it only where you call
handleExpand([node], !node.expand) or where double-click behavior is handled);
if it is intentional, add a brief code comment near lastClick/current and the
isShowPath branch documenting that clearing name is deliberate to debounce
repeated actions and reference the lastClick and handleExpand logic so future
readers understand the behavior.
app/src/components/chat.tsx (2)

12-15: ⚡ Quick win

Move the @falkordb/canvas import above the executable code.

This import is placed after the AUTH_HEADERS const declaration. While ES module imports are hoisted so this runs correctly, it's a code smell and will typically trip the import/first lint rule.

♻️ Proposed reorder
 import { Button } from "`@/components/ui/button`";
+import { dataToGraphData, graphDataToData, GraphLink, GraphNode } from "`@falkordb/canvas`";

 const AUTH_HEADERS: HeadersInit = import.meta.env.VITE_SECRET_TOKEN
     ? { 'Authorization': `Bearer ${import.meta.env.VITE_SECRET_TOKEN}` }
     : {};
-import { dataToGraphData, graphDataToData, GraphLink, GraphNode } from "`@falkordb/canvas`";
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/src/components/chat.tsx` around lines 12 - 15, Move the import statement
for "`@falkordb/canvas`" above any executable top-level code so imports come
first; specifically, relocate the line importing dataToGraphData,
graphDataToData, GraphLink, and GraphNode so it appears before the AUTH_HEADERS
constant declaration, ensuring imports are at the top to satisfy the
import/first lint rule and avoid mixing module imports with executable code.

230-235: ⚡ Quick win

Remove the console.log debug artifacts.

The two [zoomToFit] logs look like leftover debugging and will run on every path selection in production.

🧹 Proposed cleanup
         setTimeout(() => {
-            const filteredNodes = currentData.nodes.filter((n: any) => pNodeIds.has(n.id));
-            console.log('[zoomToFit] filtered nodes:', filteredNodes.map((n: any) => ({ id: n.id, x: n.x, y: n.y })));
-            console.log('[zoomToFit] pNodeIds:', [...pNodeIds]);
             canvas.zoomToFit(2, (n: GraphNode) => pNodeIds.has(n.id));
         }, 300)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/src/components/chat.tsx` around lines 230 - 235, Remove the debug
console.log calls inside the setTimeout: eliminate both console.log('[zoomToFit]
filtered nodes:...' ) and console.log('[zoomToFit] pNodeIds:' ...), leaving the
logic that computes filteredNodes and the canvas.zoomToFit(2, (n: GraphNode) =>
pNodeIds.has(n.id)) call intact; ensure no other stray console logging remains
in this block (references: filteredNodes, pNodeIds, currentData.nodes,
canvas.zoomToFit).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@app/package.json`:
- Line 14: The package dependency "`@falkordb/canvas`" in app/package.json
currently points to a missing local path "file:../../falkordb-canvas" causing
TS2307; fix it by updating the dependency to a valid reference (either correct
the relative file: path to the actual local package location, replace it with
the workspace / monorepo package name if using workspaces, or point to a
published version on the registry), then ensure the target package exports
TypeScript declarations (include "types" or .d.ts files or set "declaration":
true in its tsconfig) so imports resolve correctly; look for the dependency
entry in app/package.json and adjust it and the referenced package's
package.json/tsconfig accordingly.

---

Nitpick comments:
In `@app/src/components/chat.tsx`:
- Around line 12-15: Move the import statement for "`@falkordb/canvas`" above any
executable top-level code so imports come first; specifically, relocate the line
importing dataToGraphData, graphDataToData, GraphLink, and GraphNode so it
appears before the AUTH_HEADERS constant declaration, ensuring imports are at
the top to satisfy the import/first lint rule and avoid mixing module imports
with executable code.
- Around line 230-235: Remove the debug console.log calls inside the setTimeout:
eliminate both console.log('[zoomToFit] filtered nodes:...' ) and
console.log('[zoomToFit] pNodeIds:' ...), leaving the logic that computes
filteredNodes and the canvas.zoomToFit(2, (n: GraphNode) => pNodeIds.has(n.id))
call intact; ensure no other stray console logging remains in this block
(references: filteredNodes, pNodeIds, currentData.nodes, canvas.zoomToFit).

In `@app/src/components/graphView.tsx`:
- Around line 238-240: The label-skipping threshold uses a hardcoded check
(const zoom = ctx.getTransform().a; if (zoom < 1) return;) which may hide labels
too aggressively; replace this magic number with a configurable constant or prop
(e.g., ZOOM_LABEL_THRESHOLD / prop like labelZoomThreshold) and use that in the
check (if (zoom < labelZoomThreshold) return;), expose a sensible default (0.75
or 0.5) and update any relevant component props or config in the GraphView
rendering code so callers can tune the threshold.
- Around line 159-162: The change resets lastClick.current.name to an empty
string in both the double-click branch and the isShowPath branch which
effectively disables rapid consecutive actions on the same node; if this
debouncing is not intended, remove the line that clears lastClick.current.name
from the isShowPath branch (keep it only where you call handleExpand([node],
!node.expand) or where double-click behavior is handled); if it is intentional,
add a brief code comment near lastClick/current and the isShowPath branch
documenting that clearing name is deliberate to debounce repeated actions and
reference the lastClick and handleExpand logic so future readers understand the
behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f5b0f6a2-2798-4305-a437-a072f011bb0e

📥 Commits

Reviewing files that changed from the base of the PR and between 9feb1b4 and eaef11e.

⛔ Files ignored due to path filters (1)
  • app/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (8)
  • app/package.json
  • app/src/App.tsx
  • app/src/components/ForceGraph.tsx
  • app/src/components/chat.tsx
  • app/src/components/code-graph.tsx
  • app/src/components/graphView.tsx
  • app/src/components/toolbar.tsx
  • app/src/lib/utils.ts

Comment thread app/package.json
},
"dependencies": {
"@falkordb/canvas": "^0.0.44",
"@falkordb/canvas": "file:../../falkordb-canvas",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify the local `@falkordb/canvas` package exists and has required files

# Check if the directory exists
if [ -d "../../falkordb-canvas" ]; then
  echo "✓ Directory exists at ../../falkordb-canvas"
  
  # Check for package.json
  if [ -f "../../falkordb-canvas/package.json" ]; then
    echo "✓ package.json found"
    cat ../../falkordb-canvas/package.json | jq '{name, version, main, types, exports}'
  else
    echo "✗ package.json NOT found"
  fi
  
  # Check for TypeScript definitions
  fd -e d.ts . ../../falkordb-canvas -x echo "Found: {}"
  
  # List directory structure
  tree -L 2 ../../falkordb-canvas || ls -la ../../falkordb-canvas
else
  echo "✗ Directory does NOT exist at ../../falkordb-canvas"
  echo "Current directory structure:"
  pwd
  ls -la ../..
fi

Repository: FalkorDB/code-graph

Length of output: 329


Critical: @falkordb/canvas local file:../../falkordb-canvas path is missing in this checkout (causes TS2307).

File: app/package.json (line 14)

The file:../../falkordb-canvas directory isn’t present in the repo checkout, so @falkordb/canvas can’t be resolved and TypeScript fails with TS2307. Fix the file: path to the actual location (or wire it via the workspace setup) and ensure the package exports/provides TypeScript type declarations.

🧰 Tools
🪛 GitHub Actions: Playwright Tests / test (2)

[error] Build step failed: 'npm run build' (runs 'tsc -b && vite build'). Command exited with a non-zero status due to the TypeScript error.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/package.json` at line 14, The package dependency "`@falkordb/canvas`" in
app/package.json currently points to a missing local path
"file:../../falkordb-canvas" causing TS2307; fix it by updating the dependency
to a valid reference (either correct the relative file: path to the actual local
package location, replace it with the workspace / monorepo package name if using
workspaces, or point to a published version on the registry), then ensure the
target package exports TypeScript declarations (include "types" or .d.ts files
or set "declaration": true in its tsconfig) so imports resolve correctly; look
for the dependency entry in app/package.json and adjust it and the referenced
package's package.json/tsconfig accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant