-
Type:
Task
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Data Modeling
Let's use `@dnd-kit` https://github.com/clauderic/dnd-kit
This is the same drag and drop we have in Compass currently.
An example from dnd-kit’s docs of a similar use case: https://master--5fc05e08a4a65d0021ae0bf2.chromatic.com/?path=/docs/presets-sortable-multiple-containers--vertical
The code for that example: https://github.com/clauderic/dnd-kit/blob/e9215e820798459ae036896fce7fd9a6fe855772/stories/2%20-%20Presets/Sortable/MultipleContainers.tsx
Let's add handlers on the DiagramProps Compass can use.
https://github.com/mongodb-js/diagramming/blob/1aeee833b142e1541521e23b4d6d0284aad1e620/src/types/component-props.ts#L60C18-L60C30
onFieldSelectionDrag?: (
event: ReactMouseEvent,
params:
) => void;
onFieldSelectionDragStop?: (
event: ReactMouseEvent,
params: {
source:
,
// This is the field where the fields were dropped to. If the user dragged the field(s) to empty space then the destination is undefined. We use the x, y position of the event to position the new collection node.
destination?:
}
) => void;
On the NodeField
https://github.com/mongodb-js/diagramming/blob/1aeee833b142e1541521e23b4d6d0284aad1e620/src/types/node.ts#L132
Add a draggable?: boolean which indicates if the field is draggable (also requires the drag handlers to be passed).
While dragging let's show visual indicators of the resulting action of the drag. We can do that with droppable areas. The `useDroppable` hook from dnd-kit provides an interface for that.
To not impact Migrator's performance usages let's make these draggable handlers not activate when the handler's are not passed. We add a `isFieldDroppable` to the NodeProps to indicate if the collection can be dragged on to.
Tech design:
https://docs.google.com/document/d/15Dn5FB3POEj9sYQrYIUajZySqFzlPfpcgjkPhzFqSFg/edit?tab=t.0#bookmark=id.a1gtvsp0v4jz
Designs:
https://www.figma.com/design/reNpAkCcrtlHEgBoNDiY6P/Ben-s-playground?node-id=3240-12163&t=C3ZLPfZq7cisWEga-4
- depends on
-
COMPASS-9656 Add field selection to the diagramming package
-
- Closed
-