Skip to content
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

PoC: Table Drag & Drop #9955

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

PoC: Table Drag & Drop #9955

wants to merge 6 commits into from

Conversation

DonkeyCo
Copy link
Member

This is a PoC to see what effort needs to be taken for D&D to be possible in the Table.

@@ -463,6 +483,88 @@ class Table extends UI5Element {
this.fireEvent<TableRowClickEventDetail>("row-click", { row });
}

_ondragenter(e: DragEvent) {
Copy link
Member Author

Choose a reason for hiding this comment

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

_ondragenter, _ondragover, _ondragleave are pretty much the same implementation as in List.ts.

So maybe there is a way to reuse the code in a Utility or something?

* @public
*/
@property({ type: Boolean })
movable = false;
Copy link
Member Author

Choose a reason for hiding this comment

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

technically not required, as you could just simply set draggable="true" directly on the ui5-table-row as it is in the light DOM.

But I guess, this would make sense for consistency across the API

Copy link
Contributor

@dimovpetar dimovpetar Oct 8, 2024

Choose a reason for hiding this comment

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

Yes, please use movable for consistency. It is also more meaningful in conjunction with the:

  • move and move-over events
  • potential keyboard support from your side

Last but not least, it won't work like that if you put the attribute to the root element in the shadow DOM.

@DonkeyCo DonkeyCo requested review from a team and simlin and removed request for a team September 27, 2024 12:55
@DonkeyCo DonkeyCo marked this pull request as ready for review October 2, 2024 09:57
@dimovpetar
Copy link
Contributor

Please revisit the commit history, 112 files appear as changed.

- add DragRowUtil, which provides reusable code for dragOver and drop in List and Table
- List and Table have a lot of redundant code regarding drag&drop
- extract dragover and drop into utility functions
Copy link
Contributor

Choose a reason for hiding this comment

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

Other test pages follow the pattern ComponentNameDragAndDrop.html. Please call this TableDragAndDrop.html

function tableMove(e) {
const { source, destination } = e.detail;

if (source.element.hasAttribute("ui5-table-row") && destination.element.hasAttribute("ui5-table-row")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Better do such validations in tableMoveOver. It is misleading to show drop indicator and then to cancel the operation.

Comment on lines +118 to +120
if (sourceIndex === -1 || destinationIndex === -1) {
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

* @public
*/
@property({ type: Boolean })
movable = false;
Copy link
Contributor

@dimovpetar dimovpetar Oct 8, 2024

Choose a reason for hiding this comment

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

Yes, please use movable for consistency. It is also more meaningful in conjunction with the:

  • move and move-over events
  • potential keyboard support from your side

Last but not least, it won't work like that if you put the attribute to the root element in the shadow DOM.

Comment on lines +101 to +105
if (this.movable) {
this.setAttribute("draggable", "true");
} else {
this.removeAttribute("draggable");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Better do this in TableRow.hbs, to encapsulate this attribute in a shadow DOM.

@@ -72,6 +78,17 @@ type TableRowClickEventDetail = {
row: TableRow,
};

type TableMoveEventDetail = {
Copy link
Contributor

Choose a reason for hiding this comment

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

You should also describe the move and move-overs events using @event decorator

}

export {
DragOverResult,
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems unnecessary to export DragOverResult

Copy link
Contributor

Choose a reason for hiding this comment

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

I like the idea of this util. Please move both functions to separate files. Something like handleDragOver.ts and handleDrop.ts

Comment on lines +21 to +36
const dragOverResult: DragOverResult = {
targetReference: null,
placement: null,
};

const draggedElement = DragRegistry.getDraggedElement();

if (!(e.target instanceof HTMLElement) || !draggedElement) {
return dragOverResult;
}

const closestPosition = findClosestPosition(
items,
e.clientY,
Orientation.Vertical,
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Although this code is the same for List and Table, it is not for the Tree and TabContainer. Maybe put this back to the components and only reuse the code below?

return dragOverResult;
}

function dropRow(e: DragEvent, component: UI5Element, target: HTMLElement, placement: `${MovePlacement}`): void {
Copy link
Contributor

Choose a reason for hiding this comment

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

Thumbs up for making this reusable. It will foster proper maintenance of the DragRegistry and can be directly reused by Tree and TabContainer.

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