Commit 69c7fc5f authored by Phil Hughes's avatar Phil Hughes

Jumps between discussions on the changes tab

Ordered the jump to discussion by order in the DOM
parent 433f1c42
...@@ -43,38 +43,34 @@ ...@@ -43,38 +43,34 @@
}, },
methods: { methods: {
jumpToNextUnresolvedDiscussion: function () { jumpToNextUnresolvedDiscussion: function () {
let nextUnresolvedDiscussionId, let unresolvedIds = CommentsStore.unresolvedDiscussionIds(),
firstUnresolvedDiscussionId, nextUnresolvedDiscussionId;
useNextDiscussionId = false, const activePage = $('.merge-request-tabs .active a').attr('data-action'),
i = 0; $diffDiscussions = $('.discussion').filter(function () {
return unresolvedIds.indexOf($(this).attr('data-discussion-id')) !== -1;
});
for (const discussionId in this.discussions) { unresolvedIds = unresolvedIds.sort(function (a, b) {
const discussion = this.discussions[discussionId]; return $diffDiscussions.index(`[data-discussion-id="${b}"]`) > $diffDiscussions.index(`[data-discussion-id="${a}"]`);
});
if (!discussion.isResolved()) { unresolvedIds.forEach(function (discussionId, i) {
if (i === 0) { if (this.discussionId && discussionId === this.discussionId) {
firstUnresolvedDiscussionId = discussion.id; nextUnresolvedDiscussionId = unresolvedIds[i + 1];
return;
} }
}.bind(this));
if (useNextDiscussionId) { nextUnresolvedDiscussionId = nextUnresolvedDiscussionId || unresolvedIds[0];
nextUnresolvedDiscussionId = discussion.id;
break;
}
if (this.discussionId && discussion.id === this.discussionId) { if (nextUnresolvedDiscussionId) {
useNextDiscussionId = true; let selector = '.discussion';
}
i++; if (activePage === 'diffs' && $(`${selector}[data-discussion-id="${nextUnresolvedDiscussionId}"]`).length) {
} selector = '.diffs .notes';
} }
nextUnresolvedDiscussionId = nextUnresolvedDiscussionId || firstUnresolvedDiscussionId $.scrollTo(`${selector}[data-discussion-id="${nextUnresolvedDiscussionId}"]`, {
if (nextUnresolvedDiscussionId) {
mrTabs.activateTab('notes');
$.scrollTo(`.discussion[data-discussion-id="${nextUnresolvedDiscussionId}"]`, {
offset: -($('.navbar-gitlab').outerHeight() + $('.layout-nav').outerHeight()) offset: -($('.navbar-gitlab').outerHeight() + $('.layout-nav').outerHeight())
}); });
} }
......
...@@ -26,6 +26,19 @@ ...@@ -26,6 +26,19 @@
if (discussion.notesCount() === 0) { if (discussion.notesCount() === 0) {
Vue.delete(this.state, discussionId); Vue.delete(this.state, discussionId);
} }
},
unresolvedDiscussionIds: function () {
let ids = [];
for (const discussionId in this.state) {
const discussion = this.state[discussionId];
if (!discussion.isResolved()) {
ids.push(discussion.id);
}
}
return ids;
} }
}; };
})(window); })(window);
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