Commit ac6673dd authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch 'ide-open-all-mr-files' into 'master'

Open first 10 merge request files in IDE

Closes #51635

See merge request gitlab-org/gitlab-ce!23234
parents d179ffc2 b24316b2
...@@ -56,7 +56,10 @@ export const setFileActive = ({ commit, state, getters, dispatch }, path) => { ...@@ -56,7 +56,10 @@ export const setFileActive = ({ commit, state, getters, dispatch }, path) => {
dispatch('scrollToTab'); dispatch('scrollToTab');
}; };
export const getFileData = ({ state, commit, dispatch }, { path, makeFileActive = true }) => { export const getFileData = (
{ state, commit, dispatch },
{ path, makeFileActive = true, openFile = makeFileActive },
) => {
const file = state.entries[path]; const file = state.entries[path];
if (file.raw || (file.tempFile && !file.prevPath)) return Promise.resolve(); if (file.raw || (file.tempFile && !file.prevPath)) return Promise.resolve();
...@@ -71,8 +74,8 @@ export const getFileData = ({ state, commit, dispatch }, { path, makeFileActive ...@@ -71,8 +74,8 @@ export const getFileData = ({ state, commit, dispatch }, { path, makeFileActive
const normalizedHeaders = normalizeHeaders(headers); const normalizedHeaders = normalizeHeaders(headers);
setPageTitle(decodeURI(normalizedHeaders['PAGE-TITLE'])); setPageTitle(decodeURI(normalizedHeaders['PAGE-TITLE']));
commit(types.SET_FILE_DATA, { data, file }); if (data) commit(types.SET_FILE_DATA, { data, file });
if (makeFileActive) commit(types.TOGGLE_FILE_OPEN, path); if (openFile) commit(types.TOGGLE_FILE_OPEN, path);
if (makeFileActive) dispatch('setFileActive', path); if (makeFileActive) dispatch('setFileActive', path);
commit(types.TOGGLE_LOADING, { entry: file }); commit(types.TOGGLE_LOADING, { entry: file });
}) })
......
...@@ -161,6 +161,7 @@ export const openMergeRequest = ( ...@@ -161,6 +161,7 @@ export const openMergeRequest = (
dispatch('getFileData', { dispatch('getFileData', {
path: change.new_path, path: change.new_path,
makeFileActive: ind === 0, makeFileActive: ind === 0,
openFile: true,
}); });
} }
} }
......
---
title: Open first 10 merge request files in IDE
merge_request:
author:
type: fixed
...@@ -262,16 +262,28 @@ describe('IDE store merge request actions', () => { ...@@ -262,16 +262,28 @@ describe('IDE store merge request actions', () => {
bar: {}, bar: {},
}; };
spyOn(store, 'dispatch').and.callFake(type => { const originalDispatch = store.dispatch;
spyOn(store, 'dispatch').and.callFake((type, payload) => {
switch (type) { switch (type) {
case 'getMergeRequestData': case 'getMergeRequestData':
return Promise.resolve(testMergeRequest); return Promise.resolve(testMergeRequest);
case 'getMergeRequestChanges': case 'getMergeRequestChanges':
return Promise.resolve(testMergeRequestChanges); return Promise.resolve(testMergeRequestChanges);
default: case 'getFiles':
case 'getMergeRequestVersions':
case 'getBranchData':
case 'setFileMrChange':
return Promise.resolve(); return Promise.resolve();
default:
return originalDispatch(type, payload);
} }
}); });
spyOn(service, 'getFileData').and.callFake(() =>
Promise.resolve({
headers: {},
}),
);
}); });
it('dispatch actions for merge request data', done => { it('dispatch actions for merge request data', done => {
...@@ -303,7 +315,17 @@ describe('IDE store merge request actions', () => { ...@@ -303,7 +315,17 @@ describe('IDE store merge request actions', () => {
}); });
it('updates activity bar view and gets file data, if changes are found', done => { it('updates activity bar view and gets file data, if changes are found', done => {
testMergeRequestChanges.changes = [{ new_path: 'foo' }, { new_path: 'bar' }]; store.state.entries.foo = {
url: 'test',
};
store.state.entries.bar = {
url: 'test',
};
testMergeRequestChanges.changes = [
{ new_path: 'foo', path: 'foo' },
{ new_path: 'bar', path: 'bar' },
];
openMergeRequest(store, mr) openMergeRequest(store, mr)
.then(() => { .then(() => {
...@@ -321,8 +343,11 @@ describe('IDE store merge request actions', () => { ...@@ -321,8 +343,11 @@ describe('IDE store merge request actions', () => {
expect(store.dispatch).toHaveBeenCalledWith('getFileData', { expect(store.dispatch).toHaveBeenCalledWith('getFileData', {
path: change.new_path, path: change.new_path,
makeFileActive: i === 0, makeFileActive: i === 0,
openFile: true,
}); });
}); });
expect(store.state.openFiles.length).toBe(testMergeRequestChanges.changes.length);
}) })
.then(done) .then(done)
.catch(done.fail); .catch(done.fail);
......
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