Skip to content

Add drag-and-drop reordering for schema form arrays#3

Open
tomerqodo wants to merge 3 commits into
coderabbit_full_base_add_drag-and-drop_reordering_for_schema_form_arrays_pr3from
coderabbit_full_head_add_drag-and-drop_reordering_for_schema_form_arrays_pr3
Open

Add drag-and-drop reordering for schema form arrays#3
tomerqodo wants to merge 3 commits into
coderabbit_full_base_add_drag-and-drop_reordering_for_schema_form_arrays_pr3from
coderabbit_full_head_add_drag-and-drop_reordering_for_schema_form_arrays_pr3

Conversation

@tomerqodo

@tomerqodo tomerqodo commented Jan 30, 2026

Copy link
Copy Markdown

Benchmark PR from agentic-review-benchmarks#3

Summary by CodeRabbit

  • New Features

    • Added drag-and-drop reordering for array items in forms. Array items can now be reorganized via dragging with visual drag handles displayed for movable items.
  • Tests

    • Added snapshot tests for array-type properties in schema forms.

devin-ai-integration Bot and others added 3 commits January 25, 2026 12:09
Co-Authored-By: alex.s@prefect.io <ajstreed1@gmail.com>
- Add snapshot tests for arrays with drag handles visible
- Add snapshot tests for prefixItems without drag handles
- Add behavioral tests for move up/down menu options
- Add test verifying prefix items cannot be moved

Co-Authored-By: alex.s@prefect.io <ajstreed1@gmail.com>
@coderabbitai

coderabbitai Bot commented Jan 30, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The changes introduce drag-and-drop reordering functionality for array items in schema forms by integrating the @dnd-kit library. A new itemKey prop enables sortable tracking, with visual drag handles and reordering logic. Snapshot tests are added for array property rendering with and without drag capabilities.

Changes

Cohort / File(s) Summary
Dependency Management
ui-v2/package.json
Added three @dnd-kit runtime dependencies (@dnd-kit/core, @dnd-kit/sortable, @dnd-kit/utilities) to support drag-and-drop functionality.
Array Item Component
ui-v2/src/components/schemas/schema-form-input-array-item.tsx
Integrated useSortable hook and added itemKey prop for sortable state binding. Added GripVertical drag handle with conditional rendering based on canMove flag. Applied inline styles for drag animations (transform, transition, opacity).
Array List Component
ui-v2/src/components/schemas/schema-form-input-array-list.tsx
Wrapped array rendering in DndContext and SortableContext with verticalListSortingStrategy. Configured PointerSensor and KeyboardSensor with coordinateGetter. Implemented onDragEnd handler to reorder items via localKeyedValues and propagate changes via onValuesChange.
Array Property Tests
ui-v2/src/components/schemas/schema-form.snapshot.test.tsx
Added four new snapshot tests covering base array rendering, arrays with values (verifying drag handles), arrays with prefixItems (excluding drag handles from prefix items), and arrays with enum-constrained items.

Sequence Diagram

sequenceDiagram
    actor User
    participant List as SchemaFormInputArrayList
    participant DndContext as DndContext
    participant Sortable as SortableContext
    participant Item as SchemaFormInputArrayItem
    participant State as Local State

    User->>Item: Interact with drag handle
    Item->>DndContext: Initiate drag via sensor
    DndContext->>Sortable: Register drag event
    Sortable->>Item: Apply transform/opacity styles
    Item->>User: Show visual feedback
    User->>DndContext: Drop item at target position
    DndContext->>List: Trigger onDragEnd(event)
    List->>State: Calculate new item index
    State->>State: Reorder localKeyedValues
    State->>List: Update internal order
    List->>User: Render reordered list
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 With whiskers twitching, paws to grip,
Drag and drop makes sorting flip,
Array items dance and glide,
Sorted smooth from side to side!

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request description is minimal and only contains a benchmark reference. It does not follow the required template structure with an overview, related issue link, or relevant checklist items about tests and documentation. Add an overview of the proposed changes explaining the drag-and-drop feature implementation. Include checklist items confirming unit tests were added and reference any related issues.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title accurately describes the main change: adding drag-and-drop reordering functionality for schema form arrays, which aligns with all file changes across package.json, components, and tests.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch coderabbit_full_head_add_drag-and-drop_reordering_for_schema_form_arrays_pr3

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@tomerqodo

Copy link
Copy Markdown
Author

@coderabbitai review

1 similar comment
@tomerqodo

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jan 30, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@tomerqodo

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jan 30, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@bar-qodo

bar-qodo commented Feb 2, 2026

Copy link
Copy Markdown

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Feb 2, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
ui-v2/src/components/schemas/schema-form-input-array-list.tsx (1)

45-149: ⚠️ Potential issue | 🟠 Major

Fix drag reordering indices and block prefix item movement.

Line 142 calls moveItem(newIndex, oldIndex), but moveItem(from, to) expects the dragged item’s index first—this moves the wrong element. Also, without guarding prefixItemsCount, a non-prefix item can be dropped into the prefix range, effectively reordering prefix items.

🐛 Proposed fix
 function handleDragEnd(event: DragEndEvent) {
 	const { active, over } = event;

-	if (over && active.id !== over.id) {
-		const oldIndex = localKeyedValues.findIndex(
-			(item) => item.key === active.id,
-		);
-		const newIndex = localKeyedValues.findIndex(
-			(item) => item.key === over.id,
-		);
-
-		if (oldIndex !== -1 && newIndex !== -1) {
-			moveItem(newIndex, oldIndex);
-		}
-	}
+	if (!over || active.id === over.id) return;
+
+	const oldIndex = localKeyedValues.findIndex(
+		(item) => item.key === active.id,
+	);
+	const newIndex = localKeyedValues.findIndex(
+		(item) => item.key === over.id,
+	);
+
+	if (oldIndex === -1 || newIndex === -1) return;
+	if (oldIndex < prefixItemsCount || newIndex < prefixItemsCount) return;
+
+	moveItem(oldIndex, newIndex);
 }

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.

2 participants