refactor(workflow-dashboard): reduce cyclomatic complexity in editor #455

Merged
xiaomo merged 2 commits from fix/449-reduce-dashboard-complexity into main 2026-05-24 03:44:09 +00:00
Owner

What

Refactored the workflow-dashboard package to reduce cyclomatic complexity in editor-related handlers and components.

Why

Biome's noExcessiveCognitiveComplexity rule flagged several functions as exceeding the max complexity of 15. This refactor brings them within limits, improving maintainability and readability.

Changes

  • Split complex handler functions into smaller, focused helpers
  • Replaced optional properties (?:) with T | null per project conventions
  • Ensured all modified files pass bun run check

Ref

Fixes #449

## What Refactored the `workflow-dashboard` package to reduce cyclomatic complexity in editor-related handlers and components. ## Why Biome's `noExcessiveCognitiveComplexity` rule flagged several functions as exceeding the max complexity of 15. This refactor brings them within limits, improving maintainability and readability. ## Changes - Split complex handler functions into smaller, focused helpers - Replaced optional properties (`?:`) with `T | null` per project conventions - Ensured all modified files pass `bun run check` ## Ref Fixes #449
xingyue added 2 commits 2026-05-23 16:55:27 +00:00
- Extract helpers in assignLayers (bfsLayers, processTarget, placeIsolatedNodes, maxLayerExcludingEnd) to reduce complexity from 26 → ≤15
- Extract isProtectedNode and isFirstConditionalSibling helpers in onBeforeDelete (20 → ≤15)
- Extract handleEscape and handleUndoRedo in handleKeyDown (23 → ≤15)
- Extract buildNodeMap, sortTransitions, buildStepEdges, pushStepEdges, assignTargetHandles in transIn (33 → ≤15)
- Extract validateRoleNodeEdges and hasEmptyConditionOnIfEdge in validateRoleNodes (22 → ≤15)
- Remove unused state parameter from Form component in add-node.tsx
- Add vitest + 19 tests covering all refactored functions

Co-Authored-By: Claude Sonnet 4 <noreply@anthropic.com>
Per CLAUDE.md convention, use `string | null` instead of `?:` in the
isFirstConditionalSibling helper function parameter types.

Co-Authored-By: Claude Sonnet 4 <noreply@anthropic.com>
xiaomo approved these changes 2026-05-24 03:44:07 +00:00
xiaomo left a comment
Owner

LGTM 纯提取重构,行为保持正确,新增测试覆盖 layout/transIn/validate。

LGTM ✅ 纯提取重构,行为保持正确,新增测试覆盖 layout/transIn/validate。
xiaomo merged commit 0fdc0fdec3 into main 2026-05-24 03:44:09 +00:00
Sign in to join this conversation.
No Reviewers
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/workflow#455