Commit 638b4359 authored by Justin Boyson's avatar Justin Boyson Committed by Brandon Labuschagne

Fix unified components inline view

Added check for `inline` to parallelizeDiffLines util function.
This keeps the data in a more "inine" structure.
parent 4a03d54e
...@@ -170,5 +170,8 @@ export const diffLines = state => (file, unifiedDiffComponents) => { ...@@ -170,5 +170,8 @@ export const diffLines = state => (file, unifiedDiffComponents) => {
return null; return null;
} }
return parallelizeDiffLines(file.highlighted_diff_lines || []); return parallelizeDiffLines(
file.highlighted_diff_lines || [],
state.diffViewType === INLINE_DIFF_VIEW_TYPE,
);
}; };
...@@ -36,9 +36,12 @@ export const isMeta = line => ['match', 'new-nonewline', 'old-nonewline'].includ ...@@ -36,9 +36,12 @@ export const isMeta = line => ['match', 'new-nonewline', 'old-nonewline'].includ
* *
* @param {Object[]} diffLines - inline diff lines * @param {Object[]} diffLines - inline diff lines
* *
* @param {Boolean} inline - is inline context or not
*
* @returns {Object[]} parallel lines * @returns {Object[]} parallel lines
*/ */
export const parallelizeDiffLines = (diffLines = []) => {
export const parallelizeDiffLines = (diffLines, inline) => {
let freeRightIndex = null; let freeRightIndex = null;
const lines = []; const lines = [];
...@@ -57,7 +60,7 @@ export const parallelizeDiffLines = (diffLines = []) => { ...@@ -57,7 +60,7 @@ export const parallelizeDiffLines = (diffLines = []) => {
} }
index += 1; index += 1;
} else if (isAdded(line)) { } else if (isAdded(line)) {
if (freeRightIndex !== null) { if (freeRightIndex !== null && !inline) {
// If an old line came before this without a line on the right, this // If an old line came before this without a line on the right, this
// line can be put to the right of it. // line can be put to the right of it.
lines[freeRightIndex].right = line; lines[freeRightIndex].right = line;
......
...@@ -641,12 +641,12 @@ table.code { ...@@ -641,12 +641,12 @@ table.code {
} }
} }
.diff-grid-left .old:nth-child(2) [data-linenumber], .diff-grid-left .old:nth-child(1) [data-linenumber],
.diff-grid-right .new:nth-child(2) [data-linenumber] { .diff-grid-right .new:nth-child(2) [data-linenumber] {
display: inline; display: inline;
} }
.diff-grid-left .old:nth-child(3) [data-linenumber], .diff-grid-left .old:nth-child(2) [data-linenumber],
.diff-grid-right .new:nth-child(1) [data-linenumber] { .diff-grid-right .new:nth-child(1) [data-linenumber] {
display: none; display: none;
} }
......
---
title: Fix unified component inline display
merge_request: 47345
author:
type: fixed
...@@ -1221,5 +1221,26 @@ describe('DiffsStoreUtils', () => { ...@@ -1221,5 +1221,26 @@ describe('DiffsStoreUtils', () => {
file.parallel_diff_lines, file.parallel_diff_lines,
); );
}); });
/**
* What's going on here?
*
* The inline version of parallelizeDiffLines simply keeps the difflines
* in the same order they are received as opposed to shuffling them
* to be "side by side".
*
* This keeps the underlying data structure the same which simplifies
* the components, but keeps the changes grouped together as users
* expect when viewing changes inline.
*/
it('converts inline diff lines to inline diff lines with a parallel structure', () => {
const file = getDiffFileMock();
const files = utils.parallelizeDiffLines(file.highlighted_diff_lines, true);
expect(files[5].left).toEqual(file.parallel_diff_lines[5].left);
expect(files[5].right).toBeNull();
expect(files[6].left).toBeNull();
expect(files[6].right).toEqual(file.parallel_diff_lines[5].right);
});
}); });
}); });
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