diff options
Diffstat (limited to 'app/assets/javascripts/diffs/components/diff_row_utils.js')
-rw-r--r-- | app/assets/javascripts/diffs/components/diff_row_utils.js | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/app/assets/javascripts/diffs/components/diff_row_utils.js b/app/assets/javascripts/diffs/components/diff_row_utils.js index 08b87a4bade..d5491d3cd56 100644 --- a/app/assets/javascripts/diffs/components/diff_row_utils.js +++ b/app/assets/javascripts/diffs/components/diff_row_utils.js @@ -83,3 +83,76 @@ export const parallelViewLeftLineType = (line, hll) => { export const shouldShowCommentButton = (hover, context, meta, discussions) => { return hover && !context && !meta && !discussions; }; + +export const mapParallel = content => line => { + let { left, right } = line; + + // Dicussions/Comments + const hasExpandedDiscussionOnLeft = + left?.discussions?.length > 0 ? left?.discussionsExpanded : false; + const hasExpandedDiscussionOnRight = + right?.discussions?.length > 0 ? right?.discussionsExpanded : false; + + const renderCommentRow = + hasExpandedDiscussionOnLeft || hasExpandedDiscussionOnRight || left?.hasForm || right?.hasForm; + + if (left) { + left = { + ...left, + renderDiscussion: hasExpandedDiscussionOnLeft, + hasDraft: content.hasParallelDraftLeft(content.diffFile.file_hash, line), + lineDraft: content.draftForLine(content.diffFile.file_hash, line, 'left'), + hasCommentForm: left.hasForm, + }; + } + if (right) { + right = { + ...right, + renderDiscussion: Boolean(hasExpandedDiscussionOnRight && right.type), + hasDraft: content.hasParallelDraftRight(content.diffFile.file_hash, line), + lineDraft: content.draftForLine(content.diffFile.file_hash, line, 'right'), + hasCommentForm: Boolean(right.hasForm && right.type), + }; + } + + return { + ...line, + left, + right, + isMatchLineLeft: isMatchLine(left?.type), + isMatchLineRight: isMatchLine(right?.type), + isContextLineLeft: isContextLine(left?.type), + isContextLineRight: isContextLine(right?.type), + hasDiscussionsLeft: hasDiscussions(left), + hasDiscussionsRight: hasDiscussions(right), + lineHrefOld: lineHref(left), + lineHrefNew: lineHref(right), + lineCode: lineCode(line), + isMetaLineLeft: isMetaLine(left?.type), + isMetaLineRight: isMetaLine(right?.type), + draftRowClasses: left?.lineDraft > 0 || right?.lineDraft > 0 ? '' : 'js-temp-notes-holder', + renderCommentRow, + commentRowClasses: hasDiscussions(left) || hasDiscussions(right) ? '' : 'js-temp-notes-holder', + }; +}; + +// TODO: Delete this function when unifiedDiffComponents FF is removed +export const mapInline = content => line => { + // Discussions/Comments + const renderCommentRow = line.hasForm || (line.discussions?.length && line.discussionsExpanded); + + return { + ...line, + renderDiscussion: Boolean(line.discussions?.length), + isMatchLine: isMatchLine(line.type), + commentRowClasses: line.discussions?.length ? '' : 'js-temp-notes-holder', + renderCommentRow, + hasDraft: content.shouldRenderDraftRow(content.diffFile.file_hash, line), + hasCommentForm: line.hasForm, + isMetaLine: isMetaLine(line.type), + isContextLine: isContextLine(line.type), + hasDiscussions: hasDiscussions(line), + lineHref: lineHref(line), + lineCode: lineCode(line), + }; +}; |