Skip to content

feat: implement drag-and-drop functionality for documents and folders… - #732

Merged
pikann merged 4 commits into
masterfrom
feature/implement-drag-and-drop-functionality-for-documentation
Nov 13, 2026
Merged

pikann merged 4 commits into
masterfrom
feature/implement-drag-and-drop-functionality-for-documentation

Conversation

@pikann

@pikann pikann commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds drag-and-drop to the Documentation tree in the sidebar so documents and folders can be moved between folders.

Changes

All in apps/web/src/components/app-shell/app-sidebar.tsx:

  • Drag source: document and folder rows are draggable (native HTML5 DnD) for users with docs:write. Rows are not draggable while being renamed.
  • Drop targets: dropping on a folder, anywhere in its expanded subtree, moves the item into it (the innermost folder under the cursor wins). Dropping on the empty area of the Documentation list moves the item to the top level. The active target is highlighted.
  • Moving: uses the existing updateDocument (folder_id) and updateFolder (parent_id) endpoints, then invalidates the docs query keys so the tree refreshes.
  • No-ops: dropping an item into its current folder, or a folder onto itself, does nothing.

Not included

  • Reordering within a folder (position is left to the server).
  • A client-side check against dropping a folder into its own descendant; this relies on the server rejecting it, and no error message is shown.
  • Auto-expanding collapsed folders on hover while dragging.

Testing

  • tsc -b and Biome pass.
  • Not yet verified manually in a browser.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ No critical issues — minor suggestions below.

Reviewed changes

  • Drag sources — DocsDocRow and DocsFolderNode rows become draggable for docs:write users (except while renaming) and publish a {kind, id, parentId} payload under application/x-paca-doc-node.
  • Drop targets — a folder's whole subtree wrapper and the root Documentation container accept drops, reparenting through updateFolder/updateDocument and then invalidating docQueryKeys.all(projectId).
  • Guards — same-folder and folder-onto-itself drops are skipped; the server already rejects self-parent and ancestor cycles, so there is no data-integrity risk.

ℹ️ Multiple drop targets stay highlighted

isOver is per-hook state and onDragLeave deliberately ignores moves into descendants, so a parent target never yields: while the pointer is over a nested folder, the root container and every expanded ancestor folder keep their ring, and which target is actually active becomes ambiguous. The task→sprint drag in this same file keeps one dragOverInteractionId, which is the model to mirror.

Technical details
# Only one drop target should be highlighted

## Affected sites
- `apps/web/src/components/app-shell/app-sidebar.tsx:203` — `isOver` lives in each `useDocNodeDrop` instance, so the root container (`:824-828`) and every expanded ancestor folder highlight independently.
- `apps/web/src/components/app-shell/app-sidebar.tsx:235-239` — the containment check treats any descendant as still inside the parent, so the outer target never clears when the pointer enters a nested drop target.
- `apps/web/src/components/app-shell/app-sidebar.tsx:1508` (existing) — task→sprint drag uses a single active id; the same model applies here.

## Required outcome
- At most one target highlighted at a time: the innermost folder under the pointer, or the root container when the pointer is over root-level rows or empty space.

## Suggested approach
- Lift the active target into one piece of state in `DocsSidebarSection` (e.g. `activeDocDropTarget: "root" | folderId | null`) exposed through a small context so the recursive `DocsFolderNode` needs no prop threading; both the root and per-folder highlights derive from it.

ℹ️ Rejected moves toast the raw server error

Dropping a folder into its own expanded subtree is easy to trigger, and moveMutation has no onError, so the global mutation handler toasts the envelope's raw text (doc folder: moving the folder there would create a cycle). The rename mutations in this file map their error codes to docs.errors.*; this one should do the same for the folder cycle and self-parent codes.

Technical details
# Localize the rejected-move message

## Affected sites
- `apps/web/src/components/app-shell/app-sidebar.tsx:205-215` — `moveMutation` declares no `onError`, so `integrations/react-query/query-client.ts:169-173` calls `notifyError`, whose description is `getApiErrorMessage` = the envelope's `error`, set to `err.Error()` in `services/api/internal/transport/http/presenter/response.go:106`.
- `apps/web/src/lib/api-error.ts:132-134` — `ApiErrorCode` has the doc title/folder-name codes but not `DOC_FOLDER_CYCLE` / `DOC_FOLDER_SELF_PARENT`.
- `apps/web/src/components/app-shell/app-sidebar.tsx:306-313` and `:498-505` — the rename mutations show the intended code-to-`docs.errors.*` mapping.

## Required outcome
- A rejected folder move shows a translated, plain-language explanation instead of the internal message.

## Suggested approach
- Add the two codes to `ApiErrorCode` plus `docs.errors.*` strings (all 9 locale dirs; `src/i18n/locales.test.ts` enforces parity), then handle them in the mutation's `onError` with a generic fallback.

ℹ️ The new capability has no touch or keyboard path

Native HTML5 drag events do not fire on touch devices, and the Documentation tree renders inside the mobile sidebar Sheet, so documents and folders cannot be reparented on mobile, or from the keyboard on desktop. Drag is now the only way to move a doc between folders, so it is worth deciding whether a "Move to…" action in the existing actions menu needs to exist as the non-drag path.

Technical details
# Non-drag path for reparenting docs and folders

## Affected sites
- `apps/web/src/components/app-shell/app-sidebar.tsx:329-335` and `:552-555` — the only move affordances, both drag-only.
- `apps/web/src/components/app-shell/app-sidebar.tsx:392-424` and `:609-632` — the existing `⋯` menus, the natural home for a "Move to folder…" item.

## Open questions for the human
- Is a menu-based move planned as a follow-up, or is this intentionally desktop-mouse-only for now?

Pullfrog  | Fix it ➔ | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

  • Single active drop target — per-node isOver state is replaced by a DocDropTargetContext holding one "root" | folderId | null value in DocsSidebarSection, cleared on dragend, so ancestor folders and the root container no longer stay ringed together.
  • Localized move failures — moveMutation now declares onError, mapping DOC_FOLDER_CYCLE / DOC_FOLDER_SELF_PARENT to a new docs.errors.moveIntoSelf toast and falling back to notifyError with docs.errors.moveFailed. Declaring onError also correctly suppresses the global mutation toast.
  • Error codes and strings — both doc-folder codes were added to ApiErrorCode, with docs.errors.moveIntoSelf / moveFailed present in all nine locale files (JSON parses, key sets stay in parity).
  • Root drop area extracted — the root container moved into DocsRootDropArea, wrapping the same folder/doc rows plus the add menu, with unchanged drop behavior.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

…, add move to top feature and enhance payload validation

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ No critical issues — one minor suggestion inline.

Reviewed changes

Since the prior review at 0b0a6ea, this delta:

  • Extracted drag payload parsing/validation and the move-blocking guard into doc-dnd.ts, with colocated unit tests for both helpers.
  • Added projectId to the drag payload so a payload dragged from another project or browser tab is rejected.
  • Added a client-side ancestor guard: a folder can no longer be dropped into itself or a rendered descendant, so the server no longer round-trips those moves.
  • Narrowed post-move cache invalidation to the source and target child lists plus the moved node's own path/detail, instead of the whole docs prefix.
  • Auto-expanded a collapsed drop target after a successful move so the moved item is visible.
  • Moved the drag handlers onto each row's main button (Firefox cannot start a drag from a button nested in a draggable parent), and added a "Move to top level" menu action with strings in all nine locales.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

Since the prior review at 0b34f86:

  • Broadened folder-path invalidation — a folder move now marks the folders/path query prefix stale instead of only the moved folder's own path, so documents open inside descendant folders pick up their new breadcrumb immediately. Verified the prefix matches docQueryKeys.folderPath (apps/web/src/lib/doc-api.ts:147-148) and does not overlap the folderChildren / docChildren keys.

This addresses the one inline finding from the previous review; the thread is resolved.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@pikann
pikann merged commit 47119ae into master Nov 13, 2026
2 checks passed
@pikann
pikann deleted the feature/implement-drag-and-drop-functionality-for-documentation branch November 13, 2026 07:46
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.

1 participant