Commit 2247d8a4 authored by Phil Hughes's avatar Phil Hughes
Browse files

Updates the text above discussions when resolving notes & discussions

parent 86446846
......@@ -56,6 +56,8 @@
if (response.status === 200) {
CommentsStore.update(this.discussionId, this.noteId, !this.isResolved, user);
ResolveService.updateUpdatedHtml(this.discussionId, data);
}
this.$nextTick(this.updateTooltip);
......
......@@ -58,6 +58,8 @@
CommentsStore.loading[discussionId] = false;
CommentsStore.updateCommentsForDiscussion(discussionId, true, user);
this.updateUpdatedHtml(discussionId, data);
});
}
......@@ -71,11 +73,28 @@
mergeRequestId,
discussionId
}, {}).then((response) => {
const data = response.data;
CommentsStore.loading[discussionId] = false;
CommentsStore.updateCommentsForDiscussion(discussionId, false);
this.updateUpdatedHtml(discussionId, data);
});
}
updateUpdatedHtml(discussionId, data) {
const $discussionHeadline = $(`.${discussionId} .js-discussion-headline`);
if (data.updated_html) {
if ($discussionHeadline.length) {
$discussionHeadline.replaceWith(data.updated_html);
} else {
$(`.${discussionId} .discussion-header`).append(data.updated_html);
}
} else {
$discussionHeadline.remove();
}
}
}
w.ResolveService = new ResolveServiceClass();
......
......@@ -10,7 +10,8 @@ def resolve
discussion.resolve!(current_user)
render json: {
resolved_by: discussion.resolved_by.try(:name)
resolved_by: discussion.resolved_by.try(:name),
updated_html: view_to_html_string('discussions/_headline', discussion: discussion)
}
end
......@@ -19,7 +20,9 @@ def unresolve
discussion.unresolve!
head :ok
render json: {
updated_html: view_to_html_string('discussions/_headline', discussion: discussion)
}
end
private
......
......@@ -72,8 +72,11 @@ def resolve
note.resolve!(current_user)
discussion = note.noteable.discussions.find { |d| d.id == note.discussion_id } || render_404
render json: {
resolved_by: note.resolved_by.try(:name)
resolved_by: note.resolved_by.try(:name),
updated_html: view_to_html_string('discussions/_headline', discussion: discussion)
}
end
......@@ -82,7 +85,11 @@ def unresolve
note.unresolve!
head :ok
discussion = note.noteable.discussions.find { |d| d.id == note.discussion_id } || render_404
render json: {
updated_html: view_to_html_string('discussions/_headline', discussion: discussion)
}
end
private
......
......@@ -38,21 +38,7 @@
= time_ago_with_tooltip(discussion.created_at, placement: "bottom", html_class: "note-created-ago")
-# TODO: Live update!
- if discussion.resolved?
.discussion-headline-light
Resolved
- if discussion.resolved_by
by
= link_to_member(@project, discussion.resolved_by, avatar: false)
= time_ago_with_tooltip(discussion.resolved_at, placement: "bottom")
- elsif discussion.last_updated_at != discussion.created_at
.discussion-headline-light
Last updated
- if discussion.last_updated_by
by
= link_to_member(@project, discussion.last_updated_by, avatar: false)
= time_ago_with_tooltip(discussion.last_updated_at, placement: "bottom")
= render "discussions/headline", discussion: discussion
.discussion-body.js-toggle-content{ class: ("hide" unless expanded) }
- if discussion.diff_discussion? && discussion.diff_file
......
- if discussion.resolved?
.discussion-headline-light.js-discussion-headline
Resolved
- if discussion.resolved_by
by
= link_to_member(@project, discussion.resolved_by, avatar: false)
= time_ago_with_tooltip(discussion.resolved_at, placement: "bottom")
- elsif discussion.last_updated_at != discussion.created_at
.discussion-headline-light.js-discussion-headline
Last updated
- if discussion.last_updated_by
by
= link_to_member(@project, discussion.last_updated_by, avatar: false)
= time_ago_with_tooltip(discussion.last_updated_at, placement: "bottom")
......@@ -11,7 +11,7 @@
= link_to_reply_discussion(discussion_left, 'old')
.btn-group{ role: "group" }
= render "discussions/resolve_all", discussion: discussion_left
= render "discussions/jump_to_next", discussion: discussion
= render "discussions/jump_to_next", discussion: discussion_left
- else
%td.notes_line.old= ""
%td.notes_content.parallel.old= ""
......@@ -28,7 +28,7 @@
= link_to_reply_discussion(discussion_right, 'new')
.btn-group{ role: "group" }
= render "discussions/resolve_all", discussion: discussion_right
= render "discussions/jump_to_next", discussion: discussion
= render "discussions/jump_to_next", discussion: discussion_right
- else
%td.notes_line.new= ""
%td.notes_content.parallel.new= ""
......@@ -119,7 +119,7 @@
page.find('.discussion-next-btn').click
end
expect(page.evaluate_script("$('body').scrollTop()")).to be 495
expect(page.evaluate_script("$('body').scrollTop()")).to be > 0
end
it 'hides jump to next button when all resolved' do
......@@ -129,6 +129,44 @@
expect(page).to have_selector('.discussion-next-btn', visible: false)
end
it 'updates updated text after resolving note' do
page.within '.diff-content .note' do
find('.line-resolve-btn').click
end
expect(page).to have_content("Resolved by #{user.name}")
end
end
context 'multiple notes' do
before do
create(:diff_note_on_merge_request, project: project, noteable: merge_request)
end
it 'does not mark discussion as resolved when resolving single note' do
page.within '.diff-content .note' do
first('.line-resolve-btn').click
end
expect(page).to have_content('Last updated')
page.within '.line-resolve-all-container' do
expect(page).to have_content('0/1 discussion resolved')
end
end
it 'resolves discussion' do
page.all('.note').each do |note|
note.find('.line-resolve-btn').click
end
expect(page).to have_content('Resolved by')
page.within '.line-resolve-all-container' do
expect(page).to have_content('1/1 discussion resolved')
end
end
end
context 'muliple discussions' do
......@@ -184,7 +222,15 @@
page.find('.discussion-next-btn').click
end
expect(page.evaluate_script("$('body').scrollTop()")).to be 495
expect(page.evaluate_script("$('body').scrollTop()")).to be > 0
end
it 'updates updated text after resolving note' do
page.within first('.diff-content .note') do
find('.line-resolve-btn').click
end
expect(page).to have_content("Resolved by #{user.name}")
end
end
......
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