feat: re-parent tasks by drag and drop in the sidebar (#2355)
This commit is contained in:
@@ -0,0 +1,120 @@
|
||||
---
|
||||
spec: docs/specs/tasks/subtask-reparenting-drag-drop.md
|
||||
created: 2026-08-04
|
||||
status: complete
|
||||
---
|
||||
|
||||
# Implementation Plan: Subtask re-parenting by drag and drop
|
||||
|
||||
## Overview
|
||||
|
||||
The backend reparent contract (`PATCH /api/v1/tasks/:id` with `parent_id`, validated by `resolveParentID` + `validateReparentDepth`) already exists and is tested. Two deltas make drag-drop "strictly equivalent" to the menu composite (un-nest + nest): (1) normalize `inherit_parent` workspace mode to `shared_group` on any effective parent change in the canonical update path, and (2) add the same normalization to the Office dashboard PATCH for parity. The real work is frontend: hoist the sidebar tree's per-level `DndContext` into one per-group context, add nest drop zones with a pure drop-decision helper, and wire `onReparentTask` through `TaskSwitcher` to the existing `useNestTask` hook. E2E (desktop + mobile touch) comes last.
|
||||
|
||||
---
|
||||
|
||||
## Backend
|
||||
|
||||
### Canonical update normalization (`apps/backend/internal/task/service/service_tasks.go`)
|
||||
|
||||
In `Service.UpdateTask`, the parent block (~line 1225) already resolves and assigns `task.ParentID` only when the parent effectively changed. After that block, add a small helper `normalizeWorkspaceModeAfterReparent(task)` that copies `task.Metadata["workspace"]` and changes only `mode: "inherit_parent"` → `"shared_group"` — the exact detach semantics — applied whenever the effective parent changed (set or cleared). The existing full-row persist writes the metadata; the existing `parent_id` event emission (explicit nil on clear) is unchanged. This covers core PATCH, WS update, the sidebar menu, the Office parent picker (`updateTask`), and the drag-drop, all through one path.
|
||||
|
||||
### Office dashboard parity (`apps/backend/internal/office/dashboard/service_tasks.go`)
|
||||
|
||||
`DashboardService.UpdateTaskParentID` non-empty path currently writes `parent_id` directly and publishes `["parent_id"]`. Change it so that after the repo write it loads the task, and if workspace mode is `inherit_parent`, persists `shared_group` and publishes fields `["parent_id", "metadata"]`. Add `UpdateTaskWorkspaceMode(ctx, taskID, mode)` to the office sqlite repository (dialect-aware JSON set, mirroring `detachTaskQuery`'s mode branch) and to the `DashboardService` repo interface. The empty-parent path keeps routing to the canonical detacher.
|
||||
|
||||
### Events
|
||||
|
||||
No new event types. `task.updated` already carries `parent_id` (nil when cleared) and `metadata`; the normalization rides along. Office `OfficeTaskUpdated` gains `metadata` in its `fields` list only when the mode changed.
|
||||
|
||||
## Frontend
|
||||
|
||||
### Drop-decision logic (`apps/web/components/task/task-switcher-subtask-dnd.tsx`)
|
||||
|
||||
- Extract a pure, unit-testable `resolveSidebarDrop({ activeId, overId, groupRootIds, childrenByParent })` returning `{kind:"nest", parentTaskId}` | `{kind:"reorder", level:"group"|"subtasks", parentTaskId?, orderedTaskIds}` | `null`. `overId` prefixed `nest:` → nest; otherwise both tasks must share a level (group root list or one parent's children) → `arrayMove` within that level; anything else → `null`.
|
||||
- Add `NestDropZone` (small component): `useDroppable({ id: "nest:"+taskId })`, absolute left-edge strip, `data-testid="nest-drop-zone"`, `data-task-id`, hover affordance label "Nest under <title>". Rendered only for rows that are valid targets of the active drag.
|
||||
- Add a `computeNestTargets(activeTask, groupTasks)` helper: flatten the group's subtree, filter to the active task's `workflowId`, run the existing `computeNestCandidates` from `apps/web/lib/sidebar/nest-candidates.ts`. Returns the candidate id set (empty for tasks with children).
|
||||
|
||||
### DndContext hoisting (`task-switcher-subtask-dnd.tsx` + `apps/web/components/task/task-switcher.tsx`)
|
||||
|
||||
- `SortableTaskLevel` currently creates one `DndContext` per sibling level, which makes cross-level drops impossible. Change `SortableTaskLevel` so it renders only `SortableContext` + nodes when a group-level context is present (new prop, e.g. `externalDragContext`), preserving current behavior for non-reorderable callers.
|
||||
- `GroupSection` in `task-switcher.tsx` renders ONE `DndContext` (sensors from `taskSwitcherDragActivationConstraints`, custom `collisionDetection`: `pointerWithin` filtered to `nest:` ids wins, else `closestCenter`, `onDragEnd` dispatching through `resolveSidebarDrop`).
|
||||
- Track the active drag id (`onDragStart`) in the group; compute `computeNestTargets` and thread candidate ids through `TaskTreeContext` so `TaskTreeNode` renders `NestDropZone` on candidate rows.
|
||||
- New `TaskSwitcher` prop `onReparentTask?: (taskId: string, parentTaskId: string) => void`, threaded through `GroupSection` → `TaskTreeContext` → drop handling.
|
||||
|
||||
### Sidebar + mobile wiring
|
||||
|
||||
- `apps/web/components/task/task-session-sidebar.tsx`: `handleReparentTask(taskId, parentTaskId)` resolves the task's `workflowId` from `displayTasks` and calls the existing `useNestTask` (non-null path → `updateTask(taskId, { parent_id })` → composite semantics after the backend change; same optimistic snapshot patch, rollback, and toast).
|
||||
- `apps/web/components/task/mobile/session-task-switcher-sheet.tsx`: same wiring; touch drag already works via the existing `TouchSensor` (250 ms delay / 5 px tolerance).
|
||||
|
||||
### i18n
|
||||
|
||||
New user-facing copy (nest-zone label, aria text) goes through `t()` / `<Trans>` with keys added to the sidebar's locale namespace; do not hardcode.
|
||||
|
||||
## Tests
|
||||
|
||||
### Backend
|
||||
|
||||
- **What:** reparenting an `inherit_parent` child normalizes mode to `shared_group` (persisted + event metadata).
|
||||
- **File:** `apps/backend/internal/task/service/service_reparent_test.go`
|
||||
- **How:** extend the existing reparent fixture; assert `Metadata["workspace"]["mode"]` in the returned task, the persisted row, and the `task.updated` payload.
|
||||
- **What:** non-`inherit_parent` modes (`shared_group`, `new_workspace`) and root-task reparents are untouched.
|
||||
- **File:** same, table-driven.
|
||||
- **What:** un-nest via `UpdateTask` (empty `parent_id`) normalizes like the detach endpoint.
|
||||
- **File:** same.
|
||||
- **What:** Office dashboard non-empty reparent normalizes `inherit_parent` and publishes `metadata` in fields.
|
||||
- **File:** `apps/backend/internal/office/dashboard/service_detachment_test.go` (mirror `TestUpdateTaskParentIDUsesCanonicalDetacherWhenCleared`).
|
||||
- Existing reparent/detach/handler suites must stay green (no changes to `resolveParentID` / `validateReparentDepth`).
|
||||
|
||||
### Frontend
|
||||
|
||||
- **What:** drop decision maps `nest:` over-ids and same-level reorders correctly, rejects cross-level drops.
|
||||
- **File:** `apps/web/components/task/task-switcher-subtask-dnd.test.ts`
|
||||
- **How:** pure-function unit tests for `resolveSidebarDrop`.
|
||||
- **What:** nest targets = same-workflow roots per `computeNestCandidates`, empty for tasks with children.
|
||||
- **File:** `apps/web/lib/sidebar/nest-candidates.test.ts` (extend) or a new sibling test.
|
||||
- **What:** existing `TaskSwitcher` / sortable rendering behavior is preserved (regression).
|
||||
- **File:** `apps/web/components/task/task-switcher.test.tsx`.
|
||||
|
||||
### E2E
|
||||
|
||||
See task 04. Desktop spec `apps/web/e2e/tests/task/subtask-reparent-drag-drop.spec.ts` + mobile touch variant, modeled on `subtask-detachment.spec.ts` / `mobile-subtask-detachment.spec.ts` and the `Input.dispatchTouchEvent` pattern in `mobile-automations-scroll.spec.ts`.
|
||||
|
||||
## E2E Tests
|
||||
|
||||
- **Scenario:** subtask dragged onto another root's nest zone re-parents (API `parent_id` + sidebar nesting, no reload).
|
||||
- **Scenario:** `inherit_parent` subtask ends with `shared_group` (assert via API metadata).
|
||||
- **Scenario:** root dragged onto root nests; task with children offers no nest zone; drop on an invalid row is a no-op.
|
||||
- **Scenario:** sibling reorder still works (regression).
|
||||
- **Scenario:** mobile touch drag re-parents (mobile-chrome project).
|
||||
- **File:** `apps/web/e2e/tests/task/subtask-reparent-drag-drop.spec.ts`
|
||||
|
||||
## Verification Results
|
||||
|
||||
All task checks passed; see each task's `## Results` for exact commands and counts.
|
||||
|
||||
- Backend: `go test ./internal/task/service ./internal/task/handlers ./internal/office/dashboard` — service + office/dashboard `ok`; handlers `ok` under `umask 022` (3 pre-existing env failures under umask 002, verified on base).
|
||||
- Web: full unit suite passes (8441+ of 8450; the 5 failures are pre-existing env issues: 3 Docker-bridge `http-git-server`, 2 load-sensitive file-browser timeouts that pass in isolation); typecheck, lint, i18n ratchet clean.
|
||||
- E2E: `subtask-reparent-drag-drop.spec.ts` 5/5 (chromium), `mobile-subtask-reparent-drag-drop.spec.ts` 1/1 (mobile-chrome touch).
|
||||
- Root: `make fmt`, `make typecheck`, `make lint` pass. `make test` residual failures are pre-existing environment-dependent tests (launchd/systemd/cli-shim) unrelated to this feature.
|
||||
|
||||
## Implementation Waves And Parallel Candidates
|
||||
|
||||
```
|
||||
Wave 1:
|
||||
- [x] [task-01-backend-composite-semantics](task-01-backend-composite-semantics.md)
|
||||
|
||||
Wave 2:
|
||||
- [x] [task-02-frontend-nest-drop-infrastructure](task-02-frontend-nest-drop-infrastructure.md)
|
||||
|
||||
Wave 3:
|
||||
- [x] [task-03-frontend-wiring-and-affordances](task-03-frontend-wiring-and-affordances.md)
|
||||
|
||||
Wave 4:
|
||||
- [x] [task-04-e2e-and-verification](task-04-e2e-and-verification.md)
|
||||
```
|
||||
|
||||
All tasks are sequential (each depends on the previous). No parallel candidates.
|
||||
|
||||
## Open Questions
|
||||
|
||||
None.
|
||||
@@ -0,0 +1,53 @@
|
||||
---
|
||||
id: "01-backend-composite-semantics"
|
||||
title: "Backend composite re-parent semantics"
|
||||
status: done
|
||||
wave: 1
|
||||
depends_on: []
|
||||
plan: "plan.md"
|
||||
spec: "../../specs/tasks/subtask-reparenting-drag-drop.md"
|
||||
---
|
||||
|
||||
# Task 01: Backend composite re-parent semantics
|
||||
|
||||
## Acceptance
|
||||
|
||||
- `Service.UpdateTask` normalizes `metadata.workspace.mode` from `inherit_parent` to `shared_group` whenever the effective parent changes (set or cleared); other modes and root tasks are untouched. The returned task, the persisted row, and the `task.updated` payload all reflect the change.
|
||||
- `DashboardService.UpdateTaskParentID` (Office dashboard PATCH) applies the same normalization on its non-empty parent path and includes `metadata` in the published `fields` when the mode changed.
|
||||
- All existing reparent/detach service and handler tests pass unchanged.
|
||||
|
||||
## Verification
|
||||
|
||||
```bash
|
||||
cd apps/backend && go test ./internal/task/service ./internal/task/handlers ./internal/office/dashboard
|
||||
```
|
||||
|
||||
## Files likely touched
|
||||
|
||||
- `apps/backend/internal/task/service/service_tasks.go` (parent block in `Service.UpdateTask`, new `normalizeWorkspaceModeAfterReparent` helper)
|
||||
- `apps/backend/internal/task/service/service_reparent_test.go` (new cases)
|
||||
- `apps/backend/internal/office/dashboard/service_tasks.go` (`UpdateTaskParentID`)
|
||||
- `apps/backend/internal/office/dashboard/service_detachment_test.go` (parity test)
|
||||
- `apps/backend/internal/office/repository/sqlite/tasks.go` (new `UpdateTaskWorkspaceMode`)
|
||||
- `apps/backend/internal/office/dashboard/service.go` (repo interface member, if `UpdateTaskWorkspaceMode` is not already surfaced)
|
||||
|
||||
## Dependencies
|
||||
|
||||
None.
|
||||
|
||||
## Inputs
|
||||
|
||||
- Spec sections: What (composite semantics), Data model, API surface, Failure modes.
|
||||
- Existing pattern: `Service.DetachTask` + `detachTaskQuery` (dialect-aware JSON mode normalization in `apps/backend/internal/task/repository/sqlite/task.go`), `resolveParentID` / `validateReparentDepth` in `service_tasks.go`, `publishTaskUpdated` in the office dashboard service.
|
||||
- Do NOT change `resolveParentID` / `validateReparentDepth`; validation behavior is already shipped and tested.
|
||||
|
||||
## Output contract
|
||||
|
||||
Report the service/repo changes, exact commands and results, files changed, blockers, residual risks; update this task and `plan.md` when acceptance passes.
|
||||
|
||||
## Results
|
||||
|
||||
- `cd apps/backend && go test ./internal/task/service ./internal/task/handlers ./internal/office/dashboard` — service and office/dashboard `ok`; handlers `ok` (run with `umask 022`; this sandbox's default umask 002 makes 3 pre-existing local-repository handler tests fail — they pass under standard umask and fail identically on the stash-clean base).
|
||||
- Added `normalizeWorkspaceModeAfterReparent` to `Service.UpdateTask` (parent-change block): `inherit_parent` → `shared_group` on any effective parent change. TDD red→green: `TestService_UpdateTask_ReparentNormalizesInheritedWorkspaceMode`, `TestService_UpdateTask_UnnestNormalizesInheritedWorkspaceMode`, `TestService_UpdateTask_ReparentPreservesNonInheritedWorkspaceModes`.
|
||||
- Office parity: repo `UpdateTaskParentID` now sets `parent_id` AND normalizes mode in one dialect-aware UPDATE (SQLite JSON, mirroring `detachTaskQuery`); dashboard service publishes `["parent_id", "metadata"]`; parity test `TestUpdateTaskParentIDNormalizesInheritedWorkspaceMode`; added the missing `metadata` column to the office test-harness tasks DDL (matches production schema).
|
||||
- Files changed: `internal/task/service/service_tasks.go`, `service_reparent_test.go`, `internal/office/dashboard/service_tasks.go`, `service_detachment_test.go`, `handler_test.go`, `internal/office/repository/sqlite/tasks.go`.
|
||||
@@ -0,0 +1,51 @@
|
||||
---
|
||||
id: "02-frontend-nest-drop-infrastructure"
|
||||
title: "Frontend nest-drop infrastructure"
|
||||
status: done
|
||||
wave: 2
|
||||
depends_on: ["01-backend-composite-semantics"]
|
||||
plan: "plan.md"
|
||||
spec: "../../specs/tasks/subtask-reparenting-drag-drop.md"
|
||||
---
|
||||
|
||||
# Task 02: Frontend nest-drop infrastructure
|
||||
|
||||
## Acceptance
|
||||
|
||||
- A single `DndContext` per sidebar group section replaces the per-level contexts, so a drag can target rows outside its own sibling level; sibling reorder behavior is unchanged.
|
||||
- `resolveSidebarDrop` (pure) and `computeNestTargets` (pure) exist with unit tests; `NestDropZone` renders on candidate rows with `data-testid="nest-drop-zone"` and `data-task-id`.
|
||||
- Existing `TaskSwitcher` / `SortableTaskLevel` tests pass (no behavior regression when no group-level context or reorder is configured).
|
||||
|
||||
## Verification
|
||||
|
||||
```bash
|
||||
cd apps/web && pnpm test -- components/task/task-switcher-subtask-dnd.test.ts components/task/task-switcher.test.tsx lib/sidebar/nest-candidates.test.ts
|
||||
cd apps/web && pnpm run typecheck
|
||||
```
|
||||
|
||||
## Files likely touched
|
||||
|
||||
- `apps/web/components/task/task-switcher-subtask-dnd.tsx` — hoist `DndContext` out of `SortableTaskLevel` (new `externalDragContext` mode), add `NestDropZone`, `resolveSidebarDrop`, `computeNestTargets`, custom collision (`pointerWithin` → `nest:` ids, else `closestCenter`), sensors, group-level `onDragStart`/`onDragEnd`.
|
||||
- `apps/web/components/task/task-switcher.tsx` — `GroupSection` renders the hoisted `DndContext`; `TaskTreeContext` carries candidate ids + `onReparentTask`; `TaskTreeNode` renders `NestDropZone` on candidate rows; new optional `onReparentTask` prop on `TaskSwitcher` (unwired for now).
|
||||
- `apps/web/components/task/task-switcher-subtask-dnd.test.ts` (new) — `resolveSidebarDrop` unit tests: nest id mapping, group-root reorder, subtask-level reorder, cross-level drop → null, no-over → null.
|
||||
|
||||
## Dependencies
|
||||
|
||||
Task 01 (semantics only — infra works against the existing `updateTask` path regardless).
|
||||
|
||||
## Inputs
|
||||
|
||||
- Spec sections: What (gesture, targets, reorder preservation), Scenarios.
|
||||
- Existing code: `useLevelDnd` / `SortableTaskLevel` / `DraggableSortableTaskNode` in `task-switcher-subtask-dnd.tsx`; `TaskTreeLevel`/`GroupSection`/`TaskTreeContext` in `task-switcher.tsx`; `computeNestCandidates` in `apps/web/lib/sidebar/nest-candidates.ts`; activation constraints constants.
|
||||
- Reorder callbacks keep their signatures: `onReorderGroup(orderedTaskIds)`, `onReorderSubtasks(parentTaskId, orderedTaskIds)`.
|
||||
|
||||
## Output contract
|
||||
|
||||
Report the component/helper changes, exact commands and results, files changed, blockers, residual risks; update this task and `plan.md` when acceptance passes.
|
||||
|
||||
## Results
|
||||
|
||||
- `cd apps/web && pnpm test -- components/task/task-switcher-subtask-dnd.test.ts components/task/task-switcher.test.tsx components/task/task-switcher-direct-subtasks.test.tsx` — 31 passed (new helper tests + switcher regression suites).
|
||||
- `pnpm run typecheck` clean; `pnpm run lint` clean (0 warnings); `pnpm run i18n:ratchet` clean.
|
||||
- Hoisted per-level `DndContext` into `TaskTreeDndGroup` (one per group section; custom collision: `pointerWithin` → `nest:` ids win, else `closestCenter`); `SortableTaskLevel` gained `externalDragContext`; added `NestDropZone` + pure `resolveSidebarDrop`/`computeNestTargets` (unit-tested); `GroupSection` slimmed via props-object + new `task-switcher-tree-context.ts` (`flattenGroupTasks`/`buildTaskTreeContext`) to stay under lint line limits.
|
||||
- Files changed: `components/task/task-switcher-subtask-dnd.tsx`, `task-switcher-subtask-dnd.test.ts`, `task-switcher.tsx`, `task-switcher-tree-context.ts` (new), `src/locales/en/sidebar.json` (`sidebar:nestUnder`).
|
||||
@@ -0,0 +1,55 @@
|
||||
---
|
||||
id: "03-frontend-wiring-and-affordances"
|
||||
title: "Frontend wiring and affordances"
|
||||
status: done
|
||||
wave: 3
|
||||
depends_on: ["02-frontend-nest-drop-infrastructure"]
|
||||
plan: "plan.md"
|
||||
spec: "../../specs/tasks/subtask-reparenting-drag-drop.md"
|
||||
---
|
||||
|
||||
# Task 03: Frontend wiring and affordances
|
||||
|
||||
## Acceptance
|
||||
|
||||
- Desktop sidebar and mobile task switcher sheet wire `onReparentTask` through the existing `useNestTask` hook: a drop on a nest zone calls `updateTask(taskId, { parent_id })` with the task's `workflowId`, applies the optimistic snapshot patch, rolls back + toasts on error, and reconciles via the `task.updated` WS event.
|
||||
- The nest-zone affordance shows `Nest under <title>` (localized via `t()`), and the drag exposes no nest zone on invalid targets.
|
||||
- All new user-facing copy is i18n'd; `pnpm run i18n:ratchet` is clean for touched lines.
|
||||
|
||||
## Verification
|
||||
|
||||
```bash
|
||||
cd apps/web && pnpm test -- components/task/task-session-sidebar.test.tsx components/task/mobile/session-task-switcher-sheet.test.tsx
|
||||
cd apps/web && pnpm run typecheck
|
||||
cd apps/web && pnpm run lint
|
||||
cd apps/web && pnpm run i18n:ratchet
|
||||
```
|
||||
|
||||
(Adjust test file list to the files that actually exist for these components; if a surface has no test file, add focused tests for the new handler.)
|
||||
|
||||
## Files likely touched
|
||||
|
||||
- `apps/web/components/task/task-session-sidebar.tsx` — `handleReparentTask(taskId, parentTaskId)` resolving `workflowId` from `displayTasks`, wired to `onReparentTask` via `buildTaskSwitcherProps`.
|
||||
- `apps/web/components/task/task-session-sidebar-switcher-props.ts` — thread the new prop.
|
||||
- `apps/web/components/task/mobile/session-task-switcher-sheet.tsx` — same wiring (shared `TaskSwitcher`; touch drag already active).
|
||||
- `apps/web/src/locales/en/<sidebar-namespace>.json` — new keys (`nestUnder`, aria label); use the namespace already used by the sidebar components.
|
||||
- `apps/web/components/task/task-switcher-subtask-dnd.tsx` — affordance label rendering (if not already in task 02).
|
||||
|
||||
## Dependencies
|
||||
|
||||
Task 02 (props/context plumbing) and Task 01 (composite semantics behind `updateTask`).
|
||||
|
||||
## Inputs
|
||||
|
||||
- Spec sections: What (single API call, optimistic update, no confirmation), Scenarios (invalid target toast, mobile).
|
||||
- Existing code: `useNestTask` in `apps/web/hooks/use-nest-task.ts` (non-null path already calls `updateTask`), `buildTaskSwitcherProps`, mobile sheet's existing `TaskSwitcher` usage.
|
||||
|
||||
## Output contract
|
||||
|
||||
Report wiring changes, exact commands and results, files changed, blockers, residual risks; update this task and `plan.md` when acceptance passes.
|
||||
|
||||
## Results
|
||||
|
||||
- `pnpm run typecheck` clean; `pnpm run lint` clean; `pnpm run i18n:ratchet` clean; task-component suites passed (249 files / 2140 tests in the `components/task` run).
|
||||
- Desktop sidebar and mobile sheet wire `onNestTask` through the existing `useNestTask` hook; workflow resolved from snapshot keys via the new shared helper `taskWorkflowIdFromSnapshots` in `hooks/use-nest-task.ts`; `MobileTaskList` gained `onNestTask` (sheet stays open on drop); new `sidebar:nestUnder` key.
|
||||
- Files changed: `components/task/task-session-sidebar.tsx`, `task-session-sidebar-switcher-props.ts`, `components/task/mobile/session-task-switcher-sheet.tsx`, `session-task-switcher-sheet-hooks.ts`, `hooks/use-nest-task.ts`.
|
||||
@@ -0,0 +1,50 @@
|
||||
---
|
||||
id: "04-e2e-and-verification"
|
||||
title: "E2E and full verification"
|
||||
status: done
|
||||
wave: 4
|
||||
depends_on: ["03-frontend-wiring-and-affordances"]
|
||||
plan: "plan.md"
|
||||
spec: "../../specs/tasks/subtask-reparenting-drag-drop.md"
|
||||
---
|
||||
|
||||
# Task 04: E2E and full verification
|
||||
|
||||
## Acceptance
|
||||
|
||||
- Desktop Playwright spec covers: subtask dragged onto another root's nest zone re-parents (assert API `parent_id` and sidebar nesting, no reload); `inherit_parent` subtask ends with `shared_group` (assert via API metadata); root dragged onto root nests; a task with children offers no nest zone; a drop on an invalid row is a no-op; sibling reorder still works.
|
||||
- Mobile-chrome touch variant covers the same re-parent flow via `Input.dispatchTouchEvent`.
|
||||
- `make fmt` then `make typecheck test lint` pass from the repository root.
|
||||
|
||||
## Verification
|
||||
|
||||
```bash
|
||||
cd apps/web && pnpm e2e:run e2e/tests/task/subtask-reparent-drag-drop.spec.ts
|
||||
cd /home/clem/.kandev/tasks/re-parenting-from-dr_0b8/kdlbs-kandev && make fmt && make typecheck && make test && make lint
|
||||
```
|
||||
|
||||
Note: run `pnpm install --frozen-lockfile` from `apps/` once if this is a fresh worktree (missing `node_modules` breaks pnpm commands and the commit hook).
|
||||
|
||||
## Files likely touched
|
||||
|
||||
- `apps/web/e2e/tests/task/subtask-reparent-drag-drop.spec.ts` (new) — model structure, seeding, and sidebar interaction on `apps/web/e2e/tests/task/subtask-detachment.spec.ts`; drag mechanics via `locator.hover()` + `page.mouse.down()` + stepped `mouse.move()` + `mouse.up()` (dnd-kit needs >8px movement before activation).
|
||||
- Mobile variant: same spec gated to `mobile-chrome` project or a sibling spec, using the `Input.dispatchTouchEvent` pattern from `apps/web/e2e/tests/mobile-automations-scroll.spec.ts`.
|
||||
|
||||
## Dependencies
|
||||
|
||||
Tasks 01–03.
|
||||
|
||||
## Inputs
|
||||
|
||||
- Spec Scenarios (each maps to a test), plan E2E section, existing `subtask-detachment` e2e specs and helpers (`apps/web/e2e/helpers/api-client.ts` createTask/updateTask with `parent_id` and `workspace_mode`).
|
||||
|
||||
## Output contract
|
||||
|
||||
Report the spec files, exact commands and results (including per-scenario pass counts), files changed, blockers, residual risks; update this task and `plan.md` when acceptance passes.
|
||||
|
||||
## Results
|
||||
|
||||
- Desktop: `pnpm e2e:run tests/task/subtask-reparent-drag-drop.spec.ts --shards 1` — 5 passed (subtask→root reparent + workspace-mode normalization, root→root nest, no nest zones for a task with children, subtask-row drop no-op, sibling reorder regression).
|
||||
- Mobile: `pnpm e2e:run --project mobile-chrome tests/task/mobile-subtask-reparent-drag-drop.spec.ts --shards 1` — 1 passed (touch drag via CDP `Input.dispatchTouchEvent`; source handle and target zone are scrolled into view first — the sheet scrolls and off-viewport coordinates make raw mouse/touch events no-ops).
|
||||
- Root verification: `make fmt`, `make typecheck`, `make lint` pass (umask 022). `make test`: all changed packages pass; residual failures are pre-existing environment issues (launchd/systemd/cli-shim backend tests, Docker-bridge-dependent `http-git-server.test.ts`, load-sensitive file-browser timeouts that pass in isolation) — verified failing on the stash-clean base.
|
||||
- Files changed: `e2e/tests/task/subtask-reparent-drag-drop.spec.ts` (new), `e2e/tests/task/mobile-subtask-reparent-drag-drop.spec.ts` (new). Temporary diagnostic spec `mobile-drag-diag.spec.ts` created and removed.
|
||||
@@ -68,6 +68,7 @@ Kandev's task model: documents, execution stages, labels, blocker escalation, su
|
||||
| [remote-contribution-tasks](tasks/remote-contribution-tasks.md) | approved |
|
||||
| [subtask-checklist](tasks/subtask-checklist.md) | shipped |
|
||||
| [subtask-detachment](tasks/subtask-detachment.md) | shipped |
|
||||
| [subtask-reparenting-drag-drop](tasks/subtask-reparenting-drag-drop.md) | building |
|
||||
| [subtask-completion-trigger](tasks/subtask-completion-trigger.md) | draft |
|
||||
| [subtree-controls](tasks/subtree-controls.md) | shipped |
|
||||
| [blocked-task-escalation](tasks/blocked-task-escalation.md) | draft |
|
||||
|
||||
@@ -79,7 +79,7 @@ The cleared parent relationship and normalized workspace mode survive backend re
|
||||
|
||||
## Out of scope
|
||||
|
||||
- Reparenting a task to a different parent from the sidebar or kanban card menus.
|
||||
- Reparenting a task to a different parent from the sidebar or kanban card menus (now covered by [subtask-reparenting-drag-drop](subtask-reparenting-drag-drop.md) for the sidebar; kanban-card reparenting remains out of scope).
|
||||
- Copying or provisioning a separate workspace during detachment.
|
||||
- Removing blocker relationships or changing descendant relationships.
|
||||
- Stopping or restarting active sessions.
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
---
|
||||
status: building
|
||||
created: 2026-08-04
|
||||
owner: kandev
|
||||
---
|
||||
|
||||
# Subtask re-parenting by drag and drop
|
||||
|
||||
## Why
|
||||
|
||||
Users can detach a subtask or nest a task under another via context-menu actions, but moving a task from under one parent to under another takes two menu hops (un-nest, then nest under), and the sidebar's drag-and-drop only reorders siblings. A direct drag gesture should re-parent a task in one motion with the exact same result as those two menu actions.
|
||||
|
||||
## What
|
||||
|
||||
- The sidebar task tree (desktop sidebar and the mobile task switcher sheet) lets a user re-parent a task by dragging its row onto another row's **nest drop zone**.
|
||||
- The result is strictly equivalent to choosing `Un-nest (remove parent)` then `Nest under <target>` from the task's context menu: the task's parent becomes the target, and a task whose workspace mode is `inherit_parent` ends with mode `shared_group` — its materialized workspace and workspace-group membership are unchanged.
|
||||
- Drop targets are exactly the candidates the context menu offers (the `computeNestCandidates` rules): same-workflow root tasks in the visible group, excluding the dragged task, its current parent, and any subtask (which also excludes the task's own descendants). A task that already has children offers no nest targets.
|
||||
- While a drag with valid targets is active, candidate rows show a nest drop zone (a left-edge strip) with a `Nest under <title>` affordance. Dropping on a zone re-parents; dropping between rows keeps the existing sibling-reorder behavior; any other drop is a no-op.
|
||||
- Re-parenting is a single API call on the existing canonical path (`PATCH /api/v1/tasks/:id` with `parent_id`), which already rejects self-parenting, missing/archived/cross-workspace targets, descendant cycles, and one-level-depth violations for kanban tasks.
|
||||
- The sidebar `Nest under` menu, the Office parent picker, the WS task-update path, and the Office dashboard PATCH all share the same composite semantics: any effective parent change normalizes an `inherit_parent` workspace mode to `shared_group`.
|
||||
- No confirmation dialog is shown on drop (unlike the detach menu action): the gesture is explicit, the operation is non-destructive (workspace membership is retained) and reversible via the menu or another drag.
|
||||
- Successful re-parenting is reflected across sidebar, board, and task-detail views without a reload, via the existing optimistic snapshot update and the `task.updated` WebSocket event.
|
||||
- The mobile task switcher sheet offers the same touch drag-and-drop re-parenting.
|
||||
|
||||
## Data model
|
||||
|
||||
No table or column is added. Re-parenting updates existing persisted fields in the same task-row write:
|
||||
|
||||
- `tasks.parent_id` becomes the target task's id (the previous parent, if any, is replaced).
|
||||
- `tasks.metadata.workspace.mode` changes from `inherit_parent` to `shared_group` when the parent relationship effectively changes and the mode was `inherit_parent`. Other modes (`shared_group`, `new_workspace`) are unchanged.
|
||||
- `task_workspace_group_members` is unchanged; active membership remains the durable source of shared workspace access.
|
||||
- Descendant `parent_id` values, blockers, sessions, repositories, workflow, workflow step, and state are unchanged.
|
||||
|
||||
## API surface
|
||||
|
||||
No new endpoint. Reuses and extends existing contracts:
|
||||
|
||||
- `PATCH /api/v1/tasks/:id` with `parent_id` (non-empty nests; `""` un-nests) — already validated by `Service.resolveParentID` (self, existence, archived, same workspace, descendant cycle) and `validateReparentDepth` (one-level kanban limit, Office trees exempt). **Behavior addition:** when the effective parent changes, `inherit_parent` workspace mode is normalized to `shared_group` (mirroring the detach operation). Success returns the updated task DTO; invalid targets map to `400`; missing task to `404`.
|
||||
- `PATCH /api/v1/office/tasks/:id` with non-empty `parent_id` — same normalization added for parity; empty parent continues to route through the canonical detach operation.
|
||||
- WS `task.updated` payload unchanged: `parent_id` is always present (nil when cleared), and `metadata` carries the normalized workspace mode.
|
||||
|
||||
## Failure modes
|
||||
|
||||
- **Invalid target** (self, descendant, subtask, archived, missing, cross-workspace, or depth violation): the UI filters these targets out before a drop can land, so a drop outside every nest zone is a no-op. If a request is nevertheless rejected by the backend (e.g. a valid-zone target became invalid between render and drop), the UI keeps the task in its original tree position, rolls back the optimistic update, and shows a request-error toast.
|
||||
- **Persistence failure**: no successful response is returned; the UI rolls back to the original tree.
|
||||
- **Concurrent submissions** are safe: setting the same parent twice is idempotent, and the optimistic update is reconciled by the authoritative `task.updated` event.
|
||||
- **No valid targets**: the drag offers no nest zones; only reorder remains possible.
|
||||
|
||||
## Scenarios
|
||||
|
||||
- **GIVEN** a subtask `C` under parent `A` and a root task `B` in the same workflow, **WHEN** the user drags `C` onto `B`'s nest drop zone, **THEN** `C`'s parent becomes `B`, the sidebar shows `C` nested under `B`, and no reload occurs.
|
||||
- **GIVEN** an `inherit_parent` subtask `C` under `A`, **WHEN** `C` is dragged onto root `B`'s nest zone, **THEN** `C`'s persisted workspace mode is `shared_group` and its workspace-group membership is unchanged.
|
||||
- **GIVEN** a root task with no children, **WHEN** it is dragged onto another root's nest zone, **THEN** it becomes that root's subtask.
|
||||
- **GIVEN** a task that already has children, **WHEN** it is dragged, **THEN** no row offers a nest drop zone (reorder only).
|
||||
- **GIVEN** a drag over a subtask row or over a task in a different workflow, **WHEN** the pointer rests on the row, **THEN** no nest drop zone is offered.
|
||||
- **GIVEN** a subtask dragged toward its current parent, **WHEN** the pointer rests on that parent row, **THEN** no nest drop zone is offered.
|
||||
- **GIVEN** a drag dropped between two sibling rows, **WHEN** the drop lands outside every nest zone, **THEN** the siblings reorder as before.
|
||||
- **GIVEN** a drop that lands outside every nest zone, **WHEN** the drop completes, **THEN** the task keeps its original parent and no request is sent (a plain no-op); a request-error toast appears only when a valid-zone drop's request is rejected by the backend.
|
||||
- **GIVEN** a re-parented task, **WHEN** its `task.updated` event arrives over WebSocket, **THEN** cached parent relationships in sidebar, board, and task-detail views are updated.
|
||||
- **GIVEN** the mobile task switcher sheet, **WHEN** a user touch-drags a subtask onto a root's nest zone, **THEN** the same re-parenting occurs.
|
||||
|
||||
## Out of scope
|
||||
|
||||
- Nesting via drag on the kanban board (cards keep their step-move drag semantics).
|
||||
- Lifting the one-level kanban subtask limit (still enforced by `computeNestCandidates` and `validateReparentDepth`; Office trees keep arbitrary depth).
|
||||
- Drag-to-re-parent in the Office task list (Office keeps its parent picker).
|
||||
- Bulk or multi-select drag re-parenting.
|
||||
- A keyboard/AT drag gesture; the existing context menus remain the accessible path to the same operation.
|
||||
|
||||
## Implementation plan
|
||||
|
||||
See [the implementation plan](../../plans/subtask-reparenting-drag-drop/plan.md).
|
||||
Reference in New Issue
Block a user