Skip to content

fix(notes): make drag-and-drop reorder and grouping work end to end#107

Open
sricharan12-hub wants to merge 1 commit into
niharika-mente:mainfrom
sricharan12-hub:fix/drag-drop-reorder-grouping
Open

fix(notes): make drag-and-drop reorder and grouping work end to end#107
sricharan12-hub wants to merge 1 commit into
niharika-mente:mainfrom
sricharan12-hub:fix/drag-drop-reorder-grouping

Conversation

@sricharan12-hub

Copy link
Copy Markdown

Overview

Makes note drag-and-drop reordering and grouping/stacking work end to end.
Previously the feature was only partially wired: the drag events were never bound,
the API endpoints it called did not exist, and the frontend used a groupId field
that is not part of the Note schema — so reordering/grouping did nothing or 404'd.

Closes #80

Root causes fixed

  1. Drag handlers never attachedNoteCard now sets draggable and binds
    onDragStart / onDragOver / onDrop / onDragEnd.
  2. Missing / undefined props & stateNoteCard destructures all required
    props (activeDragId, setActiveDragId, allNotes, onMoveNote,
    onCombineNotes, onReorderNotes) and owns its own drag-indicator state,
    removing the undefined setDragIndicator / setChildDragIndicator references
    that would have thrown ReferenceError.
  3. Endpoints didn't exist — added PATCH /notes/:id/reorder and
    POST /notes/group in routes + controllers.
  4. Schema/field mismatch — standardized on parentId (already in the schema)
    everywhere; removed the non-existent groupId.

Changes

Backend

  • PATCH /notes/:id/reorder — repositions a note among its siblings and, when a
    parentId is supplied, moves it into that container; renumbers position
    sequentially. Body: { targetId?, parentId? }.
  • POST /notes/group — creates an isGroup: true note and sets both notes'
    parentId to it. Body: { sourceId, targetId, title }.
  • Every query is scoped to req.user._id; ids validated with
    mongoose.Types.ObjectId.isValid.
  • getAllNotes now sorts by position so a reorder persists across refresh.

Frontend

  • NoteCard.jsx: full drag wiring, before/after/stack indicators, and grouped
    notes rendered stacked under their group card.
  • HomePage.jsx: topLevelNotes filters on parentId; reorder/group handlers
    apply the authoritative note list returned by the endpoints.

Acceptance criteria

  • Dragging a note onto another reorders it, and the new order persists after refresh.
  • Dragging one note onto another can create a named group, and grouped notes render stacked.
  • No 404s on /notes/:id/reorder or /notes/group; no ReferenceError during drag.
  • Frontend and backend use a single consistent field name (parentId) for grouping.

Testing

  • eslint passes on HomePage.jsx and NoteCard.jsx; node --check passes on the
    backend controller and routes.
  • Simulated the reorder insertion/renumbering algorithm across representative cases
    (top-level reorder, move into group, append to group, reorder within group) — all
    produce correct sequential position values and parentId updates.

Note: this repo has no automated test suite or local DB wired up, so backend
handlers were verified via static checks and an algorithm simulation rather than a
live integration run.

Reordering and grouping on the home page were only partially wired:
drag events were never attached, the API endpoints did not exist, and
the frontend used a groupId field absent from the Note schema.

Backend:
- Add PATCH /notes/:id/reorder — repositions a note among its siblings
  (optionally moving it into a different container via parentId) and
  renumbers position sequentially.
- Add POST /notes/group — creates an isGroup note and assigns the two
  source/target notes' parentId to it.
- Both scope every query to req.user._id and validate ids with
  mongoose.Types.ObjectId.isValid.
- Sort getAllNotes by position so a reorder persists across refresh.

Frontend:
- NoteCard: bind draggable + onDragStart/onDragOver/onDrop/onDragEnd,
  destructure all required props, and add local drag-indicator state
  (removing the undefined setDragIndicator/setChildDragIndicator refs).
  Render group notes with their children stacked.
- HomePage: use parentId consistently (replacing the non-existent
  groupId) and drive reorder/group handlers off the authoritative note
  list returned by the endpoints.

Closes niharika-mente#80
@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@sricharan12-hub, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 44 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: df6b3b6c-42f1-41f3-bca6-d4de4078edfa

📥 Commits

Reviewing files that changed from the base of the PR and between 87148ba and 6ccea76.

📒 Files selected for processing (4)
  • backend/src/controllers/notesController.js
  • backend/src/routes/notesRoutes.js
  • frontend/src/components/NoteCard.jsx
  • frontend/src/pages/HomePage.jsx
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

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.

Drag-and-drop reordering and note grouping is non-functional (missing endpoints, unwired handlers, schema mismatch)

1 participant