Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

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

Aleix Suauab3bc179750c
diff --git a/frontend/src/app/components/wp-table/drag-and-drop/actions/hierarchy-drag-action.service.ts b/frontend/src/app/components/wp-table/drag-and-drop/actions/hierarchy-drag-action.service.ts
index feb867ec168..057c1ac2758 100644
--- a/frontend/src/app/components/wp-table/drag-and-drop/actions/hierarchy-drag-action.service.ts
+++ b/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 {