Commit a22347cc authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch 'symlink-identifier/simplify-diffs-actions' into 'master'

Clean up unnecessary actions

See merge request gitlab-org/gitlab!32735
parents 761ef054 aefff876
...@@ -507,9 +507,6 @@ export const cacheTreeListWidth = (_, size) => { ...@@ -507,9 +507,6 @@ export const cacheTreeListWidth = (_, size) => {
localStorage.setItem(TREE_LIST_WIDTH_STORAGE_KEY, size); localStorage.setItem(TREE_LIST_WIDTH_STORAGE_KEY, size);
}; };
export const requestFullDiff = ({ commit }, filePath) => commit(types.REQUEST_FULL_DIFF, filePath);
export const receiveFullDiffSucess = ({ commit }, { filePath }) =>
commit(types.RECEIVE_FULL_DIFF_SUCCESS, { filePath });
export const receiveFullDiffError = ({ commit }, filePath) => { export const receiveFullDiffError = ({ commit }, filePath) => {
commit(types.RECEIVE_FULL_DIFF_ERROR, filePath); commit(types.RECEIVE_FULL_DIFF_ERROR, filePath);
createFlash(s__('MergeRequest|Error loading full diff. Please try again.')); createFlash(s__('MergeRequest|Error loading full diff. Please try again.'));
...@@ -600,7 +597,7 @@ export const setExpandedDiffLines = ({ commit, state }, { file, data }) => { ...@@ -600,7 +597,7 @@ export const setExpandedDiffLines = ({ commit, state }, { file, data }) => {
} }
}; };
export const fetchFullDiff = ({ dispatch }, file) => export const fetchFullDiff = ({ commit, dispatch }, file) =>
axios axios
.get(file.context_lines_path, { .get(file.context_lines_path, {
params: { params: {
...@@ -609,15 +606,16 @@ export const fetchFullDiff = ({ dispatch }, file) => ...@@ -609,15 +606,16 @@ export const fetchFullDiff = ({ dispatch }, file) =>
}, },
}) })
.then(({ data }) => { .then(({ data }) => {
dispatch('receiveFullDiffSucess', { filePath: file.file_path }); commit(types.RECEIVE_FULL_DIFF_SUCCESS, { filePath: file.file_path });
dispatch('setExpandedDiffLines', { file, data }); dispatch('setExpandedDiffLines', { file, data });
}) })
.catch(() => dispatch('receiveFullDiffError', file.file_path)); .catch(() => dispatch('receiveFullDiffError', file.file_path));
export const toggleFullDiff = ({ dispatch, getters, state }, filePath) => { export const toggleFullDiff = ({ dispatch, commit, getters, state }, filePath) => {
const file = state.diffFiles.find(f => f.file_path === filePath); const file = state.diffFiles.find(f => f.file_path === filePath);
dispatch('requestFullDiff', filePath); commit(types.REQUEST_FULL_DIFF, filePath);
if (file.isShowingFullFile) { if (file.isShowingFullFile) {
dispatch('loadCollapsedDiff', file) dispatch('loadCollapsedDiff', file)
......
...@@ -35,8 +35,6 @@ import { ...@@ -35,8 +35,6 @@ import {
setRenderTreeList, setRenderTreeList,
setShowWhitespace, setShowWhitespace,
setRenderIt, setRenderIt,
requestFullDiff,
receiveFullDiffSucess,
receiveFullDiffError, receiveFullDiffError,
fetchFullDiff, fetchFullDiff,
toggleFullDiff, toggleFullDiff,
...@@ -1136,34 +1134,8 @@ describe('DiffsStoreActions', () => { ...@@ -1136,34 +1134,8 @@ describe('DiffsStoreActions', () => {
}); });
}); });
describe('requestFullDiff', () => {
it('commits REQUEST_FULL_DIFF', done => {
testAction(
requestFullDiff,
'file',
{},
[{ type: types.REQUEST_FULL_DIFF, payload: 'file' }],
[],
done,
);
});
});
describe('receiveFullDiffSucess', () => {
it('commits REQUEST_FULL_DIFF', done => {
testAction(
receiveFullDiffSucess,
{ filePath: 'test' },
{},
[{ type: types.RECEIVE_FULL_DIFF_SUCCESS, payload: { filePath: 'test' } }],
[],
done,
);
});
});
describe('receiveFullDiffError', () => { describe('receiveFullDiffError', () => {
it('commits REQUEST_FULL_DIFF', done => { it('updates state with the file that did not load', done => {
testAction( testAction(
receiveFullDiffError, receiveFullDiffError,
'file', 'file',
...@@ -1191,7 +1163,7 @@ describe('DiffsStoreActions', () => { ...@@ -1191,7 +1163,7 @@ describe('DiffsStoreActions', () => {
mock.onGet(`${gl.TEST_HOST}/context`).replyOnce(200, ['test']); mock.onGet(`${gl.TEST_HOST}/context`).replyOnce(200, ['test']);
}); });
it('dispatches receiveFullDiffSucess', done => { it('commits the success and dispatches an action to expand the new lines', done => {
const file = { const file = {
context_lines_path: `${gl.TEST_HOST}/context`, context_lines_path: `${gl.TEST_HOST}/context`,
file_path: 'test', file_path: 'test',
...@@ -1201,11 +1173,8 @@ describe('DiffsStoreActions', () => { ...@@ -1201,11 +1173,8 @@ describe('DiffsStoreActions', () => {
fetchFullDiff, fetchFullDiff,
file, file,
null, null,
[], [{ type: types.RECEIVE_FULL_DIFF_SUCCESS, payload: { filePath: 'test' } }],
[ [{ type: 'setExpandedDiffLines', payload: { file, data: ['test'] } }],
{ type: 'receiveFullDiffSucess', payload: { filePath: 'test' } },
{ type: 'setExpandedDiffLines', payload: { file, data: ['test'] } },
],
done, done,
); );
}); });
...@@ -1243,11 +1212,8 @@ describe('DiffsStoreActions', () => { ...@@ -1243,11 +1212,8 @@ describe('DiffsStoreActions', () => {
toggleFullDiff, toggleFullDiff,
'test', 'test',
state, state,
[], [{ type: types.REQUEST_FULL_DIFF, payload: 'test' }],
[ [{ type: 'fetchFullDiff', payload: state.diffFiles[0] }],
{ type: 'requestFullDiff', payload: 'test' },
{ type: 'fetchFullDiff', payload: state.diffFiles[0] },
],
done, done,
); );
}); });
......
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