-
Notifications
You must be signed in to change notification settings - Fork 279
refactor(ui5-list, ui5-tree, ui5-list-item-group): extract drag-and-drop logic #11928
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…rop logic - Create reusable DragAndDropHandler delegate class - Refactor List, Tree, and ListItemGroup to use shared handler - Remove duplicated drag and drop logic across components - Improve maintainability and consistency of drag/drop behavior - Support configurable drag validation and placement filtering This consolidates ~200 lines of duplicated code into a single, configurable handler that can be reused across all drag-enabled components. Fixes #11120
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors drag-and-drop functionality across UI5 components by extracting common logic into a reusable DragAndDropHandler delegate class. The refactoring eliminates code duplication while maintaining the existing drag-and-drop behavior.
- Creates a new DragAndDropHandler delegate class with configurable options for different component needs
- Refactors List, Tree, and ListItemGroup components to use the shared handler instead of duplicated logic
- Consolidates approximately 200 lines of duplicated drag-and-drop code into a single, maintainable handler
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
File | Description |
---|---|
packages/main/src/delegate/DragAndDropHandler.ts | New delegate class providing configurable drag-and-drop functionality with validation and filtering options |
packages/main/src/Tree.ts | Replaces inline drag-and-drop logic with DragAndDropHandler instance configured for tree-specific behavior |
packages/main/src/ListItemGroup.ts | Refactors to use DragAndDropHandler with group-specific placement filtering |
packages/main/src/List.ts | Updates to use DragAndDropHandler with original event handling enabled |
this._dragAndDropHandler = new DragAndDropHandler(this, { | ||
getItems: () => this.items, | ||
getDropIndicator: () => this.dropIndicatorDOM, | ||
filterPlacements: (placements, draggedElement, targetElement) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's have the filterPlacements handler as a class member as well, to keep the constructor code shorter
// Initialize the DragAndDropHandler with the necessary configurations | ||
// The handler will manage the drag and drop operations for the tree items. | ||
this._dragAndDropHandler = new DragAndDropHandler(this, { | ||
getItems: () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here as well, to keep the constructor readability, make all handlers members of the class end bind them
Description
This consolidates ~200 lines of duplicated code into a single, configurable handler that can be reused across all drag-enabled components.
Fixes: #11120