diff options
author | Filipa Lacerda <filipa@gitlab.com> | 2018-08-17 08:40:40 +0000 |
---|---|---|
committer | Julius Kvedaras <juliuskvedaras@yahoo.ie> | 2018-08-17 10:39:34 +0100 |
commit | 9e5f6c7476e3bbc789ab228db945b31075a6e4fb (patch) | |
tree | b39ad676a56d54d84c6e09bea0dfd14a509a52ab | |
parent | 1cb68dc8af05098305893df94b1bc10e3cff0894 (diff) | |
download | gitlab-ce-9e5f6c7476e3bbc789ab228db945b31075a6e4fb.tar.gz |
Merge branch 'ide-live-preview-merge-requests' into 'master'
Fixed Web IDE live preview crashing when loading from merge request
Closes #50392
See merge request gitlab-org/gitlab-ce!21252
-rw-r--r-- | app/assets/javascripts/ide/components/repo_editor.vue | 1 | ||||
-rw-r--r-- | app/assets/javascripts/ide/stores/actions/file.js | 7 | ||||
-rw-r--r-- | spec/javascripts/ide/stores/actions/file_spec.js | 20 |
3 files changed, 19 insertions, 9 deletions
diff --git a/app/assets/javascripts/ide/components/repo_editor.vue b/app/assets/javascripts/ide/components/repo_editor.vue index f9badb01535..f55aa843444 100644 --- a/app/assets/javascripts/ide/components/repo_editor.vue +++ b/app/assets/javascripts/ide/components/repo_editor.vue @@ -133,7 +133,6 @@ export default { .then(() => this.getRawFileData({ path: this.file.path, - baseSha: this.currentMergeRequest ? this.currentMergeRequest.baseCommitSha : '', }), ) .then(() => { diff --git a/app/assets/javascripts/ide/stores/actions/file.js b/app/assets/javascripts/ide/stores/actions/file.js index 9e3f5da4676..1417b6fdb84 100644 --- a/app/assets/javascripts/ide/stores/actions/file.js +++ b/app/assets/javascripts/ide/stores/actions/file.js @@ -95,7 +95,7 @@ export const setFileMrChange = ({ commit }, { file, mrChange }) => { commit(types.SET_FILE_MERGE_REQUEST_CHANGE, { file, mrChange }); }; -export const getRawFileData = ({ state, commit, dispatch }, { path, baseSha }) => { +export const getRawFileData = ({ state, commit, dispatch, getters }, { path }) => { const file = state.entries[path]; return new Promise((resolve, reject) => { service @@ -103,6 +103,9 @@ export const getRawFileData = ({ state, commit, dispatch }, { path, baseSha }) = .then(raw => { if (!(file.tempFile && !file.prevPath)) commit(types.SET_FILE_RAW_DATA, { file, raw }); if (file.mrChange && file.mrChange.new_file === false) { + const baseSha = + (getters.currentMergeRequest && getters.currentMergeRequest.baseCommitSha) || ''; + service .getBaseRawFileData(file, baseSha) .then(baseRaw => { @@ -125,7 +128,7 @@ export const getRawFileData = ({ state, commit, dispatch }, { path, baseSha }) = action: payload => dispatch('getRawFileData', payload).then(() => dispatch('setErrorMessage', null)), actionText: __('Please try again'), - actionPayload: { path, baseSha }, + actionPayload: { path }, }); reject(); }); diff --git a/spec/javascripts/ide/stores/actions/file_spec.js b/spec/javascripts/ide/stores/actions/file_spec.js index 72eb20bdc87..bca2033ff97 100644 --- a/spec/javascripts/ide/stores/actions/file_spec.js +++ b/spec/javascripts/ide/stores/actions/file_spec.js @@ -352,10 +352,22 @@ describe('IDE store file actions', () => { it('calls also getBaseRawFileData service method', done => { spyOn(service, 'getBaseRawFileData').and.returnValue(Promise.resolve('baseraw')); + store.state.currentProjectId = 'gitlab-org/gitlab-ce'; + store.state.currentMergeRequestId = '1'; + store.state.projects = { + 'gitlab-org/gitlab-ce': { + mergeRequests: { + 1: { + baseCommitSha: 'SHA', + }, + }, + }, + }; + tmpFile.mrChange = { new_file: false }; store - .dispatch('getRawFileData', { path: tmpFile.path, baseSha: 'SHA' }) + .dispatch('getRawFileData', { path: tmpFile.path }) .then(() => { expect(service.getBaseRawFileData).toHaveBeenCalledWith(tmpFile, 'SHA'); expect(tmpFile.baseRaw).toBe('baseraw'); @@ -392,10 +404,7 @@ describe('IDE store file actions', () => { const dispatch = jasmine.createSpy('dispatch'); actions - .getRawFileData( - { state: store.state, commit() {}, dispatch }, - { path: tmpFile.path, baseSha: tmpFile.baseSha }, - ) + .getRawFileData({ state: store.state, commit() {}, dispatch }, { path: tmpFile.path }) .then(done.fail) .catch(() => { expect(dispatch).toHaveBeenCalledWith('setErrorMessage', { @@ -404,7 +413,6 @@ describe('IDE store file actions', () => { actionText: 'Please try again', actionPayload: { path: tmpFile.path, - baseSha: tmpFile.baseSha, }, }); |