Commit 2eae06f8 authored by Mike Greiling's avatar Mike Greiling

Merge branch 'tor/feature/persist-file-by-file/api-save' into 'master'

Sync single-file mode user preference

See merge request gitlab-org/gitlab!55931
parents 1a66c29d 1b04fb50
......@@ -793,10 +793,22 @@ export const navigateToDiffFileIndex = ({ commit, state }, index) => {
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;
commit(types.SET_FILE_BY_FILE, fileByFile);
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 }) {
......
---
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', () => {
});
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`
value
${true}
${false}
`('commits SET_FILE_BY_FILE with the new value $value', ({ value }) => {
return testAction(
setFileByFile,
{ fileByFile: value },
{ viewDiffsFileByFile: null },
[{ type: types.SET_FILE_BY_FILE, payload: value }],
[],
);
});
`(
'commits SET_FILE_BY_FILE and persists the File-by-File user preference with the new value $value',
async ({ value }) => {
await testAction(
setFileByFile,
{ fileByFile: value },
{
viewDiffsFileByFile: null,
endpointUpdateUser: updateUserEndpoint,
},
[{ type: types.SET_FILE_BY_FILE, payload: value }],
[],
);
expect(putSpy).toHaveBeenCalledWith(updateUserEndpoint, { view_diffs_file_by_file: value });
},
);
});
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