Correctly cycles the unresolved discussions

Switches back to discussion tab when clicking jump to next unresolved button
This commit is contained in:
Phil Hughes 2016-07-29 13:31:32 +01:00
parent 4e679819f2
commit 6f94f62f72
7 changed files with 27 additions and 8 deletions

View file

@ -1,5 +1,5 @@
((w) => { ((w) => {
w.ResolveCommentBtn = Vue.extend({ w.CommentAndResolveBtn = Vue.extend({
props: { props: {
discussionId: String discussionId: String
}, },

View file

@ -37,9 +37,20 @@
i++; i++;
} }
} else { } else {
let nextDiscussionId;
const discussionKeys = Object.keys(this.discussions), const discussionKeys = Object.keys(this.discussions),
indexOfDiscussion = discussionKeys.indexOf(this.discussionId), indexOfDiscussion = discussionKeys.indexOf(this.discussionId);
nextDiscussionId = discussionKeys[indexOfDiscussion + 1]; nextDiscussionIds = discussionKeys.splice(indexOfDiscussion);
nextDiscussionIds.forEach((discussionId) => {
if (discussionId !== this.discussionId) {
const discussion = this.discussions[discussionId];
if (!discussion.isResolved()) {
nextDiscussionId = discussion.id;
}
}
});
if (nextDiscussionId) { if (nextDiscussionId) {
nextUnresolvedDiscussionId = nextDiscussionId; nextUnresolvedDiscussionId = nextDiscussionId;
@ -54,6 +65,9 @@
} }
if (nextUnresolvedDiscussionId) { if (nextUnresolvedDiscussionId) {
$('#notes').addClass('active');
$('#commits, #builds, #diffs').removeClass('active');
$.scrollTo(`.discussion[data-discussion-id="${nextUnresolvedDiscussionId}"]`, { $.scrollTo(`.discussion[data-discussion-id="${nextUnresolvedDiscussionId}"]`, {
offset: -($('.navbar-gitlab').outerHeight() + $('.layout-nav').outerHeight()) offset: -($('.navbar-gitlab').outerHeight() + $('.layout-nav').outerHeight())
}); });

View file

@ -12,7 +12,7 @@ $(() => {
components: { components: {
'resolve-btn': ResolveBtn, 'resolve-btn': ResolveBtn,
'resolve-discussion-btn': ResolveDiscussionBtn, 'resolve-discussion-btn': ResolveDiscussionBtn,
'resolve-comment-btn': ResolveCommentBtn 'comment-and-resolve-btn': CommentAndResolveBtn
} }
}); });

View file

@ -1,12 +1,12 @@
class DiscussionModel { class DiscussionModel {
constructor (discussionId) { constructor (discussionId) {
this.discussionId = discussionId; this.id = discussionId;
this.notes = {}; this.notes = {};
this.loading = false; this.loading = false;
} }
createNote (noteId, resolved, user) { createNote (noteId, resolved, user) {
Vue.set(this.notes, noteId, new NoteModel(this.discussionId, noteId, resolved, user)); Vue.set(this.notes, noteId, new NoteModel(this.id, noteId, resolved, user));
} }
deleteNote (noteId) { deleteNote (noteId) {

View file

@ -1,7 +1,7 @@
class NoteModel { class NoteModel {
constructor (discussionId, noteId, resolved, user) { constructor (discussionId, noteId, resolved, user) {
this.discussionId = discussionId; this.discussionId = discussionId;
this.noteId = noteId; this.id = noteId;
this.resolved = resolved; this.resolved = resolved;
this.user = user; this.user = user;
} }

View file

@ -4,7 +4,7 @@
= link_to 'Close merge request', merge_request_path(@merge_request, merge_request: {state_event: :close }), method: :put, class: "btn btn-nr btn-comment btn-close close-mr-link js-note-target-close", title: "Close merge request", data: {original_text: "Close merge request", alternative_text: "Comment & close merge request"} = link_to 'Close merge request', merge_request_path(@merge_request, merge_request: {state_event: :close }), method: :put, class: "btn btn-nr btn-comment btn-close close-mr-link js-note-target-close", title: "Close merge request", data: {original_text: "Close merge request", alternative_text: "Comment & close merge request"}
- if @merge_request.closed? - if @merge_request.closed?
= link_to 'Reopen merge request', merge_request_path(@merge_request, merge_request: {state_event: :reopen }), method: :put, class: "btn btn-nr btn-comment btn-reopen reopen-mr-link js-note-target-reopen", title: "Reopen merge request", data: {original_text: "Reopen merge request", alternative_text: "Comment & reopen merge request"} = link_to 'Reopen merge request', merge_request_path(@merge_request, merge_request: {state_event: :reopen }), method: :put, class: "btn btn-nr btn-comment btn-reopen reopen-mr-link js-note-target-reopen", title: "Reopen merge request", data: {original_text: "Reopen merge request", alternative_text: "Comment & reopen merge request"}
%resolve-comment-btn{ "inline-template" => true, ":discussion-id" => "" } %comment-and-resolve-btn{ "inline-template" => true, ":discussion-id" => "" }
%button.btn.btn-nr.btn-default.append-right-10.js-comment-resolve-button{ type: "submit", data: { namespace_path: "#{@merge_request.project.namespace.path}", project_path: "#{@merge_request.project.path}" } } %button.btn.btn-nr.btn-default.append-right-10.js-comment-resolve-button{ type: "submit", data: { namespace_path: "#{@merge_request.project.namespace.path}", project_path: "#{@merge_request.project.path}" } }
{{ buttonText }} {{ buttonText }}

View file

@ -35,6 +35,7 @@ feature 'Diff notes resolve', feature: true, js: true do
find('.line-resolve-btn').click find('.line-resolve-btn').click
expect(page).to have_selector('.line-resolve-btn.is-active') expect(page).to have_selector('.line-resolve-btn.is-active')
expect(find('.line-resolve-btn')['data-original-title']).to eq("Resolved by #{user.name}")
end end
page.within '.diff-content' do page.within '.diff-content' do
@ -54,6 +55,8 @@ feature 'Diff notes resolve', feature: true, js: true do
page.within '.diff-content .note' do page.within '.diff-content .note' do
expect(page).to have_selector('.line-resolve-btn.is-active') expect(page).to have_selector('.line-resolve-btn.is-active')
expect(find('.line-resolve-btn')['data-original-title']).to eq("Resolved by #{user.name}")
end end
page.within '.line-resolve-all-container' do page.within '.line-resolve-all-container' do
@ -147,6 +150,8 @@ feature 'Diff notes resolve', feature: true, js: true do
it 'does not mark discussion as resolved when resolving single note' do it 'does not mark discussion as resolved when resolving single note' do
page.within '.diff-content .note' do page.within '.diff-content .note' do
first('.line-resolve-btn').click first('.line-resolve-btn').click
sleep 1
expect(first('.line-resolve-btn')['data-original-title']).to eq("Resolved by #{user.name}")
end end
expect(page).to have_content('Last updated') expect(page).to have_content('Last updated')