# Open Point AGILE-292 - Decide shape of Stimulus sortable-lists controller

Project: Stream agile
Status: decided
URL: https://community.openproject.org/work_packages/AGILE-292

## Details

| Attribute | Value |
| --- | --- |
| Involved people | Jens Ulferts, Henriette Darge, Alexander Coles |
| Assignee |  |
| Decision |  |
| Date |  |
| Module |  |
| Labels |  |

## Related to

_No work packages_

## Description

## Context

Migrating Backlogs from dragula to Atlassian Pragmatic DnD (<mention class="mention" data-id="AGILE-251" data-type="work_package" data-text="#AGILE-251">#AGILE-251</mention>). Open question: what controller topology should the reusable `sortable-lists` Stimulus primitive take, given upcoming requirements — <mention class="mention" data-id="AGILE-181" data-type="work_package" data-text="#AGILE-181">#AGILE-181</mention> (multi-select + batch move), <mention class="mention" data-id="AGILE-175" data-type="work_package" data-text="#AGILE-175">#AGILE-175</mention> (draggable buckets/sprints), <mention class="mention" data-id="AGILE-278" data-type="work_package" data-text="#AGILE-278">#AGILE-278</mention> (bulk move action), <mention class="mention" data-id="AGILE-284" data-type="work_package" data-text="#AGILE-284">#AGILE-284</mention> (optimistic reordering).

`sortable-lists` lives in generic `frontend/src/stimulus/controllers/dynamic/` — a reusable primitive, not backlogs-specific. Backlogs is its first consumer, so API quality matters beyond Backlogs.

## Options considered

  - **A — 2 controllers** (current branch): root `SortableListsController` owns the monitor, per-list drop targets, and the optimistic move/persist/rollback transaction; per-card `ItemController`. A list is a *target* of the root. Item↔root via DOM walk (`closest`) + reading a `data-…-accepted-type` attr.
  - **B — 3 controllers via outlets** (experiment PR <https://github.com/opf/openproject/pull/23739>): adds a first-class `ListController`; the root coordinates `list` + `item` leaves via Stimulus outlets. Each leaf owns the Pragmatic DnD primitive for its own DOM surface; the root pushes shared state down and reads its children as a live collection.
  - **C — 1 monolith** (the original `generic-drag-and-drop` topology, re-done in Pragmatic): one controller owns everything via targets.

## Topology illustration

![Controller topologies A, B and C annotated with Pragmatic DnD primitives: Monitor, Drop Target, Draggable](/api/v3/attachments/922018/content)

Pragmatic DnD primitives: **\[M\]** Monitor (`monitorForElements` — one per surface, runs the actual drop) · **\[D\]** Drop Target (`dropTargetForElements`) · **\[G\]** Draggable (`draggable`).

| Primitive | A (2 ctrl) | B (3 ctrl) | C (monolith) |
| --- | --- | --- | --- |
| Monitor | root | root | one controller |
| Drop Target — list | root | **list** | one controller |
| Drop Target — card/item edge | item | item | one controller |
| Draggable — card/item | item | item | one controller |

## Key Pragmatic DnD constraint

A drop target is keyed by its DOM `element`: registering two `dropTargetForElements` on the same element is unsupported (the adapter warns, and its registry stores one entry per element). So a domain object can be **both a list and an item**, but that composition must be expressed through **distinct DOM surfaces**, not two drop targets on one element. The shorthand "Sprint / Bucket = `--item --list` on the same element" is therefore invalid.

Default dual-role shape (e.g. a future Sprint that is reorderable *and* accepts cards):

``` html
<li data-controller="sortable-lists--item" data-sortable-lists--item-type-value="sprint">
  <section data-controller="sortable-lists--list" data-sortable-lists--list-type-value="sprint">
    ... work package cards ...
  </section>
</li>
```

## Recommendation (not a final decision)

Adopt **B** — single root coordinator + first-class `list`/`item` leaf controllers via outlets — with these constraints:

  - **One Pragmatic DnD drop target per DOM element.** Represent dual-role concepts (Sprint, Bucket) as separate nested/sibling item + list surfaces by default; a deliberate composite controller stays possible if one physical surface must do both.
  - **Move `acceptedType` to leaf targets** as multi-valued, per-target config (a card edge accepts `work_package`; a Sprint list surface accepts `work_package`; a Sprint item surface accepts `sprint`; a bucket item surface accepts `backlog_bucket`).
  - **Keep the root as coordinator** for shared state, selection, the monitor, move orchestration, and `type → moveUrlTemplate` resolution.

Why B over A/C: the upcoming requirements push toward first-class leaves (per-surface typed config) plus a coordinator that can enumerate its children for root-owned selection and broadcast — which A's DOM-walk + root-wide scalar can't give cleanly, and C collapses into a type-dispatch matrix that grows with selection/batch/container drag. B keeps those benefits while respecting the element-keyed drop-target registry.

## Open questions

  - Exact markup shape for <mention class="mention" data-id="AGILE-175" data-type="work_package" data-text="#AGILE-175">#AGILE-175</mention>: nested item/list surfaces, sibling surfaces, or a purpose-built composite controller.
  - Ordering rule for the N selected within the target (selection order vs source Position).
  - Partial-failure / atomicity of the batch move (<mention class="mention" data-id="AGILE-278" data-type="work_package" data-text="#AGILE-278">#AGILE-278</mention>).
  - Multi-card drag preview ("N cards") behaviour.
  - Confirm no turbo-stream re-renders the root *element* itself (would drop the in-memory selection `Set`).
  - Whether <mention class="mention" data-id="AGILE-175" data-type="work_package" data-text="#AGILE-175">#AGILE-175</mention> / <mention class="mention" data-id="AGILE-181" data-type="work_package" data-text="#AGILE-181">#AGILE-181</mention> belong in the generic `sortable-lists` primitive or in backlogs-specific adapters.
