diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-15 12:10:00 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-15 12:10:00 +0300 |
commit | a79324ad1f94b0c497a89c1ee35bd7d33f318008 (patch) | |
tree | 51758517c955d805e343b5b640724964100219f9 /app/assets | |
parent | 4f33294e27e82f7d281c7ff7e390aa6c2ea32cb9 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets')
-rw-r--r-- | app/assets/javascripts/blob/file_template_mediator.js | 7 | ||||
-rw-r--r-- | app/assets/javascripts/blob_edit/edit_blob.js | 3 | ||||
-rw-r--r-- | app/assets/javascripts/diffs/store/actions.js | 8 | ||||
-rw-r--r-- | app/assets/javascripts/diffs/store/mutations.js | 7 | ||||
-rw-r--r-- | app/assets/javascripts/diffs/store/utils.js | 4 | ||||
-rw-r--r-- | app/assets/javascripts/diffs/utils/diff_file.js | 22 | ||||
-rw-r--r-- | app/assets/javascripts/ide/lib/common/model.js | 3 | ||||
-rw-r--r-- | app/assets/javascripts/ide/utils.js | 4 | ||||
-rw-r--r-- | app/assets/javascripts/lib/utils/text_utility.js | 10 |
9 files changed, 46 insertions, 22 deletions
diff --git a/app/assets/javascripts/blob/file_template_mediator.js b/app/assets/javascripts/blob/file_template_mediator.js index 5058ca7122d..8f64bda1ba6 100644 --- a/app/assets/javascripts/blob/file_template_mediator.js +++ b/app/assets/javascripts/blob/file_template_mediator.js @@ -82,7 +82,6 @@ export default class FileTemplateMediator { initPageEvents() { this.listenForFilenameInput(); - this.prepFileContentForSubmit(); this.listenForPreviewMode(); } @@ -92,12 +91,6 @@ export default class FileTemplateMediator { }); } - prepFileContentForSubmit() { - this.$commitForm.submit(() => { - this.$fileContent.val(this.editor.getValue()); - }); - } - listenForPreviewMode() { this.$navLinks.on('click', 'a', e => { const urlPieces = e.target.href.split('#'); diff --git a/app/assets/javascripts/blob_edit/edit_blob.js b/app/assets/javascripts/blob_edit/edit_blob.js index c8a31d96a69..1bc51aa1d6f 100644 --- a/app/assets/javascripts/blob_edit/edit_blob.js +++ b/app/assets/javascripts/blob_edit/edit_blob.js @@ -6,6 +6,7 @@ import TemplateSelectorMediator from '../blob/file_template_mediator'; import { addEditorMarkdownListeners } from '~/lib/utils/text_markdown'; import EditorLite from '~/editor/editor_lite'; import { FileTemplateExtension } from '~/editor/editor_file_template_ext'; +import { insertFinalNewline } from '~/lib/utils/text_utility'; export default class EditBlob { // The options object has: @@ -49,7 +50,7 @@ export default class EditBlob { }); form.addEventListener('submit', () => { - fileContentEl.value = this.editor.getValue(); + fileContentEl.value = insertFinalNewline(this.editor.getValue()); }); } diff --git a/app/assets/javascripts/diffs/store/actions.js b/app/assets/javascripts/diffs/store/actions.js index 8c72971682d..5b410051705 100644 --- a/app/assets/javascripts/diffs/store/actions.js +++ b/app/assets/javascripts/diffs/store/actions.js @@ -191,7 +191,13 @@ export const fetchDiffFilesMeta = ({ commit, state }) => { commit(types.SET_MERGE_REQUEST_DIFFS, data.merge_request_diffs || []); commit(types.SET_DIFF_METADATA, strippedData); - worker.postMessage(prepareDiffData(data, state.diffFiles)); + worker.postMessage( + prepareDiffData({ + diff: data, + priorFiles: state.diffFiles, + meta: true, + }), + ); return data; }) diff --git a/app/assets/javascripts/diffs/store/mutations.js b/app/assets/javascripts/diffs/store/mutations.js index 90940d82226..19122c3096f 100644 --- a/app/assets/javascripts/diffs/store/mutations.js +++ b/app/assets/javascripts/diffs/store/mutations.js @@ -73,7 +73,10 @@ export default { }, [types.SET_DIFF_DATA_BATCH](state, data) { - const files = prepareDiffData(data, state.diffFiles); + const files = prepareDiffData({ + diff: data, + priorFiles: state.diffFiles, + }); Object.assign(state, { ...convertObjectPropsToCamelCase(data), @@ -143,7 +146,7 @@ export default { }, [types.ADD_COLLAPSED_DIFFS](state, { file, data }) { - const files = prepareDiffData(data); + const files = prepareDiffData({ diff: data }); const [newFileData] = 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 }); diff --git a/app/assets/javascripts/diffs/store/utils.js b/app/assets/javascripts/diffs/store/utils.js index 8949c8cd23e..1839df12c96 100644 --- a/app/assets/javascripts/diffs/store/utils.js +++ b/app/assets/javascripts/diffs/store/utils.js @@ -386,9 +386,9 @@ function deduplicateFilesList(files) { return Object.values(dedupedFiles); } -export function prepareDiffData(diff, priorFiles = []) { +export function prepareDiffData({ diff, priorFiles = [], meta = false }) { const cleanedFiles = (diff.diff_files || []) - .map((file, index, allFiles) => prepareRawDiffFile({ file, allFiles })) + .map((file, index, allFiles) => prepareRawDiffFile({ file, allFiles, meta })) .map(ensureBasicDiffFileLines) .map(prepareDiffFileLines) .map(finalizeDiffFile); diff --git a/app/assets/javascripts/diffs/utils/diff_file.js b/app/assets/javascripts/diffs/utils/diff_file.js index aa801783c57..67f117bc4d3 100644 --- a/app/assets/javascripts/diffs/utils/diff_file.js +++ b/app/assets/javascripts/diffs/utils/diff_file.js @@ -4,6 +4,7 @@ import { DIFF_FILE_MANUAL_COLLAPSE, DIFF_FILE_AUTOMATIC_COLLAPSE, } from '../constants'; +import { uuids } from './uuids'; function fileSymlinkInformation(file, fileList) { const duplicates = fileList.filter(iteratedFile => iteratedFile.file_hash === file.file_hash); @@ -32,16 +33,29 @@ function collapsed(file) { }; } -export function prepareRawDiffFile({ file, allFiles }) { - Object.assign(file, { +function identifier(file) { + return uuids({ + seeds: [file.file_identifier_hash, file.content_sha], + })[0]; +} + +export function prepareRawDiffFile({ file, allFiles, meta = false }) { + const additionalProperties = { brokenSymlink: fileSymlinkInformation(file, allFiles), viewer: { ...file.viewer, ...collapsed(file), }, - }); + }; + + // It's possible, but not confirmed, that `content_sha` isn't available sometimes + // See: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/49506#note_464692057 + // We don't want duplicate IDs if that's the case, so we just don't assign an ID + if (!meta && file.content_sha) { + additionalProperties.id = identifier(file); + } - return file; + return Object.assign(file, additionalProperties); } export function collapsedType(file) { diff --git a/app/assets/javascripts/ide/lib/common/model.js b/app/assets/javascripts/ide/lib/common/model.js index c5bb00c3dee..2471b3627ce 100644 --- a/app/assets/javascripts/ide/lib/common/model.js +++ b/app/assets/javascripts/ide/lib/common/model.js @@ -1,7 +1,8 @@ import { editor as monacoEditor, Uri } from 'monaco-editor'; import Disposable from './disposable'; import eventHub from '../../eventhub'; -import { trimTrailingWhitespace, insertFinalNewline } from '../../utils'; +import { trimTrailingWhitespace } from '../../utils'; +import { insertFinalNewline } from '~/lib/utils/text_utility'; import { defaultModelOptions } from '../editor_options'; export default class Model { diff --git a/app/assets/javascripts/ide/utils.js b/app/assets/javascripts/ide/utils.js index 1ca1b971de1..43276f32322 100644 --- a/app/assets/javascripts/ide/utils.js +++ b/app/assets/javascripts/ide/utils.js @@ -97,10 +97,6 @@ export function trimTrailingWhitespace(content) { return content.replace(/[^\S\r\n]+$/gm, ''); } -export function insertFinalNewline(content, eol = '\n') { - return content.slice(-eol.length) !== eol ? `${content}${eol}` : content; -} - export function getPathParents(path, maxDepth = Infinity) { const pathComponents = path.split('/'); const paths = []; diff --git a/app/assets/javascripts/lib/utils/text_utility.js b/app/assets/javascripts/lib/utils/text_utility.js index a81ca3f211f..c398874db24 100644 --- a/app/assets/javascripts/lib/utils/text_utility.js +++ b/app/assets/javascripts/lib/utils/text_utility.js @@ -411,3 +411,13 @@ export const hasContent = obj => isString(obj) && obj.trim() !== ''; export const isValidSha1Hash = str => { return /^[0-9a-f]{5,40}$/.test(str); }; + +/** + * Adds a final newline to the content if it doesn't already exist + * + * @param {*} content Content + * @param {*} endOfLine Type of newline: CRLF='\r\n', LF='\n', CR='\r' + */ +export function insertFinalNewline(content, endOfLine = '\n') { + return content.slice(-endOfLine.length) !== endOfLine ? `${content}${endOfLine}` : content; +} |