feat: extract page tree logic into testable utility (#113)#117
Merged
Conversation
Co-authored-by: Ona <no-reply@ona.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Collaborator
Author
|
✅ UI verification passed — design spec compliance confirmed. This PR extracts pure logic functions from |
Collaborator
Author
|
✅ Post-merge verification passed. E2E suite: 35/42 passed, 4 did not run (dependent on a failed test). 3 pre-existing failures (unrelated to this PR's page-tree changes):
These tests exercise member management and search — code paths not touched by this PR. Ad-hoc smoke tests: All passed.
|
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #113
What
Extracts pure tree-manipulation logic from
src/components/sidebar/page-tree.tsx(836 lines) intosrc/lib/page-tree.ts— a side-effect-free utility module with no React or Supabase dependencies.How
New file:
src/lib/page-tree.ts— 10 exported functions:buildTree— flat pages → nestedTreeNode[]hierarchygetDescendantIds— collect all descendant IDs recursivelyfindNode— locate a node by ID in the treegetNextSiblingPosition— next available position among siblingsgetSortedSiblings— siblings sorted by positioncomputeSwapPositions— position swaps for move up/downcomputeNest— new parent_id and position for nesting under preceding siblingcomputeUnnest— parent_id, position, and sibling shifts for unnestingcomputeDrop— full update set for drag-and-drop (inside/before/after)TreeNodetype exportUpdated:
src/components/sidebar/page-tree.tsx— imports and uses the extracted functions. All Supabase mutation calls remain in the component. Also improved thefetchPageseffect to use an inline async function with cancellation cleanup (fixes a lint warning fromreact-hooks/set-state-in-effect).New file:
src/lib/page-tree.test.ts— 35 unit tests covering:Testing
pnpm lint✅pnpm typecheck✅pnpm test— 93 tests pass (35 new)pnpm test:e2e— 40 tests pass (includingpage-crud.spec.tsandsidebar-drag.spec.ts)