From 9461632bf77213e5d59a0dc19a96c7906b3c0614 Mon Sep 17 00:00:00 2001 From: rhenck <richard.henck@iqb.hu-berlin.de> Date: Wed, 21 Feb 2024 13:22:08 +0100 Subject: [PATCH] DropList: Remove source list from viable target lists This fixes an issue where items could be added to only-one-item lists with replacement, when the item to be replaced has the same list as origin. #624 --- .../drop-list/drag-operator.service.ts | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/projects/common/components/input-elements/drop-list/drag-operator.service.ts b/projects/common/components/input-elements/drop-list/drag-operator.service.ts index 4bba19406..089c966f6 100644 --- a/projects/common/components/input-elements/drop-list/drag-operator.service.ts +++ b/projects/common/components/input-elements/drop-list/drag-operator.service.ts @@ -51,16 +51,16 @@ export class DragOperatorService { listComp.stopListenForHover(); }); } - this.dragOperation.targetComponent?.refreshItemsFromForm(); - this.dragOperation.targetComponent?.cdr.detectChanges(); // reset placeholder CSS } private resetListEffects(): void { - this.dragOperation?.eligibleTargetListsIDs.forEach(listID => { - this.dropLists[listID].isHovered = false; - this.dropLists[listID].isHighlighted = false; - this.dropLists[listID].cdr.detectChanges(); - }); + if (!this.dragOperation) throw new Error('dragOP undefined'); + [...this.dragOperation.eligibleTargetListsIDs, this.dragOperation.sourceComponent.elementModel.id] + .forEach(listID => { + this.dropLists[listID].isHovered = false; + this.dropLists[listID].isHighlighted = false; + this.dropLists[listID].cdr.detectChanges(); + }); } setTargetList(listId: string): void { @@ -200,10 +200,10 @@ export class DragOperatorService { sourceList: DropListComponent, targetList: DropListComponent, allLists: { [id: string]: DropListComponent }): boolean { - return sourceList.elementModel.id === targetList.elementModel.id || // TODO: Use parenthesis - DragOperatorService.checkConnected(sourceList, targetList) && + return (sourceList.elementModel.isSortList) || + (DragOperatorService.checkConnected(sourceList, targetList) && DragOperatorService.checkOnlyOneItem(targetList, allLists) && - DragOperatorService.checkAddForeignItemToCopyList(draggedItem, targetList); + DragOperatorService.checkAddForeignItemToCopyList(draggedItem, targetList)); } /* Drop is only allowed in connected Lists AND THE SAME LIST. */ -- GitLab