diff --git a/app/assets/javascripts/repo/components/new_dropdown/modal.vue b/app/assets/javascripts/repo/components/new_dropdown/modal.vue index 51f74b06bae..ff13b3072bb 100644 --- a/app/assets/javascripts/repo/components/new_dropdown/modal.vue +++ b/app/assets/javascripts/repo/components/new_dropdown/modal.vue @@ -13,7 +13,7 @@ }, data() { return { - entryName: '', + entryName: RepoStore.path !== '' ? `${RepoStore.path}/` : '', }; }, components: { @@ -30,6 +30,8 @@ const dirNames = this.entryName.split('/'); dirNames.forEach((dirName) => { + if (dirName === '') return; + tree = RepoHelper.findOrCreateEntry('tree', tree, dirName).entry; }); } diff --git a/app/assets/javascripts/repo/components/repo_editor.vue b/app/assets/javascripts/repo/components/repo_editor.vue index 9f567d4e94d..df4caba51d8 100644 --- a/app/assets/javascripts/repo/components/repo_editor.vue +++ b/app/assets/javascripts/repo/components/repo_editor.vue @@ -16,35 +16,28 @@ const RepoEditor = { }, mounted() { - if (!this.activeFile.tempFile) { - Service.getRaw(this.activeFile.raw_path) - .then((rawResponse) => { - Store.blobRaw = rawResponse.data; - Store.activeFile.plain = rawResponse.data; + Service.getRaw(this.activeFile) + .then((rawResponse) => { + Store.blobRaw = rawResponse.data; + Store.activeFile.plain = rawResponse.data; - this.createMonacoInstance(); - }) - .catch(Helper.loadingError); - } else { - this.createMonacoInstance(); - } + const monacoInstance = Helper.monaco.editor.create(this.$el, { + model: null, + readOnly: false, + contextmenu: true, + scrollBeyondLastLine: false, + }); + + Helper.monacoInstance = monacoInstance; + + this.addMonacoEvents(); + + this.setupEditor(); + }) + .catch(Helper.loadingError); }, methods: { - createMonacoInstance() { - const monacoInstance = Helper.monaco.editor.create(this.$el, { - model: null, - readOnly: false, - contextmenu: true, - scrollBeyondLastLine: false, - }); - - Helper.monacoInstance = monacoInstance; - - this.addMonacoEvents(); - - this.setupEditor(); - }, setupEditor() { this.showHide(); diff --git a/app/assets/javascripts/repo/helpers/repo_helper.js b/app/assets/javascripts/repo/helpers/repo_helper.js index cc9bab2bb6a..09573e6e707 100644 --- a/app/assets/javascripts/repo/helpers/repo_helper.js +++ b/app/assets/javascripts/repo/helpers/repo_helper.js @@ -110,7 +110,7 @@ const RepoHelper = { RepoHelper.setBinaryDataAsBase64(data); Store.setViewToPreview(); } else if (!Store.isPreviewView() && !data.render_error) { - Service.getRaw(data.raw_path) + Service.getRaw(data) .then((rawResponse) => { Store.blobRaw = rawResponse.data; data.plain = rawResponse.data; diff --git a/app/assets/javascripts/repo/services/repo_service.js b/app/assets/javascripts/repo/services/repo_service.js index d68d71a4629..de8a2ecaa1d 100644 --- a/app/assets/javascripts/repo/services/repo_service.js +++ b/app/assets/javascripts/repo/services/repo_service.js @@ -12,8 +12,14 @@ const RepoService = { }, richExtensionRegExp: /md/, - getRaw(url) { - return axios.get(url, { + getRaw(file) { + if (file.tempFile) { + return Promise.resolve({ + data: '', + }); + } + + return axios.get(file.raw_path, { // Stop Axios from parsing a JSON file into a JS object transformResponse: [res => res], }); diff --git a/app/assets/javascripts/repo/stores/repo_store.js b/app/assets/javascripts/repo/stores/repo_store.js index 530c725ceb6..4978af07067 100644 --- a/app/assets/javascripts/repo/stores/repo_store.js +++ b/app/assets/javascripts/repo/stores/repo_store.js @@ -77,7 +77,7 @@ const RepoStore = { } else if (file.newContent || file.plain) { RepoStore.blobRaw = file.newContent || file.plain; } else if (!file.tempFile) { - Service.getRaw(file.raw_path) + Service.getRaw(file) .then((rawResponse) => { RepoStore.blobRaw = rawResponse.data; Helper.findOpenedFileFromActive().plain = rawResponse.data; diff --git a/spec/javascripts/repo/components/repo_file_buttons_spec.js b/spec/javascripts/repo/components/repo_file_buttons_spec.js index 701c260224f..bc5cb5b8f38 100644 --- a/spec/javascripts/repo/components/repo_file_buttons_spec.js +++ b/spec/javascripts/repo/components/repo_file_buttons_spec.js @@ -2,7 +2,16 @@ import Vue from 'vue'; import repoFileButtons from '~/repo/components/repo_file_buttons.vue'; import RepoStore from '~/repo/stores/repo_store'; -describe('RepoFileButtons', () => { +fdescribe('RepoFileButtons', () => { + const activeFile = { + extension: 'md', + url: 'url', + raw_path: 'raw_path', + blame_path: 'blame_path', + commits_path: 'commits_path', + permalink: 'permalink', + }; + function createComponent() { const RepoFileButtons = Vue.extend(repoFileButtons); @@ -14,14 +23,6 @@ describe('RepoFileButtons', () => { }); it('renders Raw, Blame, History, Permalink and Preview toggle', () => { - const activeFile = { - extension: 'md', - url: 'url', - raw_path: 'raw_path', - blame_path: 'blame_path', - commits_path: 'commits_path', - permalink: 'permalink', - }; const activeFileLabel = 'activeFileLabel'; RepoStore.openedFiles = new Array(1); RepoStore.activeFile = activeFile; @@ -46,10 +47,6 @@ describe('RepoFileButtons', () => { }); it('triggers rawPreviewToggle on preview click', () => { - const activeFile = { - extension: 'md', - url: 'url', - }; RepoStore.openedFiles = new Array(1); RepoStore.activeFile = activeFile; RepoStore.editMode = true; @@ -65,10 +62,7 @@ describe('RepoFileButtons', () => { }); it('does not render preview toggle if not canPreview', () => { - const activeFile = { - extension: 'abcd', - url: 'url', - }; + activeFile.extension = 'js'; RepoStore.openedFiles = new Array(1); RepoStore.activeFile = activeFile;