Skip to content

Enable scrollable drag-and-drop reordering with dnd-kit#12

Closed
0suu wants to merge 1 commit into
suu/10-sort-device-listfrom
codex/add-scroll-support-while-sorting-in-dnd-kit
Closed

Enable scrollable drag-and-drop reordering with dnd-kit#12
0suu wants to merge 1 commit into
suu/10-sort-device-listfrom
codex/add-scroll-support-while-sorting-in-dnd-kit

Conversation

@0suu

@0suu 0suu commented Nov 26, 2025

Copy link
Copy Markdown
Owner

Summary

  • replace custom drag-and-drop handling for device and scene lists with dnd-kit sortable contexts while preserving existing UI behavior
  • keep wheel scrolling active during drag so longer lists can be reordered while scrolling

Testing

  • not run (npm install blocked by registry access restrictions)

Codex Task

@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello @0suu, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request undertakes a significant refactoring of the application's drag-and-drop capabilities. By migrating from a custom implementation to the dnd-kit library, the aim is to enhance the reliability and performance of list reordering for both devices and scenes. The change ensures that the user experience remains consistent, particularly with the continued support for wheel scrolling during drag operations, which is vital for navigating extensive lists.

Highlights

  • Drag-and-Drop Library Migration: The custom drag-and-drop implementation for reordering device and scene lists has been replaced with the dnd-kit library, leveraging its robust features for sorting.
  • Scrollable Reordering Maintained: The existing functionality allowing users to scroll with the mouse wheel while dragging items has been preserved, which is crucial for reordering elements in longer lists.
  • Code Refactoring and Modularity: The drag-and-drop logic has been refactored to integrate dnd-kit hooks and components, leading to the creation of new SortableDeviceCard and SortableSceneButton components for improved modularity and maintainability.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request effectively replaces the custom drag-and-drop implementation with dnd-kit, which is a great improvement for maintainability. The code is well-structured, and the extraction of sortable items into their own components is clean. I have a few suggestions to further improve the code, primarily around using dnd-kit utilities for conciseness and addressing a couple of internationalization regressions in aria-label attributes. Overall, this is a solid refactoring.

Comment on lines +218 to +224
const oldIndex = prev.indexOf(active.id as string);
const newIndex = prev.indexOf(over.id as string);
if (oldIndex === -1 || newIndex === -1) return prev;
const next = [...prev];
next.splice(oldIndex, 1);
next.splice(newIndex, 0, active.id as string);
return next;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

For improved readability and to align with dnd-kit conventions, you can use the arrayMove utility from @dnd-kit/sortable to handle the reordering logic. This makes the code more concise and the intent clearer.

You'll need to add arrayMove to your imports from @dnd-kit/sortable.

Suggested change
const oldIndex = prev.indexOf(active.id as string);
const newIndex = prev.indexOf(over.id as string);
if (oldIndex === -1 || newIndex === -1) return prev;
const next = [...prev];
next.splice(oldIndex, 1);
next.splice(newIndex, 0, active.id as string);
return next;
const oldIndex = prev.indexOf(active.id as string);
const newIndex = prev.indexOf(over.id as string);
return oldIndex > -1 && newIndex > -1 ? arrayMove(prev, oldIndex, newIndex) : prev;

boxShadow: 1,
pointerEvents: "none",
}}
aria-label="並び替え"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The aria-label for the drag handle is hardcoded in Japanese. To support internationalization, this should be a translated string passed down as a prop from the parent DeviceListScreen component, which has access to the useTranslation hook.

Example in DeviceListScreen:

<SortableDeviceCard
  {...otherProps}
  reorderAriaLabel={t("Reorder")}
/>

Then use this prop in SortableDeviceCard.

Comment on lines +185 to +191
const oldIndex = prev.indexOf(active.id as string);
const newIndex = prev.indexOf(over.id as string);
if (oldIndex === -1 || newIndex === -1) return prev;
const next = [...prev];
next.splice(oldIndex, 1);
next.splice(newIndex, 0, active.id as string);
return next;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

For improved readability and to align with dnd-kit conventions, you can use the arrayMove utility from @dnd-kit/sortable to handle the reordering logic. This makes the code more concise and the intent clearer.

You'll need to add arrayMove to your imports from @dnd-kit/sortable.

Suggested change
const oldIndex = prev.indexOf(active.id as string);
const newIndex = prev.indexOf(over.id as string);
if (oldIndex === -1 || newIndex === -1) return prev;
const next = [...prev];
next.splice(oldIndex, 1);
next.splice(newIndex, 0, active.id as string);
return next;
const oldIndex = prev.indexOf(active.id as string);
const newIndex = prev.indexOf(over.id as string);
return oldIndex > -1 && newIndex > -1 ? arrayMove(prev, oldIndex, newIndex) : prev;

boxShadow: 1,
pointerEvents: "none",
}}
aria-label="並び替え"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The aria-label for the drag handle is hardcoded in Japanese. To support internationalization, this should be a translated string passed down as a prop from the parent ScenesScreen component, which has access to the useTranslation hook.

Example in ScenesScreen:

<SortableSceneButton
  {...otherProps}
  reorderAriaLabel={t("Reorder")}
/>

Then use this prop in SortableSceneButton.

@0suu 0suu closed this Nov 26, 2025
@0suu 0suu deleted the codex/add-scroll-support-while-sorting-in-dnd-kit branch December 29, 2025 05:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant