Jumps between discussions on the changes tab
Ordered the jump to discussion by order in the DOM
This commit is contained in:
parent
433f1c42c3
commit
69c7fc5f72
2 changed files with 34 additions and 25 deletions
|
@ -43,38 +43,34 @@
|
|||
},
|
||||
methods: {
|
||||
jumpToNextUnresolvedDiscussion: function () {
|
||||
let nextUnresolvedDiscussionId,
|
||||
firstUnresolvedDiscussionId,
|
||||
useNextDiscussionId = false,
|
||||
i = 0;
|
||||
let unresolvedIds = CommentsStore.unresolvedDiscussionIds(),
|
||||
nextUnresolvedDiscussionId;
|
||||
const activePage = $('.merge-request-tabs .active a').attr('data-action'),
|
||||
$diffDiscussions = $('.discussion').filter(function () {
|
||||
return unresolvedIds.indexOf($(this).attr('data-discussion-id')) !== -1;
|
||||
});
|
||||
|
||||
for (const discussionId in this.discussions) {
|
||||
const discussion = this.discussions[discussionId];
|
||||
unresolvedIds = unresolvedIds.sort(function (a, b) {
|
||||
return $diffDiscussions.index(`[data-discussion-id="${b}"]`) > $diffDiscussions.index(`[data-discussion-id="${a}"]`);
|
||||
});
|
||||
|
||||
if (!discussion.isResolved()) {
|
||||
if (i === 0) {
|
||||
firstUnresolvedDiscussionId = discussion.id;
|
||||
unresolvedIds.forEach(function (discussionId, i) {
|
||||
if (this.discussionId && discussionId === this.discussionId) {
|
||||
nextUnresolvedDiscussionId = unresolvedIds[i + 1];
|
||||
return;
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
if (useNextDiscussionId) {
|
||||
nextUnresolvedDiscussionId = discussion.id;
|
||||
break;
|
||||
}
|
||||
|
||||
if (this.discussionId && discussion.id === this.discussionId) {
|
||||
useNextDiscussionId = true;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
nextUnresolvedDiscussionId = nextUnresolvedDiscussionId || firstUnresolvedDiscussionId
|
||||
nextUnresolvedDiscussionId = nextUnresolvedDiscussionId || unresolvedIds[0];
|
||||
|
||||
if (nextUnresolvedDiscussionId) {
|
||||
mrTabs.activateTab('notes');
|
||||
let selector = '.discussion';
|
||||
|
||||
$.scrollTo(`.discussion[data-discussion-id="${nextUnresolvedDiscussionId}"]`, {
|
||||
if (activePage === 'diffs' && $(`${selector}[data-discussion-id="${nextUnresolvedDiscussionId}"]`).length) {
|
||||
selector = '.diffs .notes';
|
||||
}
|
||||
|
||||
$.scrollTo(`${selector}[data-discussion-id="${nextUnresolvedDiscussionId}"]`, {
|
||||
offset: -($('.navbar-gitlab').outerHeight() + $('.layout-nav').outerHeight())
|
||||
});
|
||||
}
|
||||
|
|
|
@ -26,6 +26,19 @@
|
|||
if (discussion.notesCount() === 0) {
|
||||
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);
|
||||
|
|
Loading…
Reference in a new issue