Commit 0d626bda authored by Kushal Pandya's avatar Kushal Pandya

Fix issue reordering for swapping of items

parent ba1c613d
...@@ -103,33 +103,18 @@ export default { ...@@ -103,33 +103,18 @@ export default {
toggleAddRelatedIssuesForm() { toggleAddRelatedIssuesForm() {
eventHub.$emit('toggleAddRelatedIssuesForm'); eventHub.$emit('toggleAddRelatedIssuesForm');
}, },
getBeforeAfterId(newIndex, lastIndex) { getBeforeAfterId(itemEl) {
let beforeId = null; const prevItemEl = itemEl.previousElementSibling;
let afterId = null; const nextItemEl = itemEl.nextElementSibling;
if (newIndex === 0) {
// newIndex is 0, item was moved to top => send only afterId
afterId = this.relatedIssues[newIndex].epic_issue_id;
} else if (newIndex === lastIndex) {
// newIndex is lastIndex, item was moved to bottom => send only beforeId
beforeId = this.relatedIssues[newIndex].epic_issue_id;
} else {
// leave default
beforeId = this.relatedIssues[newIndex - 1].epic_issue_id;
afterId = this.relatedIssues[newIndex].epic_issue_id;
}
return { return {
beforeId, beforeId: prevItemEl && parseInt(prevItemEl.dataset.epicIssueId, 0),
afterId, afterId: nextItemEl && parseInt(nextItemEl.dataset.epicIssueId, 0),
}; };
}, },
reordered(event) { reordered(event) {
this.removeDraggingCursor(); this.removeDraggingCursor();
const { const { beforeId, afterId } = this.getBeforeAfterId(event.item);
beforeId,
afterId,
} = this.getBeforeAfterId(event.newIndex, this.relatedIssues.length - 1);
this.$emit('saveReorder', { this.$emit('saveReorder', {
issueId: parseInt(event.item.dataset.key, 10), issueId: parseInt(event.item.dataset.key, 10),
...@@ -240,6 +225,7 @@ issue-count-badge-add-button btn btn-sm btn-default" ...@@ -240,6 +225,7 @@ issue-count-badge-add-button btn btn-sm btn-default"
card: canReorder card: canReorder
}" }"
:data-key="issue.id" :data-key="issue.id"
:data-epic-issue-id="issue.epic_issue_id"
> >
<issue-item <issue-item
event-namespace="relatedIssue" event-namespace="relatedIssue"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment