Commit 81435235 authored by Nathan Friend's avatar Nathan Friend

Merge branch...

Merge branch '213855-existing-notes-on-merge-requests-aren-t-displayed-on-merge-head-version' into 'master'

Resolve "Existing notes on merge requests aren't displayed on merge (head) version"

See merge request gitlab-org/gitlab!30402
parents eb50f1b6 7f64a65b
...@@ -437,7 +437,11 @@ export function getDiffPositionByLineCode(diffFiles, useSingleDiffStyle) { ...@@ -437,7 +437,11 @@ export function getDiffPositionByLineCode(diffFiles, useSingleDiffStyle) {
// This method will check whether the discussion is still applicable // This method will check whether the discussion is still applicable
// to the diff line in question regarding different versions of the MR // to the diff line in question regarding different versions of the MR
export function isDiscussionApplicableToLine({ discussion, diffPosition, latestDiff }) { export function isDiscussionApplicableToLine({ discussion, diffPosition, latestDiff }) {
const { line_code, ...diffPositionCopy } = diffPosition; const { line_code, ...dp } = diffPosition;
// Removing `line_range` from diffPosition because the backend does not
// yet consistently return this property. This check can be removed,
// once this is addressed. see https://gitlab.com/gitlab-org/gitlab/-/issues/213010
const { line_range: dpNotUsed, ...diffPositionCopy } = dp;
if (discussion.original_position && discussion.position) { if (discussion.original_position && discussion.position) {
const discussionPositions = [ const discussionPositions = [
...@@ -446,7 +450,14 @@ export function isDiscussionApplicableToLine({ discussion, diffPosition, latestD ...@@ -446,7 +450,14 @@ export function isDiscussionApplicableToLine({ discussion, diffPosition, latestD
...(discussion.positions || []), ...(discussion.positions || []),
]; ];
return discussionPositions.some(position => isEqual(position, diffPositionCopy)); const removeLineRange = position => {
const { line_range: pNotUsed, ...positionNoLineRange } = position;
return positionNoLineRange;
};
return discussionPositions
.map(removeLineRange)
.some(position => isEqual(position, diffPositionCopy));
} }
// eslint-disable-next-line // eslint-disable-next-line
......
...@@ -503,11 +503,16 @@ describe('DiffsStoreUtils', () => { ...@@ -503,11 +503,16 @@ describe('DiffsStoreUtils', () => {
}, },
}; };
// When multi line comments are fully implemented `line_code` will be
// included in all requests. Until then we need to ensure the logic does
// not change when it is included only in the "comparison" argument.
const lineRange = { start_line_code: 'abc_1_1', end_line_code: 'abc_1_2' };
it('returns true when the discussion is up to date', () => { it('returns true when the discussion is up to date', () => {
expect( expect(
utils.isDiscussionApplicableToLine({ utils.isDiscussionApplicableToLine({
discussion: discussions.upToDateDiscussion1, discussion: discussions.upToDateDiscussion1,
diffPosition, diffPosition: { ...diffPosition, line_range: lineRange },
latestDiff: true, latestDiff: true,
}), }),
).toBe(true); ).toBe(true);
...@@ -517,7 +522,7 @@ describe('DiffsStoreUtils', () => { ...@@ -517,7 +522,7 @@ describe('DiffsStoreUtils', () => {
expect( expect(
utils.isDiscussionApplicableToLine({ utils.isDiscussionApplicableToLine({
discussion: discussions.outDatedDiscussion1, discussion: discussions.outDatedDiscussion1,
diffPosition, diffPosition: { ...diffPosition, line_range: lineRange },
latestDiff: true, latestDiff: true,
}), }),
).toBe(false); ).toBe(false);
...@@ -534,6 +539,7 @@ describe('DiffsStoreUtils', () => { ...@@ -534,6 +539,7 @@ describe('DiffsStoreUtils', () => {
diffPosition: { diffPosition: {
...diffPosition, ...diffPosition,
lineCode: 'ABC_1', lineCode: 'ABC_1',
line_range: lineRange,
}, },
latestDiff: true, latestDiff: true,
}), }),
...@@ -551,6 +557,7 @@ describe('DiffsStoreUtils', () => { ...@@ -551,6 +557,7 @@ describe('DiffsStoreUtils', () => {
diffPosition: { diffPosition: {
...diffPosition, ...diffPosition,
line_code: 'ABC_1', line_code: 'ABC_1',
line_range: lineRange,
}, },
latestDiff: true, latestDiff: true,
}), }),
...@@ -568,6 +575,7 @@ describe('DiffsStoreUtils', () => { ...@@ -568,6 +575,7 @@ describe('DiffsStoreUtils', () => {
diffPosition: { diffPosition: {
...diffPosition, ...diffPosition,
lineCode: 'ABC_1', lineCode: 'ABC_1',
line_range: lineRange,
}, },
latestDiff: false, latestDiff: false,
}), }),
......
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