Commit ccdd16dc authored by Filipa Lacerda's avatar Filipa Lacerda

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
parents cf2c99cc 0ac3cd80
...@@ -133,7 +133,6 @@ export default { ...@@ -133,7 +133,6 @@ export default {
.then(() => .then(() =>
this.getRawFileData({ this.getRawFileData({
path: this.file.path, path: this.file.path,
baseSha: this.currentMergeRequest ? this.currentMergeRequest.baseCommitSha : '',
}), }),
) )
.then(() => { .then(() => {
......
...@@ -92,7 +92,7 @@ export const setFileMrChange = ({ commit }, { file, mrChange }) => { ...@@ -92,7 +92,7 @@ export const setFileMrChange = ({ commit }, { file, mrChange }) => {
commit(types.SET_FILE_MERGE_REQUEST_CHANGE, { 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]; const file = state.entries[path];
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
service service
...@@ -100,6 +100,9 @@ export const getRawFileData = ({ state, commit, dispatch }, { path, baseSha }) = ...@@ -100,6 +100,9 @@ export const getRawFileData = ({ state, commit, dispatch }, { path, baseSha }) =
.then(raw => { .then(raw => {
if (!(file.tempFile && !file.prevPath)) commit(types.SET_FILE_RAW_DATA, { file, raw }); if (!(file.tempFile && !file.prevPath)) commit(types.SET_FILE_RAW_DATA, { file, raw });
if (file.mrChange && file.mrChange.new_file === false) { if (file.mrChange && file.mrChange.new_file === false) {
const baseSha =
(getters.currentMergeRequest && getters.currentMergeRequest.baseCommitSha) || '';
service service
.getBaseRawFileData(file, baseSha) .getBaseRawFileData(file, baseSha)
.then(baseRaw => { .then(baseRaw => {
...@@ -122,7 +125,7 @@ export const getRawFileData = ({ state, commit, dispatch }, { path, baseSha }) = ...@@ -122,7 +125,7 @@ export const getRawFileData = ({ state, commit, dispatch }, { path, baseSha }) =
action: payload => action: payload =>
dispatch('getRawFileData', payload).then(() => dispatch('setErrorMessage', null)), dispatch('getRawFileData', payload).then(() => dispatch('setErrorMessage', null)),
actionText: __('Please try again'), actionText: __('Please try again'),
actionPayload: { path, baseSha }, actionPayload: { path },
}); });
reject(); reject();
}); });
......
...@@ -352,10 +352,22 @@ describe('IDE store file actions', () => { ...@@ -352,10 +352,22 @@ describe('IDE store file actions', () => {
it('calls also getBaseRawFileData service method', done => { it('calls also getBaseRawFileData service method', done => {
spyOn(service, 'getBaseRawFileData').and.returnValue(Promise.resolve('baseraw')); 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 }; tmpFile.mrChange = { new_file: false };
store store
.dispatch('getRawFileData', { path: tmpFile.path, baseSha: 'SHA' }) .dispatch('getRawFileData', { path: tmpFile.path })
.then(() => { .then(() => {
expect(service.getBaseRawFileData).toHaveBeenCalledWith(tmpFile, 'SHA'); expect(service.getBaseRawFileData).toHaveBeenCalledWith(tmpFile, 'SHA');
expect(tmpFile.baseRaw).toBe('baseraw'); expect(tmpFile.baseRaw).toBe('baseraw');
...@@ -392,10 +404,7 @@ describe('IDE store file actions', () => { ...@@ -392,10 +404,7 @@ describe('IDE store file actions', () => {
const dispatch = jasmine.createSpy('dispatch'); const dispatch = jasmine.createSpy('dispatch');
actions actions
.getRawFileData( .getRawFileData({ state: store.state, commit() {}, dispatch }, { path: tmpFile.path })
{ state: store.state, commit() {}, dispatch },
{ path: tmpFile.path, baseSha: tmpFile.baseSha },
)
.then(done.fail) .then(done.fail)
.catch(() => { .catch(() => {
expect(dispatch).toHaveBeenCalledWith('setErrorMessage', { expect(dispatch).toHaveBeenCalledWith('setErrorMessage', {
...@@ -404,7 +413,6 @@ describe('IDE store file actions', () => { ...@@ -404,7 +413,6 @@ describe('IDE store file actions', () => {
actionText: 'Please try again', actionText: 'Please try again',
actionPayload: { actionPayload: {
path: tmpFile.path, path: tmpFile.path,
baseSha: tmpFile.baseSha,
}, },
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment