Skip to content
Snippets Groups Projects
Unverified Commit 234563ba authored by Phil Hughes's avatar Phil Hughes
Browse files

Made diff & note data consistent

This caused many pain points when working with it.
Part of the data was camel cased the other snake case.
Other parts where snake case & then getting converted in components,
this conversion has the potential for leaking memory.

This changes that & makes it consistent with what it returned from the
API, snake case.
parent 63b4b4b2
No related branches found
No related tags found
No related merge requests found
Showing
with 209 additions and 225 deletions
Loading
Loading
@@ -94,7 +94,7 @@ export default {
return __('Show latest version');
},
canCurrentUserFork() {
return this.currentUser.canFork === true && this.currentUser.canCreateMergeRequest;
return this.currentUser.can_fork === true && this.currentUser.can_create_merge_request;
},
showCompareVersions() {
return this.mergeRequestDiffs && this.mergeRequestDiff;
Loading
Loading
Loading
Loading
@@ -40,15 +40,17 @@ export default {
},
computed: {
authorName() {
return (this.commit.author && this.commit.author.name) || this.commit.authorName;
return (this.commit.author && this.commit.author.name) || this.commit.author_name;
},
authorUrl() {
return (
(this.commit.author && this.commit.author.webUrl) || `mailto:${this.commit.authorEmail}`
(this.commit.author && this.commit.author.web_url) || `mailto:${this.commit.author_email}`
);
},
authorAvatar() {
return (this.commit.author && this.commit.author.avatarUrl) || this.commit.authorGravatarUrl;
return (
(this.commit.author && this.commit.author.avatar_url) || this.commit.author_gravatar_url
);
},
},
};
Loading
Loading
@@ -66,18 +68,18 @@ export default {
<div class="commit-detail flex-list">
<div class="commit-content qa-commit-content">
<a
:href="commit.commitUrl"
:href="commit.commit_url"
class="commit-row-message item-title"
v-html="commit.titleHtml"
v-html="commit.title_html"
></a>
 
<span class="commit-row-message d-block d-sm-none">
&middot;
{{ commit.shortId }}
{{ commit.short_id }}
</span>
 
<button
v-if="commit.descriptionHtml"
v-if="commit.description_html"
class="text-expander js-toggle-button"
type="button"
:aria-label="__('Toggle commit description')"
Loading
Loading
@@ -95,29 +97,29 @@ export default {
></a>
{{ s__('CommitWidget|authored') }}
<time-ago-tooltip
:time="commit.authoredDate"
:time="commit.authored_date"
/>
</div>
 
<pre
v-if="commit.descriptionHtml"
v-if="commit.description_html"
class="commit-row-description js-toggle-content append-bottom-8"
v-html="commit.descriptionHtml"
v-html="commit.description_html"
></pre>
</div>
<div class="commit-actions flex-row d-none d-sm-flex">
<div
v-if="commit.signatureHtml"
v-html="commit.signatureHtml"
v-if="commit.signature_html"
v-html="commit.signature_html"
></div>
<commit-pipeline-status
v-if="commit.pipelineStatusPath"
:endpoint="commit.pipelineStatusPath"
v-if="commit.pipeline_status_path"
:endpoint="commit.pipeline_status_path"
/>
<div class="commit-sha-group">
<div
class="label label-monospace"
v-text="commit.shortId"
v-text="commit.short_id"
></div>
<clipboard-button
:text="commit.id"
Loading
Loading
Loading
Loading
@@ -56,16 +56,16 @@ export default {
methods: {
commitsText(version) {
return n__(
`${version.commitsCount} commit,`,
`${version.commitsCount} commits,`,
version.commitsCount,
`${version.commits_count} commit,`,
`${version.commits_count} commits,`,
version.commits_count,
);
},
href(version) {
if (this.showCommitCount) {
return version.versionPath;
return version.version_path;
}
return version.comparePath;
return version.compare_path;
},
versionName(version) {
if (this.isLatest(version)) {
Loading
Loading
@@ -74,7 +74,7 @@ export default {
if (this.targetBranch && (this.isBase(version) || !version)) {
return this.targetBranch.branchName;
}
return `version ${version.versionIndex}`;
return `version ${version.version_index}`;
},
isActive(version) {
if (!version) {
Loading
Loading
@@ -84,11 +84,11 @@ export default {
if (this.targetBranch) {
return (
(this.isBase(version) && !this.startVersion) ||
(this.startVersion && this.startVersion.versionIndex === version.versionIndex)
(this.startVersion && this.startVersion.version_index === version.version_index)
);
}
 
return version.versionIndex === this.mergeRequestVersion.versionIndex;
return version.version_index === this.mergeRequestVersion.version_index;
},
isBase(version) {
if (!version || !this.targetBranch) {
Loading
Loading
@@ -98,7 +98,7 @@ export default {
},
isLatest(version) {
return (
this.mergeRequestVersion && version.versionIndex === this.targetVersions[0].versionIndex
this.mergeRequestVersion && version.version_index === this.targetVersions[0].version_index
);
},
},
Loading
Loading
@@ -142,7 +142,7 @@ export default {
</div>
<div>
<small class="commit-sha">
{{ version.truncatedCommitSha }}
{{ version.truncated_commit_sha }}
</small>
</div>
<div>
Loading
Loading
@@ -151,8 +151,8 @@ export default {
{{ commitsText(version) }}
</template>
<time-ago
v-if="version.createdAt"
:time="version.createdAt"
v-if="version.created_at"
:time="version.created_at"
class="js-timeago js-timeago-render"
/>
</small>
Loading
Loading
Loading
Loading
@@ -39,7 +39,7 @@ export default {
return this.diffFile.viewer.name === 'text';
},
diffFileCommentForm() {
return this.getCommentFormForDiffFile(this.diffFile.fileHash);
return this.getCommentFormForDiffFile(this.diffFile.file_hash);
},
showNotesContainer() {
return this.diffFile.discussions.length || this.diffFileCommentForm;
Loading
Loading
@@ -73,28 +73,28 @@ export default {
<inline-diff-view
v-if="isInlineView"
:diff-file="diffFile"
:diff-lines="diffFile.highlightedDiffLines || []"
:diff-lines="diffFile.highlighted_diff_lines || []"
/>
<parallel-diff-view
v-if="isParallelView"
:diff-file="diffFile"
:diff-lines="diffFile.parallelDiffLines || []"
:diff-lines="diffFile.parallel_diff_lines || []"
/>
</template>
<diff-viewer
v-else
:diff-mode="diffMode"
:new-path="diffFile.newPath"
:new-sha="diffFile.diffRefs.headSha"
:old-path="diffFile.oldPath"
:old-sha="diffFile.diffRefs.baseSha"
:file-hash="diffFile.fileHash"
:new-path="diffFile.new_path"
:new-sha="diffFile.diff_refs.head_sha"
:old-path="diffFile.old_path"
:old-sha="diffFile.diff_refs.base_sha"
:file-hash="diffFile.file_hash"
:project-path="projectPath"
>
<image-diff-overlay
slot="image-overlay"
:discussions="diffFile.discussions"
:file-hash="diffFile.fileHash"
:file-hash="diffFile.file_hash"
:can-comment="getNoteableData.current_user.can_create_note"
/>
<div
Loading
Loading
@@ -115,7 +115,7 @@ export default {
:save-button-title="__('Comment')"
class="diff-comment-form new-note discussion-form discussion-form-container"
@handleFormUpdate="handleSaveNote"
@cancelForm="closeDiffFileCommentForm(diffFile.fileHash)"
@cancelForm="closeDiffFileCommentForm(diffFile.file_hash)"
/>
</div>
</diff-viewer>
Loading
Loading
Loading
Loading
@@ -40,7 +40,7 @@ export default {
return sprintf(
__('You can %{linkStart}view the blob%{linkEnd} instead.'),
{
linkStart: `<a href="${_.escape(this.file.viewPath)}">`,
linkStart: `<a href="${_.escape(this.file.view_path)}">`,
linkEnd: '</a>',
},
false,
Loading
Loading
@@ -49,9 +49,9 @@ export default {
showExpandMessage() {
return (
this.isCollapsed ||
(!this.file.highlightedDiffLines &&
(!this.file.highlighted_diff_lines &&
!this.isLoadingCollapsedDiff &&
!this.file.tooLarge &&
!this.file.too_large &&
this.file.text)
);
},
Loading
Loading
@@ -59,9 +59,11 @@ export default {
return this.isLoadingCollapsedDiff || (!this.file.renderIt && !this.isCollapsed);
},
hasDiffLines() {
const { highlightedDiffLines, parallelDiffLines } = this.file;
return highlightedDiffLines && parallelDiffLines && parallelDiffLines.length > 0;
return (
this.file.highlighted_diff_lines &&
this.file.parallel_diff_lines &&
this.file.parallel_diff_lines.length > 0
);
},
},
watch: {
Loading
Loading
@@ -115,9 +117,9 @@ export default {
 
<template>
<div
:id="file.fileHash"
:id="file.file_hash"
:class="{
'is-active': currentDiffFileId === file.fileHash
'is-active': currentDiffFileId === file.file_hash
}"
class="diff-file file-holder"
>
Loading
Loading
@@ -141,7 +143,7 @@ export default {
make your changes there, and submit a merge request.
</span>
<a
:href="file.forkPath"
:href="file.fork_path"
class="js-fork-suggestion-button btn btn-grouped btn-inverted btn-success"
>
Fork
Loading
Loading
@@ -157,7 +159,7 @@ export default {
 
<diff-content
v-if="!isCollapsed && file.renderIt"
:class="{ hidden: isCollapsed || file.tooLarge }"
:class="{ hidden: isCollapsed || file.too_large }"
:diff-file="file"
/>
<gl-loading-icon
Loading
Loading
@@ -178,7 +180,7 @@ export default {
</a>
</div>
<div
v-if="file.tooLarge"
v-if="file.too_large"
class="nothing-here-block diff-collapsed js-too-large-diff"
>
{{ __('This source diff could not be displayed because it is too large.') }}
Loading
Loading
Loading
Loading
@@ -68,32 +68,32 @@ export default {
},
titleLink() {
if (this.diffFile.submodule) {
return this.diffFile.submoduleTreeUrl || this.diffFile.submoduleLink;
return this.diffFile.submodule_tree_url || this.diffFile.submodule_link;
}
return this.discussionPath;
},
filePath() {
if (this.diffFile.submodule) {
return `${this.diffFile.filePath} @ ${truncateSha(this.diffFile.blob.id)}`;
return `${this.diffFile.file_path} @ ${truncateSha(this.diffFile.blob.id)}`;
}
 
if (this.diffFile.deletedFile) {
return sprintf(__('%{filePath} deleted'), { filePath: this.diffFile.filePath }, false);
if (this.diffFile.deleted_file) {
return sprintf(__('%{filePath} deleted'), { filePath: this.diffFile.file_path }, false);
}
 
return this.diffFile.filePath;
return this.diffFile.file_path;
},
titleTag() {
return this.diffFile.fileHash ? 'a' : 'span';
return this.diffFile.file_hash ? 'a' : 'span';
},
isUsingLfs() {
return this.diffFile.storedExternally && this.diffFile.externalStorage === 'lfs';
return this.diffFile.stored_externally && this.diffFile.external_storage === 'lfs';
},
collapseIcon() {
return this.expanded ? 'chevron-down' : 'chevron-right';
},
viewFileButtonText() {
const truncatedContentSha = _.escape(truncateSha(this.diffFile.contentSha));
const truncatedContentSha = _.escape(truncateSha(this.diffFile.content_sha));
return sprintf(
s__('MergeRequests|View file @ %{commitId}'),
{
Loading
Loading
@@ -103,7 +103,7 @@ export default {
);
},
viewReplacedFileButtonText() {
const truncatedBaseSha = _.escape(truncateSha(this.diffFile.diffRefs.baseSha));
const truncatedBaseSha = _.escape(truncateSha(this.diffFile.diff_refs.base_sha));
return sprintf(
s__('MergeRequests|View replaced file @ %{commitId}'),
{
Loading
Loading
@@ -113,7 +113,7 @@ export default {
);
},
gfmCopyText() {
return `\`${this.diffFile.filePath}\``;
return `\`${this.diffFile.file_path}\``;
},
},
methods: {
Loading
Loading
@@ -164,21 +164,21 @@ export default {
aria-hidden="true"
css-classes="js-file-icon append-right-5"
/>
<span v-if="diffFile.renamedFile">
<span v-if="diffFile.renamed_file">
<strong
v-tooltip
:title="diffFile.oldPath"
:title="diffFile.old_path"
class="file-title-name"
data-container="body"
v-html="diffFile.oldPathHtml"
v-html="diffFile.old_path_html"
></strong>
<strong
v-tooltip
:title="diffFile.newPath"
:title="diffFile.new_path"
class="file-title-name"
data-container="body"
v-html="diffFile.newPathHtml"
v-html="diffFile.new_path_html"
></strong>
</span>
 
Loading
Loading
@@ -195,16 +195,16 @@ export default {
 
<clipboard-button
:title="__('Copy file path to clipboard')"
:text="diffFile.filePath"
:text="diffFile.file_path"
:gfm="gfmCopyText"
css-class="btn-default btn-transparent btn-clipboard"
/>
 
<small
v-if="diffFile.modeChanged"
v-if="diffFile.mode_changed"
ref="fileMode"
>
{{ diffFile.aMode }} → {{ diffFile.bMode }}
{{ diffFile.a_mode }} → {{ diffFile.b_mode }}
</small>
 
<span
Loading
Loading
@@ -220,7 +220,7 @@ export default {
class="file-actions d-none d-sm-block"
>
<template
v-if="diffFile.blob && diffFile.blob.readableText"
v-if="diffFile.blob && diffFile.blob.readable_text"
>
<button
:disabled="!diffHasDiscussions(diffFile)"
Loading
Loading
@@ -234,33 +234,33 @@ export default {
</button>
 
<edit-button
v-if="!diffFile.deletedFile"
v-if="!diffFile.deleted_file"
:can-current-user-fork="canCurrentUserFork"
:edit-path="diffFile.editPath"
:can-modify-blob="diffFile.canModifyBlob"
:edit-path="diffFile.edit_path"
:can-modify-blob="diffFile.can_modify_blob"
@showForkMessage="showForkMessage"
/>
</template>
 
<a
v-if="diffFile.replacedViewPath"
:href="diffFile.replacedViewPath"
v-if="diffFile.replaced_view_path"
:href="diffFile.replaced_view_path"
class="btn view-file js-view-file"
v-html="viewReplacedFileButtonText"
>
</a>
<a
:href="diffFile.viewPath"
:href="diffFile.view_path"
class="btn view-file js-view-file"
v-html="viewFileButtonText"
>
</a>
 
<a
v-if="diffFile.externalUrl"
v-if="diffFile.external_url"
v-tooltip
:href="diffFile.externalUrl"
:title="`View on ${diffFile.formattedExternalUrl}`"
:href="diffFile.external_url"
:title="`View on ${diffFile.formatted_external_url}`"
target="_blank"
rel="noopener noreferrer"
class="btn btn-file-option"
Loading
Loading
Loading
Loading
@@ -73,7 +73,7 @@ export default {
}),
...mapGetters(['isLoggedIn']),
lineHref() {
return `#${this.line.lineCode || ''}`;
return `#${this.line.line_code || ''}`;
},
shouldShowCommentButton() {
return (
Loading
Loading
@@ -99,7 +99,7 @@ export default {
methods: {
...mapActions('diffs', ['loadMoreLines', 'showCommentForm']),
handleCommentButton() {
this.showCommentForm({ lineCode: this.line.lineCode });
this.showCommentForm({ lineCode: this.line.line_code });
},
handleLoadMoreLines() {
if (this.isRequesting) {
Loading
Loading
@@ -108,8 +108,8 @@ export default {
 
this.isRequesting = true;
const endpoint = this.contextLinesPath;
const oldLineNumber = this.line.metaData.oldPos || 0;
const newLineNumber = this.line.metaData.newPos || 0;
const oldLineNumber = this.line.meta_data.old_pos || 0;
const newLineNumber = this.line.meta_data.new_pos || 0;
const offset = newLineNumber - oldLineNumber;
const bottom = this.isBottom;
const { fileHash } = this;
Loading
Loading
@@ -125,12 +125,12 @@ export default {
to = lineNumber + UNFOLD_COUNT;
} else {
const diffFile = utils.findDiffFile(this.diffFiles, this.fileHash);
const indexForInline = utils.findIndexInInlineLines(diffFile.highlightedDiffLines, {
const indexForInline = utils.findIndexInInlineLines(diffFile.highlighted_diff_lines, {
oldLineNumber,
newLineNumber,
});
const prevLine = diffFile.highlightedDiffLines[indexForInline - 2];
const prevLineNumber = (prevLine && prevLine.newLine) || 0;
const prevLine = diffFile.highlighted_diff_lines[indexForInline - 2];
const prevLineNumber = (prevLine && prevLine.new_line) || 0;
 
if (since <= prevLineNumber + 1) {
since = prevLineNumber + 1;
Loading
Loading
Loading
Loading
@@ -53,7 +53,7 @@ export default {
this.noteableData.diff_head_sha,
DIFF_NOTE_TYPE,
this.noteableData.source_project_id,
this.line.lineCode,
this.line.line_code,
];
 
this.initAutoSave(this.noteableData, keys);
Loading
Loading
@@ -72,7 +72,7 @@ export default {
}
 
this.cancelCommentForm({
lineCode: this.line.lineCode,
lineCode: this.line.line_code,
});
this.$nextTick(() => {
this.resetAutoSave();
Loading
Loading
@@ -94,7 +94,7 @@ export default {
<note-form
ref="noteForm"
:is-editing="true"
:line-code="line.lineCode"
:line-code="line.line_code"
save-button-title="Comment"
class="diff-comment-form"
@cancelForm="handleCancelCommentForm"
Loading
Loading
Loading
Loading
@@ -96,9 +96,7 @@ export default {
};
},
lineNumber() {
const { lineType } = this;
return lineType === OLD_LINE_TYPE ? this.line.oldLine : this.line.newLine;
return this.lineType === OLD_LINE_TYPE ? this.line.old_line : this.line.new_line;
},
},
};
Loading
Loading
Loading
Loading
@@ -48,7 +48,7 @@ export default {
:discussions="line.discussions"
/>
<diff-line-note-form
v-if="diffLineCommentForms[line.lineCode]"
v-if="diffLineCommentForms[line.line_code]"
:diff-file-hash="diffFileHash"
:line="line"
:note-target-line="line"
Loading
Loading
Loading
Loading
@@ -52,9 +52,7 @@ export default {
};
},
inlineRowId() {
const { lineCode, oldLine, newLine } = this.line;
return lineCode || `${this.fileHash}_${oldLine}_${newLine}`;
return this.line.line_code || `${this.fileHash}_${this.line.old_line}_${this.line.new_line}`;
},
},
created() {
Loading
Loading
@@ -107,7 +105,7 @@ export default {
<td
:class="line.type"
class="line_content"
v-html="line.richText"
v-html="line.rich_text"
>
</td>
</tr>
Loading
Loading
Loading
Loading
@@ -43,16 +43,16 @@ export default {
v-for="(line, index) in diffLines"
>
<inline-diff-table-row
:key="line.lineCode"
:file-hash="diffFile.fileHash"
:context-lines-path="diffFile.contextLinesPath"
:key="line.line_code"
:file-hash="diffFile.file_hash"
:context-lines-path="diffFile.context_lines_path"
:line="line"
:is-bottom="index + 1 === diffLinesLength"
/>
<inline-diff-comment-row
v-if="shouldRenderInlineCommentRow(line)"
:key="index"
:diff-file-hash="diffFile.fileHash"
:diff-file-hash="diffFile.file_hash"
:line="line"
:line-index="index"
/>
Loading
Loading
Loading
Loading
@@ -27,10 +27,10 @@ export default {
diffLineCommentForms: state => state.diffs.diffLineCommentForms,
}),
leftLineCode() {
return this.line.left && this.line.left.lineCode;
return this.line.left && this.line.left.line_code;
},
rightLineCode() {
return this.line.right && this.line.right.lineCode;
return this.line.right && this.line.right.line_code;
},
hasExpandedDiscussionOnLeft() {
return this.line.left && this.line.left.discussions
Loading
Loading
Loading
Loading
@@ -120,11 +120,11 @@ export default {
class="diff-line-num old_line"
/>
<td
:id="line.left.lineCode"
:id="line.left.line_code"
:class="parallelViewLeftLineType"
class="line_content parallel left-side"
@mousedown.native="handleParallelLineMouseDown"
v-html="line.left.richText"
v-html="line.left.rich_text"
>
</td>
</template>
Loading
Loading
@@ -146,11 +146,11 @@ export default {
class="diff-line-num new_line"
/>
<td
:id="line.right.lineCode"
:id="line.right.line_code"
:class="line.right.type"
class="line_content parallel right-side"
@mousedown.native="handleParallelLineMouseDown"
v-html="line.right.richText"
v-html="line.right.rich_text"
>
</td>
</template>
Loading
Loading
Loading
Loading
@@ -46,8 +46,8 @@ export default {
>
<parallel-diff-table-row
:key="index"
:file-hash="diffFile.fileHash"
:context-lines-path="diffFile.contextLinesPath"
:file-hash="diffFile.file_hash"
:context-lines-path="diffFile.context_lines_path"
:line="line"
:is-bottom="index + 1 === diffLinesLength"
/>
Loading
Loading
@@ -55,7 +55,7 @@ export default {
v-if="shouldRenderParallelCommentRow(line)"
:key="`dcr-${index}`"
:line="line"
:diff-file-hash="diffFile.fileHash"
:diff-file-hash="diffFile.file_hash"
:line-index="index"
/>
</template>
Loading
Loading
import Vue from 'vue';
import { mapState } from 'vuex';
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
import diffsApp from './components/app.vue';
 
export default function initDiffsApp(store) {
Loading
Loading
@@ -17,9 +16,7 @@ export default function initDiffsApp(store) {
return {
endpoint: dataset.endpoint,
projectPath: dataset.projectPath,
currentUser: convertObjectPropsToCamelCase(JSON.parse(dataset.currentUserData), {
deep: true,
}),
currentUser: JSON.parse(dataset.currentUserData) || {},
};
},
computed: {
Loading
Loading
Loading
Loading
@@ -50,8 +50,8 @@ export const assignDiscussionsToDiff = (
};
 
export const removeDiscussionsFromDiff = ({ commit }, removeDiscussion) => {
const { fileHash, line_code, id } = removeDiscussion;
commit(types.REMOVE_LINE_DISCUSSIONS_FOR_FILE, { fileHash, lineCode: line_code, id });
const { file_hash, line_code, id } = removeDiscussion;
commit(types.REMOVE_LINE_DISCUSSIONS_FOR_FILE, { fileHash: file_hash, lineCode: line_code, id });
};
 
export const startRenderDiffsQueue = ({ state, commit }) => {
Loading
Loading
@@ -189,7 +189,7 @@ export const saveDiffDiscussion = ({ dispatch }, { note, formData }) => {
return dispatch('saveNote', postData, { root: true })
.then(result => dispatch('updateDiscussion', result.discussion, { root: true }))
.then(discussion => dispatch('assignDiscussionsToDiff', [discussion]))
.then(() => dispatch('closeDiffFileCommentForm', formData.diffFile.fileHash))
.then(() => dispatch('closeDiffFileCommentForm', formData.diffFile.file_hash))
.then(() => dispatch('startTaskList', null, { root: true }))
.catch(() => createFlash(s__('MergeRequests|Saving the comment failed')));
};
Loading
Loading
import _ from 'underscore';
import { PARALLEL_DIFF_VIEW_TYPE, INLINE_DIFF_VIEW_TYPE } from '../constants';
 
export const isParallelView = state => state.diffViewType === PARALLEL_DIFF_VIEW_TYPE;
Loading
Loading
@@ -68,8 +67,7 @@ export const diffHasDiscussions = (state, getters) => diff =>
*/
export const getDiffFileDiscussions = (state, getters, rootState, rootGetters) => diff =>
rootGetters.discussions.filter(
discussion =>
discussion.diff_discussion && _.isEqual(discussion.diff_file.file_hash, diff.fileHash),
discussion => discussion.diff_discussion && discussion.diff_file.file_hash === diff.file_hash,
) || [];
 
export const shouldRenderParallelCommentRow = state => line => {
Loading
Loading
@@ -90,14 +88,14 @@ export const shouldRenderParallelCommentRow = state => line => {
return true;
}
 
const hasCommentFormOnLeft = line.left && state.diffLineCommentForms[line.left.lineCode];
const hasCommentFormOnRight = line.right && state.diffLineCommentForms[line.right.lineCode];
const hasCommentFormOnLeft = line.left && state.diffLineCommentForms[line.left.line_code];
const hasCommentFormOnRight = line.right && state.diffLineCommentForms[line.right.line_code];
 
return hasCommentFormOnLeft || hasCommentFormOnRight;
};
 
export const shouldRenderInlineCommentRow = state => line => {
if (state.diffLineCommentForms[line.lineCode]) return true;
if (state.diffLineCommentForms[line.line_code]) return true;
 
if (!line.discussions || line.discussions.length === 0) {
return false;
Loading
Loading
@@ -108,7 +106,7 @@ export const shouldRenderInlineCommentRow = state => line => {
 
// prevent babel-plugin-rewire from generating an invalid default during karma∂ tests
export const getDiffFileByHash = state => fileHash =>
state.diffFiles.find(file => file.fileHash === fileHash);
state.diffFiles.find(file => file.file_hash === fileHash);
 
export const allBlobs = state => Object.values(state.treeEntries).filter(f => f.type === 'blob');
 
Loading
Loading
Loading
Loading
@@ -23,12 +23,11 @@ export default {
},
 
[types.SET_DIFF_DATA](state, data) {
const diffData = convertObjectPropsToCamelCase(data, { deep: true });
prepareDiffData(diffData);
const { tree, treeEntries } = generateTreeList(diffData.diffFiles);
prepareDiffData(data);
const { tree, treeEntries } = generateTreeList(data.diff_files);
 
Object.assign(state, {
...diffData,
...convertObjectPropsToCamelCase(data),
tree: sortTree(tree),
treeEntries,
});
Loading
Loading
@@ -42,7 +41,7 @@ export default {
 
[types.SET_MERGE_REQUEST_DIFFS](state, mergeRequestDiffs) {
Object.assign(state, {
mergeRequestDiffs: convertObjectPropsToCamelCase(mergeRequestDiffs, { deep: true }),
mergeRequestDiffs,
});
},
 
Loading
Loading
@@ -62,19 +61,18 @@ export default {
const { lineNumbers, contextLines, fileHash } = options;
const { bottom } = options.params;
const diffFile = findDiffFile(state.diffFiles, fileHash);
const { highlightedDiffLines, parallelDiffLines } = diffFile;
 
removeMatchLine(diffFile, lineNumbers, bottom);
 
const lines = addLineReferences(contextLines, lineNumbers, bottom).map(line => ({
...line,
lineCode: line.lineCode || `${fileHash}_${line.oldLine}_${line.newLine}`,
line_code: line.line_code || `${fileHash}_${line.old_line}_${line.new_line}`,
discussions: line.discussions || [],
}));
 
addContextLines({
inlineLines: highlightedDiffLines,
parallelLines: parallelDiffLines,
inlineLines: diffFile.highlighted_diff_lines,
parallelLines: diffFile.parallel_diff_lines,
contextLines: lines,
bottom,
lineNumbers,
Loading
Loading
@@ -82,10 +80,9 @@ export default {
},
 
[types.ADD_COLLAPSED_DIFFS](state, { file, data }) {
const normalizedData = convertObjectPropsToCamelCase(data, { deep: true });
prepareDiffData(normalizedData);
const [newFileData] = normalizedData.diffFiles.filter(f => f.fileHash === file.fileHash);
const selectedFile = state.diffFiles.find(f => f.fileHash === file.fileHash);
prepareDiffData(data);
const [newFileData] = data.diff_files.filter(f => f.file_hash === file.file_hash);
const selectedFile = state.diffFiles.find(f => f.file_hash === file.file_hash);
Object.assign(selectedFile, { ...newFileData });
},
 
Loading
Loading
@@ -101,20 +98,20 @@ export default {
 
const discussionLineCode = discussion.line_code;
const fileHash = discussion.diff_file.file_hash;
const lineCheck = ({ lineCode }) =>
lineCode === discussionLineCode &&
const lineCheck = line =>
line.line_code === discussionLineCode &&
isDiscussionApplicableToLine({
discussion,
diffPosition: diffPositionByLineCode[lineCode],
diffPosition: diffPositionByLineCode[line.line_code],
latestDiff,
});
 
state.diffFiles = state.diffFiles.map(diffFile => {
if (diffFile.fileHash === fileHash) {
if (diffFile.file_hash === fileHash) {
const file = { ...diffFile };
 
if (file.highlightedDiffLines) {
file.highlightedDiffLines = file.highlightedDiffLines.map(line => {
if (file.highlighted_diff_lines) {
file.highlighted_diff_lines = file.highlighted_diff_lines.map(line => {
if (lineCheck(line)) {
return {
...line,
Loading
Loading
@@ -126,8 +123,8 @@ export default {
});
}
 
if (file.parallelDiffLines) {
file.parallelDiffLines = file.parallelDiffLines.map(line => {
if (file.parallel_diff_lines) {
file.parallel_diff_lines = file.parallel_diff_lines.map(line => {
const left = line.left && lineCheck(line.left);
const right = line.right && lineCheck(line.right);
 
Loading
Loading
@@ -148,7 +145,7 @@ export default {
});
}
 
if (!file.parallelDiffLines || !file.highlightedDiffLines) {
if (!file.parallel_diff_lines || !file.highlighted_diff_lines) {
file.discussions = file.discussions.concat(discussion);
}
 
Loading
Loading
@@ -160,16 +157,16 @@ export default {
},
 
[types.REMOVE_LINE_DISCUSSIONS_FOR_FILE](state, { fileHash, lineCode, id }) {
const selectedFile = state.diffFiles.find(f => f.fileHash === fileHash);
const selectedFile = state.diffFiles.find(f => f.file_hash === fileHash);
if (selectedFile) {
if (selectedFile.parallelDiffLines) {
const targetLine = selectedFile.parallelDiffLines.find(
if (selectedFile.parallel_diff_lines) {
const targetLine = selectedFile.parallel_diff_lines.find(
line =>
(line.left && line.left.lineCode === lineCode) ||
(line.right && line.right.lineCode === lineCode),
(line.left && line.left.line_code === lineCode) ||
(line.right && line.right.line_code === lineCode),
);
if (targetLine) {
const side = targetLine.left && targetLine.left.lineCode === lineCode ? 'left' : 'right';
const side = targetLine.left && targetLine.left.line_code === lineCode ? 'left' : 'right';
 
Object.assign(targetLine[side], {
discussions: [],
Loading
Loading
@@ -177,9 +174,9 @@ export default {
}
}
 
if (selectedFile.highlightedDiffLines) {
const targetInlineLine = selectedFile.highlightedDiffLines.find(
line => line.lineCode === lineCode,
if (selectedFile.highlighted_diff_lines) {
const targetInlineLine = selectedFile.highlighted_diff_lines.find(
line => line.line_code === lineCode,
);
 
if (targetInlineLine) {
Loading
Loading
import _ from 'underscore';
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
import { diffModes } from '~/ide/constants';
import {
LINE_POSITION_LEFT,
Loading
Loading
@@ -15,7 +14,7 @@ import {
} from '../constants';
 
export function findDiffFile(files, hash) {
return files.filter(file => file.fileHash === hash)[0];
return files.filter(file => file.file_hash === hash)[0];
}
 
export const getReversePosition = linePosition => {
Loading
Loading
@@ -39,14 +38,14 @@ export function getFormData(params) {
} = params;
 
const position = JSON.stringify({
base_sha: diffFile.diffRefs.baseSha,
start_sha: diffFile.diffRefs.startSha,
head_sha: diffFile.diffRefs.headSha,
old_path: diffFile.oldPath,
new_path: diffFile.newPath,
base_sha: diffFile.diff_refs.base_sha,
start_sha: diffFile.diff_refs.start_sha,
head_sha: diffFile.diff_refs.head_sha,
old_path: diffFile.old_path,
new_path: diffFile.new_path,
position_type: positionType || TEXT_DIFF_POSITION_TYPE,
old_line: noteTargetLine ? noteTargetLine.oldLine : null,
new_line: noteTargetLine ? noteTargetLine.newLine : null,
old_line: noteTargetLine ? noteTargetLine.old_line : null,
new_line: noteTargetLine ? noteTargetLine.new_line : null,
x: params.x,
y: params.y,
width: params.width,
Loading
Loading
@@ -56,7 +55,7 @@ export function getFormData(params) {
const postData = {
view: diffViewType,
line_type: linePosition === LINE_POSITION_RIGHT ? NEW_LINE_TYPE : OLD_LINE_TYPE,
merge_request_diff_head_sha: diffFile.diffRefs.headSha,
merge_request_diff_head_sha: diffFile.diff_refs.head_sha,
in_reply_to_discussion_id: '',
note_project_id: '',
target_type: noteableData.targetType,
Loading
Loading
@@ -69,10 +68,10 @@ export function getFormData(params) {
noteable_id: noteableData.id,
commit_id: '',
type:
diffFile.diffRefs.startSha && diffFile.diffRefs.headSha
diffFile.diff_refs.start_sha && diffFile.diff_refs.head_sha
? DIFF_NOTE_TYPE
: LEGACY_DIFF_NOTE_TYPE,
line_code: noteTargetLine ? noteTargetLine.lineCode : null,
line_code: noteTargetLine ? noteTargetLine.line_code : null,
},
};
 
Loading
Loading
@@ -93,7 +92,7 @@ export const findIndexInInlineLines = (lines, lineNumbers) => {
 
return _.findIndex(
lines,
line => line.oldLine === oldLineNumber && line.newLine === newLineNumber,
line => line.old_line === oldLineNumber && line.new_line === newLineNumber,
);
};
 
Loading
Loading
@@ -105,18 +104,18 @@ export const findIndexInParallelLines = (lines, lineNumbers) => {
line =>
line.left &&
line.right &&
line.left.oldLine === oldLineNumber &&
line.right.newLine === newLineNumber,
line.left.old_line === oldLineNumber &&
line.right.new_line === newLineNumber,
);
};
 
export function removeMatchLine(diffFile, lineNumbers, bottom) {
const indexForInline = findIndexInInlineLines(diffFile.highlightedDiffLines, lineNumbers);
const indexForParallel = findIndexInParallelLines(diffFile.parallelDiffLines, lineNumbers);
const indexForInline = findIndexInInlineLines(diffFile.highlighted_diff_lines, lineNumbers);
const indexForParallel = findIndexInParallelLines(diffFile.parallel_diff_lines, lineNumbers);
const factor = bottom ? 1 : -1;
 
diffFile.highlightedDiffLines.splice(indexForInline + factor, 1);
diffFile.parallelDiffLines.splice(indexForParallel + factor, 1);
diffFile.highlighted_diff_lines.splice(indexForInline + factor, 1);
diffFile.parallel_diff_lines.splice(indexForParallel + factor, 1);
}
 
export function addLineReferences(lines, lineNumbers, bottom) {
Loading
Loading
@@ -125,18 +124,16 @@ export function addLineReferences(lines, lineNumbers, bottom) {
let matchLineIndex = -1;
 
const linesWithNumbers = lines.map((l, index) => {
const line = convertObjectPropsToCamelCase(l);
if (line.type === MATCH_LINE_TYPE) {
if (l.type === MATCH_LINE_TYPE) {
matchLineIndex = index;
} else {
Object.assign(line, {
oldLine: bottom ? oldLineNumber + index + 1 : oldLineNumber + index - lineCount,
newLine: bottom ? newLineNumber + index + 1 : newLineNumber + index - lineCount,
Object.assign(l, {
old_line: bottom ? oldLineNumber + index + 1 : oldLineNumber + index - lineCount,
new_line: bottom ? newLineNumber + index + 1 : newLineNumber + index - lineCount,
});
}
 
return line;
return l;
});
 
if (matchLineIndex > -1) {
Loading
Loading
@@ -146,9 +143,9 @@ export function addLineReferences(lines, lineNumbers, bottom) {
: linesWithNumbers[matchLineIndex + 1];
 
Object.assign(line, {
metaData: {
oldPos: targetLine.oldLine,
newPos: targetLine.newLine,
meta_data: {
old_pos: targetLine.old_line,
new_pos: targetLine.new_line,
},
});
}
Loading
Loading
@@ -187,11 +184,11 @@ export function trimFirstCharOfLineContent(line = {}) {
 
const parsedLine = Object.assign({}, line);
 
if (line.richText) {
const firstChar = parsedLine.richText.charAt(0);
if (line.rich_text) {
const firstChar = parsedLine.rich_text.charAt(0);
 
if (firstChar === ' ' || firstChar === '+' || firstChar === '-') {
parsedLine.richText = line.richText.substring(1);
parsedLine.rich_text = line.rich_text.substring(1);
}
}
 
Loading
Loading
@@ -201,15 +198,15 @@ export function trimFirstCharOfLineContent(line = {}) {
// This prepares and optimizes the incoming diff data from the server
// by setting up incremental rendering and removing unneeded data
export function prepareDiffData(diffData) {
const filesLength = diffData.diffFiles.length;
const filesLength = diffData.diff_files.length;
let showingLines = 0;
for (let i = 0; i < filesLength; i += 1) {
const file = diffData.diffFiles[i];
const file = diffData.diff_files[i];
 
if (file.parallelDiffLines) {
const linesLength = file.parallelDiffLines.length;
if (file.parallel_diff_lines) {
const linesLength = file.parallel_diff_lines.length;
for (let u = 0; u < linesLength; u += 1) {
const line = file.parallelDiffLines[u];
const line = file.parallel_diff_lines[u];
if (line.left) {
line.left = trimFirstCharOfLineContent(line.left);
}
Loading
Loading
@@ -219,13 +216,13 @@ export function prepareDiffData(diffData) {
}
}
 
if (file.highlightedDiffLines) {
const linesLength = file.highlightedDiffLines.length;
if (file.highlighted_diff_lines) {
const linesLength = file.highlighted_diff_lines.length;
for (let u = 0; u < linesLength; u += 1) {
const line = file.highlightedDiffLines[u];
const line = file.highlighted_diff_lines[u];
Object.assign(line, { ...trimFirstCharOfLineContent(line) });
}
showingLines += file.parallelDiffLines.length;
showingLines += file.parallel_diff_lines.length;
}
 
Object.assign(file, {
Loading
Loading
@@ -238,26 +235,21 @@ export function prepareDiffData(diffData) {
 
export function getDiffPositionByLineCode(diffFiles) {
return diffFiles.reduce((acc, diffFile) => {
const { baseSha, headSha, startSha } = diffFile.diffRefs;
const { newPath, oldPath } = diffFile;
// We can only use highlightedDiffLines to create the map of diff lines because
// highlightedDiffLines will also include every parallel diff line in it.
if (diffFile.highlightedDiffLines) {
diffFile.highlightedDiffLines.forEach(line => {
const { lineCode, oldLine, newLine } = line;
if (lineCode) {
acc[lineCode] = {
baseSha,
headSha,
startSha,
newPath,
oldPath,
oldLine,
newLine,
lineCode,
positionType: 'text',
if (diffFile.highlighted_diff_lines) {
diffFile.highlighted_diff_lines.forEach(line => {
if (line.line_code) {
acc[line.line_code] = {
base_sha: diffFile.diff_refs.base_sha,
head_sha: diffFile.diff_refs.head_sha,
start_sha: diffFile.diff_refs.start_sha,
new_path: diffFile.new_path,
old_path: diffFile.old_path,
old_line: line.old_line,
new_line: line.new_line,
line_code: line.line_code,
position_type: 'text',
};
}
});
Loading
Loading
@@ -270,30 +262,30 @@ export function getDiffPositionByLineCode(diffFiles) {
// This method will check whether the discussion is still applicable
// to the diff line in question regarding different versions of the MR
export function isDiscussionApplicableToLine({ discussion, diffPosition, latestDiff }) {
const { lineCode, ...diffPositionCopy } = diffPosition;
const { line_code, ...diffPositionCopy } = diffPosition;
 
if (discussion.original_position && discussion.position) {
const originalRefs = convertObjectPropsToCamelCase(discussion.original_position);
const refs = convertObjectPropsToCamelCase(discussion.position);
const originalRefs = discussion.original_position;
const refs = discussion.position;
 
return _.isEqual(refs, diffPositionCopy) || _.isEqual(originalRefs, diffPositionCopy);
}
 
return latestDiff && discussion.active && lineCode === discussion.line_code;
// eslint-disable-next-line
return latestDiff && discussion.active && line_code === discussion.line_code;
}
 
export const generateTreeList = files =>
files.reduce(
(acc, file) => {
const { fileHash, addedLines, removedLines, newFile, deletedFile, newPath } = file;
const split = newPath.split('/');
const split = file.new_path.split('/');
 
split.forEach((name, i) => {
const parent = acc.treeEntries[split.slice(0, i).join('/')];
const path = `${parent ? `${parent.path}/` : ''}${name}`;
 
if (!acc.treeEntries[path]) {
const type = path === newPath ? 'blob' : 'tree';
const type = path === file.new_path ? 'blob' : 'tree';
acc.treeEntries[path] = {
key: path,
path,
Loading
Loading
@@ -307,11 +299,11 @@ export const generateTreeList = files =>
if (type === 'blob') {
Object.assign(entry, {
changed: true,
tempFile: newFile,
deleted: deletedFile,
fileHash,
addedLines,
removedLines,
tempFile: file.new_file,
deleted: file.deleted_file,
fileHash: file.file_hash,
addedLines: file.added_lines,
removedLines: file.removed_lines,
});
} else {
Object.assign(entry, {
Loading
Loading
@@ -329,6 +321,6 @@ export const generateTreeList = files =>
);
 
export const getDiffMode = diffFile => {
const diffModeKey = Object.keys(diffModes).find(key => diffFile[`${key}File`]);
const diffModeKey = Object.keys(diffModes).find(key => diffFile[`${key}_file`]);
return diffModes[diffModeKey] || diffModes.replaced;
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment