fix(notes): make drag-and-drop reorder and grouping work end to end#107
fix(notes): make drag-and-drop reorder and grouping work end to end#107sricharan12-hub wants to merge 1 commit into
Conversation
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
|
Warning Review limit reached
Next review available in: 44 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
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
groupIdfieldthat is not part of the
Noteschema — so reordering/grouping did nothing or 404'd.Closes #80
Root causes fixed
NoteCardnow setsdraggableand bindsonDragStart/onDragOver/onDrop/onDragEnd.NoteCarddestructures all requiredprops (
activeDragId,setActiveDragId,allNotes,onMoveNote,onCombineNotes,onReorderNotes) and owns its own drag-indicator state,removing the undefined
setDragIndicator/setChildDragIndicatorreferencesthat would have thrown
ReferenceError.PATCH /notes/:id/reorderandPOST /notes/groupin routes + controllers.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 aparentIdis supplied, moves it into that container; renumberspositionsequentially. Body:
{ targetId?, parentId? }.POST /notes/group— creates anisGroup: truenote and sets both notes'parentIdto it. Body:{ sourceId, targetId, title }.req.user._id; ids validated withmongoose.Types.ObjectId.isValid.getAllNotesnow sorts bypositionso a reorder persists across refresh.Frontend
NoteCard.jsx: full drag wiring, before/after/stack indicators, and groupednotes rendered stacked under their group card.
HomePage.jsx:topLevelNotesfilters onparentId; reorder/group handlersapply the authoritative note list returned by the endpoints.
Acceptance criteria
/notes/:id/reorderor/notes/group; noReferenceErrorduring drag.parentId) for grouping.Testing
eslintpasses onHomePage.jsxandNoteCard.jsx;node --checkpasses on thebackend controller and routes.
(top-level reorder, move into group, append to group, reorder within group) — all
produce correct sequential
positionvalues andparentIdupdates.