Enable scrollable drag-and-drop reordering with dnd-kit#12
Conversation
Summary of ChangesHello @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 Highlights
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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.
| 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; |
There was a problem hiding this comment.
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.
| 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="並び替え" |
There was a problem hiding this comment.
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.
| 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; |
There was a problem hiding this comment.
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.
| 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="並び替え" |
There was a problem hiding this comment.
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.
Summary
Testing
Codex Task