Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Tagnard
Copy link
Contributor

@Tagnard Tagnard commented Dec 2, 2025

fixes #1434

Summary by CodeRabbit

Release Notes

  • Refactor
    • Standardized DAG node identification methodology across all visualization and execution history components. This ensures consistent behavior during node selection, context menu interactions, diagram display, and multi-component navigation scenarios throughout the application.
    • Enhanced sub-run data aggregation by optimizing merging operations for improved code maintainability and performance consistency.

✏️ Tip: You can customize this high-level summary in your review settings.

Copy link
Collaborator

@yottahmd yottahmd left a comment

Choose a reason for hiding this comment

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

@Tagnard Thanks a ton! Sorry, the UI code is a bit sloppy and we have multiple occurrences of the same regex. Could you fix them all? Also, feel free to refactor the code if you see a better way.

(n) => n.step.name.replace(/[-\s]/g, 'dagutmp') == id

(n) => n.step.name.replace(/[-\s]/g, 'dagutmp') == id

(n) => n.step.name.replace(/[-\s]/g, 'dagutmp') == id

(n) => n.step.name.replace(/[-\s]/g, 'dagutmp') == id

@yottahmd
Copy link
Collaborator

yottahmd commented Dec 4, 2025

Hi @Tagnard, Thanks for the PR! Do you have time to work on this today? If you are busy, would you mind if I pushed changes to the branch? I'm planning to release the new version today and really want to get this fix included.

Consolidate the repeated regex pattern for converting step names to
valid Mermaid node IDs into a shared utility function. This improves
maintainability by having a single source of truth for the conversion
logic that handles spaces, dashes, and parentheses.
@yottahmd
Copy link
Collaborator

yottahmd commented Dec 4, 2025

I understand you're busy, please don't mind that I push some changes.

@coderabbitai
Copy link

coderabbitai bot commented Dec 4, 2025

Walkthrough

A new utility function toMermaidNodeId sanitizes step names into Mermaid-compatible node IDs by replacing spaces, hyphens, and parentheses. This function is integrated across DAG visualization components to ensure consistent identifier generation, addressing crashes caused by special characters in step names.

Changes

Cohort / File(s) Summary
New utility function
ui/src/lib/utils.ts
Added toMermaidNodeId(stepName: string): string to convert step names to Mermaid-safe IDs by replacing spaces, hyphens, and parentheses with "dagutmp".
DAG visualization components
ui/src/features/dags/components/DAGStatus.tsx, ui/src/features/dags/components/dag-execution/DAGExecutionHistory.tsx, ui/src/features/dags/components/visualization/Graph.tsx
Updated node ID generation to use toMermaidNodeId() instead of manual string manipulation. Replaced concatenation of subRuns arrays with spread operator syntax across multiple files. Imported new utility function.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Changes follow a consistent, repetitive pattern across three files (same utility function adoption)
  • New utility function is straightforward with minimal logic
  • No alterations to public API signatures or control flow
  • Consider verifying that the "dagutmp" replacement string is appropriate and handles all problematic Mermaid character cases

Poem

🐰 A step with parentheses bold,
Made the graph crash, or so we're told!
With dagutmp now standing guard,
Special chars pose no hard regard—
Mermaid nodes now render like gold! 🎉

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ 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 describes the main fix: preventing parentheses in step names from crashing the graph in the web UI, directly addressing issue #1434.
Linked Issues check ✅ Passed The pull request successfully addresses issue #1434 by introducing toMermaidNodeId utility to sanitize step names containing parentheses, preventing graph crashes.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the parentheses crash issue: new utility function, updated node ID generation in graph components, and consistent ID matching across DAG-related files.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Copy link

@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: 0

🧹 Nitpick comments (3)
ui/src/features/dags/components/DAGStatus.tsx (1)

7-7: Consistent use of toMermaidNodeId for graph node lookups

Switching both onSelectStepOnGraph and onRightClickStepOnGraph to use toMermaidNodeId(n.step.name) keeps the lookup logic aligned with how node IDs are generated in the graph, which should eliminate the crash when step names contain parentheses or spaces/dashes.

As a small follow‑up, you could tighten the comparisons to === since both sides are strings and there’s no need for type coercion, but the current logic is correct.

Also applies to: 100-103, 197-199

ui/src/lib/utils.ts (1)

8-16: Mermaid ID sanitizer looks good; consider more generalization later

The new toMermaidNodeId centralizes Mermaid ID normalization and directly handles the problematic characters (spaces, dashes, parentheses) that were crashing the graph, which is exactly what this bugfix needs.

If you see more issues with other special characters in the future, a possible follow‑up would be to broaden the regex to normalize any non‑alphanumeric/underscore character or to prefix IDs with a fixed namespace to further reduce theoretical collision risk. Not a blocker for this PR.

ui/src/features/dags/components/dag-execution/DAGExecutionHistory.tsx (1)

11-11: History view node matching correctly reuses toMermaidNodeId

Hooking both onSelectStepOnGraph and onRightClickStepOnGraph up to toMermaidNodeId(n.step.name) keeps the execution‑history graph interactions consistent with the main DAG view and the Graph component’s ID generation, so step names with parentheses or spaces now behave correctly here as well.

The merged subRuns array using [...(n.subRuns ?? []), ...(n.subRunsRepeated ?? [])] is also a tidy improvement and avoids repeated conditional logic. As in DAGStatus.tsx, you could optionally switch == to === when comparing IDs, but the current code is functionally correct.

Also applies to: 269-296, 301-327

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8b340e6 and dd913ac.

📒 Files selected for processing (4)
  • ui/src/features/dags/components/DAGStatus.tsx (3 hunks)
  • ui/src/features/dags/components/dag-execution/DAGExecutionHistory.tsx (3 hunks)
  • ui/src/features/dags/components/visualization/Graph.tsx (3 hunks)
  • ui/src/lib/utils.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
ui/**/*.{ts,tsx,jsx,js}

📄 CodeRabbit inference engine (ui/CLAUDE.md)

ui/**/*.{ts,tsx,jsx,js}: Use developer-centric UI design with high information density, minimal whitespace, compact components, and no unnecessary decorations
Support both light and dark modes for all UI components using Tailwind CSS class pairs like dark:bg-slate-700
NEVER use full-page loading overlays or LoadingIndicator components that hide content - show stale data while fetching updates instead
Use compact modal design with small headers, minimal padding (p-2 or p-3), tight spacing, and support keyboard navigation (arrows, enter, escape)
Use small heights for form elements: select boxes h-7 or smaller, buttons h-7 or h-8, inputs with compact padding (py-0.5 or py-1)
Minimize row heights in tables and lists while maintaining readability, merge related columns, and always handle long text with whitespace-normal break-words
Use consistent metadata styling with bg-slate-200 dark:bg-slate-700 backgrounds and maintain text hierarchy with primary/secondary/muted text colors
Use flexbox-first layouts with min-h-0 and overflow-hidden to prevent layout breaks, account for fixed elements when setting heights
Maintain keyboard navigation support in all interactive components with appropriate focus indicators and ARIA labels

Files:

  • ui/src/lib/utils.ts
  • ui/src/features/dags/components/DAGStatus.tsx
  • ui/src/features/dags/components/dag-execution/DAGExecutionHistory.tsx
  • ui/src/features/dags/components/visualization/Graph.tsx
ui/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

ui/**/*.{ts,tsx}: The React + TypeScript frontend resides in ui/, with production bundles copied to internal/service/frontend/assets by make ui
UI code follows ESLint + Prettier (2-space indent) and Tailwind utilities; name React components in PascalCase (JobList.tsx) and hooks with use* (useJobs.ts)

Files:

  • ui/src/lib/utils.ts
  • ui/src/features/dags/components/DAGStatus.tsx
  • ui/src/features/dags/components/dag-execution/DAGExecutionHistory.tsx
  • ui/src/features/dags/components/visualization/Graph.tsx
🧬 Code graph analysis (3)
ui/src/features/dags/components/DAGStatus.tsx (1)
ui/src/lib/utils.ts (1)
  • toMermaidNodeId (14-16)
ui/src/features/dags/components/dag-execution/DAGExecutionHistory.tsx (1)
ui/src/lib/utils.ts (1)
  • toMermaidNodeId (14-16)
ui/src/features/dags/components/visualization/Graph.tsx (1)
ui/src/lib/utils.ts (1)
  • toMermaidNodeId (14-16)
🔇 Additional comments (2)
ui/src/features/dags/components/DAGStatus.tsx (1)

107-107: Sub‑run merging is clearer and functionally equivalent

Using a single spread expression for allSubRuns = [...(n.subRuns || []), ...(n.subRunsRepeated || [])] is a nice simplification and matches how other components in this PR merge sub‑runs. Behavior stays the same while improving readability.

ui/src/features/dags/components/visualization/Graph.tsx (1)

7-7: Graph now aligns ID generation with shared sanitizer

Using toMermaidNodeId(step.name) for both the node id and each depId brings the Mermaid definition in line with how the click/right‑click handlers resolve nodes, and removes the raw parentheses from identifiers that were previously breaking the graph rendering.

This keeps the change tightly scoped to ID generation without affecting labels or layout, which is appropriate for the reported bug. If you later expand toMermaidNodeId (e.g., to normalize more characters), this file won’t need further changes.

Also applies to: 146-147, 187-190

@yottahmd yottahmd merged commit f622796 into dagu-org:main Dec 4, 2025
2 checks passed
@yottahmd
Copy link
Collaborator

yottahmd commented Dec 4, 2025

PR merged, thank you very much @Tagnard !

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.

Parentheses in step name crash graph in web UI

2 participants