Commit 7495140d authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Expand discussion when opening link to comment

Makes discussion expansion depend on `discussion.expanded`
parent 66054aeb
...@@ -87,13 +87,10 @@ export default { ...@@ -87,13 +87,10 @@ export default {
}, },
}, },
data() { data() {
const { diff_discussion: isDiffDiscussion, resolved } = this.discussion;
return { return {
isReplying: false, isReplying: false,
isResolving: false, isResolving: false,
resolveAsThread: true, resolveAsThread: true,
isRepliesCollapsed: Boolean(!isDiffDiscussion && resolved),
}; };
}, },
computed: { computed: {
...@@ -178,11 +175,11 @@ export default { ...@@ -178,11 +175,11 @@ export default {
return ''; return '';
}, },
shouldShowDiscussions() { isExpanded() {
const { expanded, resolved } = this.discussion; return this.discussion.expanded || this.alwaysExpanded;
const isResolvedNonDiffDiscussion = !this.discussion.diff_discussion && resolved; },
shouldHideDiscussionBody() {
return expanded || this.alwaysExpanded || isResolvedNonDiffDiscussion; return this.shouldRenderDiffs && !this.isExpanded;
}, },
actionText() { actionText() {
const linkStart = `<a href="${_.escape(this.discussion.discussion_path)}">`; const linkStart = `<a href="${_.escape(this.discussion.discussion_path)}">`;
...@@ -282,9 +279,6 @@ export default { ...@@ -282,9 +279,6 @@ export default {
toggleDiscussionHandler() { toggleDiscussionHandler() {
this.toggleDiscussion({ discussionId: this.discussion.id }); this.toggleDiscussion({ discussionId: this.discussion.id });
}, },
toggleReplies() {
this.isRepliesCollapsed = !this.isRepliesCollapsed;
},
showReplyForm() { showReplyForm() {
this.isReplying = true; this.isReplying = true;
}, },
...@@ -405,7 +399,7 @@ Please check your network connection and try again.`; ...@@ -405,7 +399,7 @@ Please check your network connection and try again.`;
/> />
</div> </div>
</div> </div>
<div v-if="shouldShowDiscussions" class="discussion-body"> <div v-if="!shouldHideDiscussionBody" class="discussion-body">
<component <component
:is="wrapperComponent" :is="wrapperComponent"
v-bind="wrapperComponentProps" v-bind="wrapperComponentProps"
...@@ -436,11 +430,11 @@ Please check your network connection and try again.`; ...@@ -436,11 +430,11 @@ Please check your network connection and try again.`;
</component> </component>
<toggle-replies-widget <toggle-replies-widget
v-if="hasReplies" v-if="hasReplies"
:collapsed="isRepliesCollapsed" :collapsed="!isExpanded"
:replies="replies" :replies="replies"
@toggle="toggleReplies" @toggle="toggleDiscussionHandler"
/> />
<template v-if="!isRepliesCollapsed"> <template v-if="isExpanded">
<component <component
:is="componentName(note)" :is="componentName(note)"
v-for="note in replies" v-for="note in replies"
...@@ -467,7 +461,7 @@ Please check your network connection and try again.`; ...@@ -467,7 +461,7 @@ Please check your network connection and try again.`;
</template> </template>
</ul> </ul>
<div <div
v-if="!isRepliesCollapsed || !hasReplies" v-if="isExpanded || !hasReplies"
:class="{ 'is-replying': isReplying }" :class="{ 'is-replying': isReplying }"
class="discussion-reply-holder" class="discussion-reply-holder"
> >
......
---
title: Expand resolved discussion when linking to a comment in the discussion
merge_request: 26483
author:
type: fixed
...@@ -5,9 +5,7 @@ describe 'Merge request > User scrolls to note on load', :js do ...@@ -5,9 +5,7 @@ describe 'Merge request > User scrolls to note on load', :js do
let(:user) { project.creator } let(:user) { project.creator }
let(:merge_request) { create(:merge_request, source_project: project, author: user) } let(:merge_request) { create(:merge_request, source_project: project, author: user) }
let(:note) { create(:diff_note_on_merge_request, noteable: merge_request, project: project) } let(:note) { create(:diff_note_on_merge_request, noteable: merge_request, project: project) }
let(:resolved_note) { create(:diff_note_on_merge_request, :resolved, noteable: merge_request, project: project) }
let(:fragment_id) { "#note_#{note.id}" } let(:fragment_id) { "#note_#{note.id}" }
let(:collapsed_fragment_id) { "#note_#{resolved_note.id}" }
before do before do
sign_in(user) sign_in(user)
...@@ -45,13 +43,35 @@ describe 'Merge request > User scrolls to note on load', :js do ...@@ -45,13 +43,35 @@ describe 'Merge request > User scrolls to note on load', :js do
end end
end end
# TODO: https://gitlab.com/gitlab-org/gitlab-ce/issues/48034 context 'resolved notes' do
xit 'expands collapsed notes' do let(:collapsed_fragment_id) { "#note_#{resolved_note.id}" }
context 'when diff note' do
let(:resolved_note) { create(:diff_note_on_merge_request, :resolved, noteable: merge_request, project: project) }
it 'expands collapsed notes' do
visit "#{project_merge_request_path(project, merge_request)}#{collapsed_fragment_id}" visit "#{project_merge_request_path(project, merge_request)}#{collapsed_fragment_id}"
note_element = find(collapsed_fragment_id) note_element = find(collapsed_fragment_id)
note_container = note_element.ancestor('.timeline-content') diff_container = note_element.ancestor('.diff-content')
expect(note_element.visible?).to eq true expect(note_element.visible?).to eq(true)
expect(note_container.find('.line_content.noteable_line.old', match: :first).visible?).to eq true expect(diff_container.visible?).to eq(true)
end
end
context 'when non-diff note' do
let(:non_diff_discussion) { create(:discussion_note_on_merge_request, :resolved, noteable: merge_request, project: project) }
let(:resolved_note) { create(:discussion_note_on_merge_request, :resolved, noteable: merge_request, project: project, in_reply_to: non_diff_discussion) }
it 'expands collapsed replies' do
visit "#{project_merge_request_path(project, merge_request)}#{collapsed_fragment_id}"
note_element = find(collapsed_fragment_id)
expect(note_element.visible?).to eq(true)
expect(note_element.sibling('.replies-toggle')[:class]).to include('expanded')
end
end
end end
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