Consider the list as flat (no group) when the element is dropped after the last element of a group

pull/8621/head
Aleix Suau 4 years ago
parent 6a40064353
commit ab3bc17975
  1. 18
      frontend/src/app/components/wp-table/drag-and-drop/actions/hierarchy-drag-action.service.ts

@ -39,12 +39,14 @@ export class HierarchyDragActionService extends TableDragActionService {
*/
private determineParent(el:HTMLElement):Promise<string|null> {
let previous = el.previousElementSibling;
var parent = null;
let next = el.nextElementSibling;
let parent = null;
if (previous !== null && !this.isFlatList(previous)) {
if (previous !== null && !this.isFlatList(previous, next)) {
// If the previous element is a relation row,
// skip it until we find the real previous sibling
const isRelationRow = previous.className.indexOf(relationRowClass()) >= 0;
if (isRelationRow) {
let relationRoot = this.findRelationRowRoot(previous);
if (relationRoot == null) {
@ -54,6 +56,7 @@ export class HierarchyDragActionService extends TableDragActionService {
}
let previousWpId = (previous as HTMLElement).dataset.workPackageId!;
if (this.isHiearchyRoot(previous, previousWpId)) {
// If the sibling is a hierarchy root, return that sibling as new parent.
parent = previousWpId;
@ -79,11 +82,18 @@ export class HierarchyDragActionService extends TableDragActionService {
return null;
}
private isFlatList(previous:Element):boolean {
private isFlatList(previous:Element, next:Element | null):boolean {
const inGroup = previous.className.indexOf(hierarchyGroupClass('')) >= 0;
const isRoot = previous.className.indexOf(hierarchyRootClass('')) >= 0;
let isLastElementInGroup;
if (inGroup) {
let previousGroup = previous && Array.from(previous.classList).find(listClass => listClass.includes('__hierarchy-group-'));
let nextGroup = next && Array.from(next.classList).find(listClass => listClass.includes('__hierarchy-group-'));
isLastElementInGroup = previousGroup !== nextGroup;
}
return !(inGroup || isRoot);
return isLastElementInGroup || !inGroup && !isRoot;
}
private isHiearchyRoot(previous:Element, previousWpId:string):boolean {

Loading…
Cancel
Save