Commit f86b545f authored by Phil Hughes's avatar Phil Hughes

Merge branch 'xanf-fix-unresolved-discussion-jump' into 'master'

Next unresolved discussion button takes user to the right place

See merge request gitlab-org/gitlab!20620
parents 7de10073 0c735632
...@@ -19,6 +19,7 @@ export default { ...@@ -19,6 +19,7 @@ export default {
'resolvableDiscussionsCount', 'resolvableDiscussionsCount',
'firstUnresolvedDiscussionId', 'firstUnresolvedDiscussionId',
'unresolvedDiscussionsCount', 'unresolvedDiscussionsCount',
'getDiscussion',
]), ]),
isLoggedIn() { isLoggedIn() {
return this.getUserData.id; return this.getUserData.id;
...@@ -40,9 +41,10 @@ export default { ...@@ -40,9 +41,10 @@ export default {
...mapActions(['expandDiscussion']), ...mapActions(['expandDiscussion']),
jumpToFirstUnresolvedDiscussion() { jumpToFirstUnresolvedDiscussion() {
const diffTab = window.mrTabs.currentAction === 'diffs'; const diffTab = window.mrTabs.currentAction === 'diffs';
const discussionId = this.firstUnresolvedDiscussionId(diffTab); const discussionId =
this.firstUnresolvedDiscussionId(diffTab) || this.firstUnresolvedDiscussionId();
this.jumpToDiscussion(discussionId); const firstDiscussion = this.getDiscussion(discussionId);
this.jumpToDiscussion(firstDiscussion);
}, },
}, },
}; };
......
...@@ -19,7 +19,11 @@ export default { ...@@ -19,7 +19,11 @@ export default {
}; };
}, },
computed: { computed: {
...mapGetters(['nextUnresolvedDiscussionId', 'previousUnresolvedDiscussionId']), ...mapGetters([
'nextUnresolvedDiscussionId',
'previousUnresolvedDiscussionId',
'getDiscussion',
]),
}, },
mounted() { mounted() {
Mousetrap.bind('n', () => this.jumpToNextDiscussion()); Mousetrap.bind('n', () => this.jumpToNextDiscussion());
...@@ -33,14 +37,14 @@ export default { ...@@ -33,14 +37,14 @@ export default {
...mapActions(['expandDiscussion']), ...mapActions(['expandDiscussion']),
jumpToNextDiscussion() { jumpToNextDiscussion() {
const nextId = this.nextUnresolvedDiscussionId(this.currentDiscussionId, this.isDiffView); const nextId = this.nextUnresolvedDiscussionId(this.currentDiscussionId, this.isDiffView);
const nextDiscussion = this.getDiscussion(nextId);
this.jumpToDiscussion(nextId); this.jumpToDiscussion(nextDiscussion);
this.currentDiscussionId = nextId; this.currentDiscussionId = nextId;
}, },
jumpToPreviousDiscussion() { jumpToPreviousDiscussion() {
const prevId = this.previousUnresolvedDiscussionId(this.currentDiscussionId, this.isDiffView); const prevId = this.previousUnresolvedDiscussionId(this.currentDiscussionId, this.isDiffView);
const prevDiscussion = this.getDiscussion(prevId);
this.jumpToDiscussion(prevId); this.jumpToDiscussion(prevDiscussion);
this.currentDiscussionId = prevId; this.currentDiscussionId = prevId;
}, },
}, },
......
...@@ -84,6 +84,7 @@ export default { ...@@ -84,6 +84,7 @@ export default {
'hasUnresolvedDiscussions', 'hasUnresolvedDiscussions',
'showJumpToNextDiscussion', 'showJumpToNextDiscussion',
'getUserData', 'getUserData',
'getDiscussion',
]), ]),
currentUser() { currentUser() {
return this.getUserData; return this.getUserData;
...@@ -221,8 +222,9 @@ export default { ...@@ -221,8 +222,9 @@ export default {
this.discussion.id, this.discussion.id,
this.discussionsByDiffOrder, this.discussionsByDiffOrder,
); );
const nextDiscussion = this.getDiscussion(nextId);
this.jumpToDiscussion(nextId); this.jumpToDiscussion(nextDiscussion);
}, },
deleteNoteHandler(note) { deleteNoteHandler(note) {
this.$emit('noteDeleted', this.discussion, note); this.$emit('noteDeleted', this.discussion, note);
......
...@@ -35,20 +35,26 @@ export default { ...@@ -35,20 +35,26 @@ export default {
return false; return false;
}, },
jumpToDiscussion(id) {
if (id) {
const activeTab = window.mrTabs.currentAction;
if (activeTab === 'diffs') { switchToDiscussionsTabAndJumpTo(id) {
this.diffsJump(id);
} else if (activeTab === 'commits' || activeTab === 'pipelines') {
window.mrTabs.eventHub.$once('MergeRequestTabChange', () => { window.mrTabs.eventHub.$once('MergeRequestTabChange', () => {
setTimeout(() => this.discussionJump(id), 0); setTimeout(() => this.discussionJump(id), 0);
}); });
window.mrTabs.tabShown('show'); window.mrTabs.tabShown('show');
} else { },
jumpToDiscussion(discussion) {
const { id, diff_discussion: isDiffDiscussion } = discussion;
if (id) {
const activeTab = window.mrTabs.currentAction;
if (activeTab === 'diffs' && isDiffDiscussion) {
this.diffsJump(id);
} else if (activeTab === 'show') {
this.discussionJump(id); this.discussionJump(id);
} else {
this.switchToDiscussionsTabAndJumpTo(id);
} }
} }
}, },
......
---
title: Ensure next unresolved discussion button takes user to the right place
merge_request: 20620
author:
type: fixed
...@@ -37,6 +37,7 @@ describe('notes/components/discussion_keyboard_navigator', () => { ...@@ -37,6 +37,7 @@ describe('notes/components/discussion_keyboard_navigator', () => {
isDiff ? NEXT_DIFF_ID : NEXT_ID; isDiff ? NEXT_DIFF_ID : NEXT_ID;
notes.getters.previousUnresolvedDiscussionId = () => (currId, isDiff) => notes.getters.previousUnresolvedDiscussionId = () => (currId, isDiff) =>
isDiff ? PREV_DIFF_ID : PREV_ID; isDiff ? PREV_DIFF_ID : PREV_ID;
notes.getters.getDiscussion = () => id => ({ id });
storeOptions = { storeOptions = {
modules: { modules: {
...@@ -63,14 +64,18 @@ describe('notes/components/discussion_keyboard_navigator', () => { ...@@ -63,14 +64,18 @@ describe('notes/components/discussion_keyboard_navigator', () => {
it('calls jumpToNextDiscussion when pressing `n`', () => { it('calls jumpToNextDiscussion when pressing `n`', () => {
Mousetrap.trigger('n'); Mousetrap.trigger('n');
expect(wrapper.vm.jumpToDiscussion).toHaveBeenCalledWith(expectedNextId); expect(wrapper.vm.jumpToDiscussion).toHaveBeenCalledWith(
expect.objectContaining({ id: expectedNextId }),
);
expect(wrapper.vm.currentDiscussionId).toEqual(expectedNextId); expect(wrapper.vm.currentDiscussionId).toEqual(expectedNextId);
}); });
it('calls jumpToPreviousDiscussion when pressing `p`', () => { it('calls jumpToPreviousDiscussion when pressing `p`', () => {
Mousetrap.trigger('p'); Mousetrap.trigger('p');
expect(wrapper.vm.jumpToDiscussion).toHaveBeenCalledWith(expectedPrevId); expect(wrapper.vm.jumpToDiscussion).toHaveBeenCalledWith(
expect.objectContaining({ id: expectedPrevId }),
);
expect(wrapper.vm.currentDiscussionId).toEqual(expectedPrevId); expect(wrapper.vm.currentDiscussionId).toEqual(expectedPrevId);
}); });
}); });
......
...@@ -27,6 +27,8 @@ describe('DiscussionCounter component', () => { ...@@ -27,6 +27,8 @@ describe('DiscussionCounter component', () => {
describe('methods', () => { describe('methods', () => {
describe('jumpToFirstUnresolvedDiscussion', () => { describe('jumpToFirstUnresolvedDiscussion', () => {
it('expands unresolved discussion', () => { it('expands unresolved discussion', () => {
window.mrTabs.currentAction = 'show';
spyOn(vm, 'expandDiscussion').and.stub(); spyOn(vm, 'expandDiscussion').and.stub();
const discussions = [ const discussions = [
{ {
...@@ -47,14 +49,39 @@ describe('DiscussionCounter component', () => { ...@@ -47,14 +49,39 @@ describe('DiscussionCounter component', () => {
...store.state, ...store.state,
discussions, discussions,
}); });
setFixtures(`
<div class="discussion" data-discussion-id="${firstDiscussionId}"></div>
`);
vm.jumpToFirstUnresolvedDiscussion(); vm.jumpToFirstUnresolvedDiscussion();
expect(vm.expandDiscussion).toHaveBeenCalledWith({ discussionId: firstDiscussionId }); expect(vm.expandDiscussion).toHaveBeenCalledWith({ discussionId: firstDiscussionId });
}); });
it('jumps to first unresolved discussion from diff tab if all diff discussions are resolved', () => {
window.mrTabs.currentAction = 'diff';
spyOn(vm, 'switchToDiscussionsTabAndJumpTo').and.stub();
const unresolvedId = discussionMock.id + 1;
const discussions = [
{
...discussionMock,
id: discussionMock.id,
diff_discussion: true,
notes: [{ ...discussionMock.notes[0], resolvable: true, resolved: true }],
resolved: true,
},
{
...discussionMock,
id: unresolvedId,
notes: [{ ...discussionMock.notes[0], resolvable: true, resolved: false }],
resolved: false,
},
];
store.replaceState({
...store.state,
discussions,
});
vm.jumpToFirstUnresolvedDiscussion();
expect(vm.switchToDiscussionsTabAndJumpTo).toHaveBeenCalledWith(unresolvedId);
});
}); });
}); });
}); });
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