Commit fe24c0a8 authored by Phil Hughes's avatar Phil Hughes

Fixes commit comments in side-by-side diff view

This was caused by the `notes` global class not existing when the
`file_comment_button` code is run. The notes class was used to check
if the diff is currently in parallel view or not. To get around this
I've added a check into the `file_comment_button` JS to check if the
view is currently parallel or not.

Closes #38117
parent aaf435d1
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
* causes reflows, visit https://gist.github.com/paulirish/5d52fb081b3570c81e3a * causes reflows, visit https://gist.github.com/paulirish/5d52fb081b3570c81e3a
*/ */
import Cookies from 'js-cookie';
const LINE_NUMBER_CLASS = 'diff-line-num'; const LINE_NUMBER_CLASS = 'diff-line-num';
const UNFOLDABLE_LINE_CLASS = 'js-unfold'; const UNFOLDABLE_LINE_CLASS = 'js-unfold';
const NO_COMMENT_CLASS = 'no-comment-btn'; const NO_COMMENT_CLASS = 'no-comment-btn';
...@@ -27,9 +29,7 @@ export default { ...@@ -27,9 +29,7 @@ export default {
this.userCanCreateNote = $diffFile.closest(DIFF_CONTAINER_SELECTOR).data('can-create-note') === ''; this.userCanCreateNote = $diffFile.closest(DIFF_CONTAINER_SELECTOR).data('can-create-note') === '';
} }
if (typeof notes !== 'undefined' && !this.isParallelView) { this.isParallelView = Cookies.get('diff_view') === 'parallel';
this.isParallelView = notes.isParallelView && notes.isParallelView();
}
if (this.userCanCreateNote) { if (this.userCanCreateNote) {
$diffFile.on('mouseover', LINE_COLUMN_CLASSES, e => this.showButton(this.isParallelView, e)) $diffFile.on('mouseover', LINE_COLUMN_CLASSES, e => this.showButton(this.isParallelView, e))
......
---
title: Fixed commenting on side-by-side commit diff
merge_request:
author:
type: fixed
require 'spec_helper'
feature 'Commit diff', :js do
include RepoHelpers
let(:user) { create(:user) }
let(:project) { create(:project, :public, :repository) }
before do
project.add_master(user)
sign_in user
end
%w(inline parallel).each do |view|
context "#{view} view" do
before do
visit project_commit_path(project, sample_commit.id, view: view)
end
it "adds comment to diff" do
diff_line_num = first('.diff-line-num.new')
diff_line_num.trigger('mouseover')
diff_line_num.find('.js-add-diff-note-button').trigger('click')
page.within(first('.diff-viewer')) do
find('.js-note-text').set 'test comment'
click_button 'Comment'
expect(page).to have_content('test comment')
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