Commit 027ad138 authored by Eric Eastwood's avatar Eric Eastwood
parent 319cab41
...@@ -288,7 +288,11 @@ import BlobForkSuggestion from './blob/blob_fork_suggestion'; ...@@ -288,7 +288,11 @@ import BlobForkSuggestion from './blob/blob_fork_suggestion';
if (anchor) { if (anchor) {
const notesContent = anchor.closest('.notes_content'); const notesContent = anchor.closest('.notes_content');
const lineType = notesContent.hasClass('new') ? 'new' : 'old'; const lineType = notesContent.hasClass('new') ? 'new' : 'old';
notes.addDiffNote(anchor, lineType, false); notes.toggleDiffNote({
target: anchor,
lineType,
forceShow: true,
});
anchor[0].scrollIntoView(); anchor[0].scrollIntoView();
// We have multiple elements on the page with `#note_xxx` // We have multiple elements on the page with `#note_xxx`
// (discussion and diff tabs) and `:target` only applies to the first // (discussion and diff tabs) and `:target` only applies to the first
......
...@@ -876,10 +876,19 @@ const normalizeNewlines = function(str) { ...@@ -876,10 +876,19 @@ const normalizeNewlines = function(str) {
e.preventDefault(); e.preventDefault();
const $link = $(e.currentTarget || e.target); const $link = $(e.currentTarget || e.target);
const showReplyInput = !$link.hasClass('js-diff-comment-avatar'); const showReplyInput = !$link.hasClass('js-diff-comment-avatar');
this.addDiffNote($link, $link.data('lineType'), showReplyInput); this.toggleDiffNote({
target: $link,
lineType: $link.data('lineType'),
showReplyInput
});
}; };
Notes.prototype.addDiffNote = function(target, lineType, showReplyInput) { Notes.prototype.toggleDiffNote = function({
target,
lineType,
forceShow,
showReplyInput = false,
}) {
var $link, addForm, hasNotes, newForm, noteForm, replyButton, row, rowCssToAdd, targetContent, isDiffCommentAvatar; var $link, addForm, hasNotes, newForm, noteForm, replyButton, row, rowCssToAdd, targetContent, isDiffCommentAvatar;
$link = $(target); $link = $(target);
row = $link.closest("tr"); row = $link.closest("tr");
...@@ -924,12 +933,12 @@ const normalizeNewlines = function(str) { ...@@ -924,12 +933,12 @@ const normalizeNewlines = function(str) {
notesContent = targetRow.find(notesContentSelector); notesContent = targetRow.find(notesContentSelector);
addForm = true; addForm = true;
} else { } else {
targetRow.show(); const isCurrentlyShown = targetRow.find('.content:not(:empty)').is(':visible');
notesContent.toggle(!notesContent.is(':visible')); const isForced = forceShow === true || forceShow === false;
const showNow = forceShow === true || (!isCurrentlyShown && !isForced);
if (!targetRow.find('.content:not(:empty)').is(':visible')) { targetRow.toggle(showNow);
targetRow.hide(); notesContent.toggle(showNow);
}
} }
if (addForm) { if (addForm) {
......
...@@ -20,6 +20,34 @@ feature 'Diffs URL', js: true, feature: true do ...@@ -20,6 +20,34 @@ feature 'Diffs URL', js: true, feature: true do
end end
end end
context 'when linking to note' do
describe 'with unresolved note' do
let(:note) { create :diff_note_on_merge_request, project: project, noteable: merge_request }
let(:fragment) { "#note_#{note.id}" }
before do
visit "#{diffs_namespace_project_merge_request_path(project.namespace, project, merge_request)}#{fragment}"
end
it 'shows expanded note' do
expect(page).to have_selector(fragment, visible: true)
end
end
describe 'with resolved note' do
let(:note) { create :diff_note_on_merge_request, :resolved, project: project, noteable: merge_request }
let(:fragment) { "#note_#{note.id}" }
before do
visit "#{diffs_namespace_project_merge_request_path(project.namespace, project, merge_request)}#{fragment}"
end
it 'shows expanded note' do
expect(page).to have_selector(fragment, visible: true)
end
end
end
context 'when merge request has overflow' do context 'when merge request has overflow' do
it 'displays warning' do it 'displays warning' do
allow(Commit).to receive(:max_diff_options).and_return(max_files: 3) allow(Commit).to receive(:max_diff_options).and_return(max_files: 3)
......
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