Commit 1b04fb50 authored by Thomas Randolph's avatar Thomas Randolph Committed by Mike Greiling

Sync single-file mode user preference

parent 08c5076e
...@@ -793,10 +793,22 @@ export const navigateToDiffFileIndex = ({ commit, state }, index) => { ...@@ -793,10 +793,22 @@ export const navigateToDiffFileIndex = ({ commit, state }, index) => {
commit(types.VIEW_DIFF_FILE, fileHash); commit(types.VIEW_DIFF_FILE, fileHash);
}; };
export const setFileByFile = ({ commit }, { fileByFile }) => { export const setFileByFile = ({ state, commit }, { fileByFile }) => {
const fileViewMode = fileByFile ? DIFF_VIEW_FILE_BY_FILE : DIFF_VIEW_ALL_FILES; const fileViewMode = fileByFile ? DIFF_VIEW_FILE_BY_FILE : DIFF_VIEW_ALL_FILES;
commit(types.SET_FILE_BY_FILE, fileByFile); commit(types.SET_FILE_BY_FILE, fileByFile);
Cookies.set(DIFF_FILE_BY_FILE_COOKIE_NAME, fileViewMode); Cookies.set(DIFF_FILE_BY_FILE_COOKIE_NAME, fileViewMode);
return axios
.put(state.endpointUpdateUser, {
view_diffs_file_by_file: fileByFile,
})
.then(() => {
// https://gitlab.com/gitlab-org/gitlab/-/issues/326961
// We can't even do a simple console warning here because
// the pipeline will fail. However, the issue above will
// eventually handle errors appropriately.
// console.warn('Saving the file-by-fil user preference failed.');
});
}; };
export function reviewFile({ commit, state }, { file, reviewed = true }) { export function reviewFile({ commit, state }, { file, reviewed = true }) {
......
---
title: Sync single-file mode user preference when changed from the MR cog menu checkbox
merge_request: 55931
author:
type: changed
...@@ -1507,19 +1507,42 @@ describe('DiffsStoreActions', () => { ...@@ -1507,19 +1507,42 @@ describe('DiffsStoreActions', () => {
}); });
describe('setFileByFile', () => { describe('setFileByFile', () => {
const updateUserEndpoint = 'user/prefs';
let putSpy;
let mock;
beforeEach(() => {
mock = new MockAdapter(axios);
putSpy = jest.spyOn(axios, 'put');
mock.onPut(updateUserEndpoint).reply(200, {});
});
afterEach(() => {
mock.restore();
});
it.each` it.each`
value value
${true} ${true}
${false} ${false}
`('commits SET_FILE_BY_FILE with the new value $value', ({ value }) => { `(
return testAction( 'commits SET_FILE_BY_FILE and persists the File-by-File user preference with the new value $value',
async ({ value }) => {
await testAction(
setFileByFile, setFileByFile,
{ fileByFile: value }, { fileByFile: value },
{ viewDiffsFileByFile: null }, {
viewDiffsFileByFile: null,
endpointUpdateUser: updateUserEndpoint,
},
[{ type: types.SET_FILE_BY_FILE, payload: value }], [{ type: types.SET_FILE_BY_FILE, payload: value }],
[], [],
); );
});
expect(putSpy).toHaveBeenCalledWith(updateUserEndpoint, { view_diffs_file_by_file: value });
},
);
}); });
describe('reviewFile', () => { describe('reviewFile', () => {
......
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