Commit 64774bfa authored by Phil Hughes's avatar Phil Hughes

Fixes multi line comments options in parallel mode

Changes the line number options in parallel mode
to not include the wrong lines.
In parallel mode the dropdown should only include
the line numbers for whichever side the select
option was opened on.

Closes https://gitlab.com/gitlab-org/gitlab/-/issues/227159
parent 161ba793
...@@ -7,7 +7,7 @@ import noteForm from '../../notes/components/note_form.vue'; ...@@ -7,7 +7,7 @@ import noteForm from '../../notes/components/note_form.vue';
import MultilineCommentForm from '../../notes/components/multiline_comment_form.vue'; import MultilineCommentForm from '../../notes/components/multiline_comment_form.vue';
import autosave from '../../notes/mixins/autosave'; import autosave from '../../notes/mixins/autosave';
import userAvatarLink from '../../vue_shared/components/user_avatar/user_avatar_link.vue'; import userAvatarLink from '../../vue_shared/components/user_avatar/user_avatar_link.vue';
import { DIFF_NOTE_TYPE } from '../constants'; import { DIFF_NOTE_TYPE, PARALLEL_DIFF_VIEW_TYPE } from '../constants';
import { import {
commentLineOptions, commentLineOptions,
formatLineRange, formatLineRange,
...@@ -60,7 +60,7 @@ export default { ...@@ -60,7 +60,7 @@ export default {
diffViewType: state => state.diffs.diffViewType, diffViewType: state => state.diffs.diffViewType,
}), }),
...mapState('diffs', ['showSuggestPopover']), ...mapState('diffs', ['showSuggestPopover']),
...mapGetters('diffs', ['getDiffFileByHash']), ...mapGetters('diffs', ['getDiffFileByHash', 'diffLines']),
...mapGetters([ ...mapGetters([
'isLoggedIn', 'isLoggedIn',
'noteableType', 'noteableType',
...@@ -94,10 +94,18 @@ export default { ...@@ -94,10 +94,18 @@ export default {
if (right && right.type !== 'match') acc.push(right); if (right && right.type !== 'match') acc.push(right);
return acc; return acc;
}; };
const getDiffLines = () => {
if (this.diffViewType === PARALLEL_DIFF_VIEW_TYPE) {
return (this.glFeatures.unifiedDiffLines
? this.diffLines(this.diffFile)
: this.diffFile.parallel_diff_lines
).reduce(combineSides, []);
}
return this.diffFile.highlighted_diff_lines;
};
const side = this.line.type === 'new' ? 'right' : 'left'; const side = this.line.type === 'new' ? 'right' : 'left';
const lines = this.diffFile.highlighted_diff_lines.length const lines = getDiffLines();
? this.diffFile.highlighted_diff_lines
: this.diffFile.parallel_diff_lines.reduce(combineSides, []);
return commentLineOptions(lines, this.line, this.line.line_code, side); return commentLineOptions(lines, this.line, this.line.line_code, side);
}, },
}, },
......
---
title: Fixed multi line comment options in parallel mode
merge_request:
author:
type: fixed
...@@ -129,13 +129,6 @@ RSpec.describe 'User comments on a diff', :js do ...@@ -129,13 +129,6 @@ RSpec.describe 'User comments on a diff', :js do
visit(diffs_project_merge_request_path(project, merge_request, view: 'parallel')) visit(diffs_project_merge_request_path(project, merge_request, view: 'parallel'))
end end
# In `files/ruby/popen.rb`
it 'allows comments for changes involving both sides' do
# click +15, select -13 add and verify comment
click_diff_line(find('div[data-path="files/ruby/popen.rb"] .new_line a[data-linenumber="15"]').find(:xpath, '../..'), 'right')
add_comment('-13', '+15')
end
it 'allows comments to start above hidden lines and end below' do it 'allows comments to start above hidden lines and end below' do
# click +28, select 21 add and verify comment # click +28, select 21 add and verify comment
click_diff_line(find('div[data-path="files/ruby/popen.rb"] .new_line a[data-linenumber="28"]').find(:xpath, '../..'), 'right') click_diff_line(find('div[data-path="files/ruby/popen.rb"] .new_line a[data-linenumber="28"]').find(:xpath, '../..'), 'right')
...@@ -166,7 +159,7 @@ RSpec.describe 'User comments on a diff', :js do ...@@ -166,7 +159,7 @@ RSpec.describe 'User comments on a diff', :js do
all('.js-unfold-down')[1].click all('.js-unfold-down')[1].click
end end
click_diff_line(find('div[data-path="files/ruby/popen.rb"] .old_line a[data-linenumber="30"]').find(:xpath, '../..'), 'left') click_diff_line(find('div[data-path="files/ruby/popen.rb"] .old_line a[data-linenumber="30"]').find(:xpath, '../..'), 'left')
add_comment('+28', '37') add_comment('-9', '30')
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