Commit cb25a605 authored by Phil Hughes's avatar Phil Hughes

Fixed issue with discussion not linking to in file-by-file

This was caused by the discussions endpoint being
slower than the diffs endpoint which caused the correct
diff file ID not to be set
parent f724bf57
......@@ -233,9 +233,11 @@ export const setHighlightedRow = ({ commit }, lineCode) => {
// This is adding line discussions to the actual lines in the diff tree
// once for parallel and once for inline mode
export const assignDiscussionsToDiff = (
{ commit, state, rootState },
{ commit, state, rootState, dispatch },
discussions = rootState.notes.discussions,
) => {
const id = window?.location?.hash;
const isNoteLink = id.indexOf('#note') === 0;
const diffPositionByLineCode = getDiffPositionByLineCode(
state.diffFiles,
state.useSingleDiffStyle,
......@@ -252,6 +254,10 @@ export const assignDiscussionsToDiff = (
});
});
if (isNoteLink) {
dispatch('setCurrentDiffFileIdFromNote', id.split('_').pop());
}
Vue.nextTick(() => {
eventHub.$emit('scrollToDiscussion');
});
......@@ -736,8 +742,11 @@ export function moveToNeighboringCommit({ dispatch, state }, { direction }) {
}
export const setCurrentDiffFileIdFromNote = ({ commit, rootGetters }, noteId) => {
const fileHash = rootGetters.getDiscussion(rootGetters.notesById[noteId].discussion_id).diff_file
.file_hash;
const note = rootGetters.notesById[noteId];
if (!note) return;
const fileHash = rootGetters.getDiscussion(note.discussion_id).diff_file.file_hash;
commit(types.UPDATE_CURRENT_DIFF_FILE_ID, fileHash);
};
......
......@@ -485,6 +485,10 @@ describe('DiffsStoreActions', () => {
});
describe('assignDiscussionsToDiff', () => {
afterEach(() => {
window.location.hash = '';
});
it('should merge discussions into diffs', done => {
window.location.hash = 'ABC_123';
......@@ -578,6 +582,19 @@ describe('DiffsStoreActions', () => {
done,
);
});
it('dispatches setCurrentDiffFileIdFromNote with note ID', done => {
window.location.hash = 'note_123';
testAction(
assignDiscussionsToDiff,
[],
{ diffFiles: [], useSingleDiffStyle: true },
[],
[{ type: 'setCurrentDiffFileIdFromNote', payload: '123' }],
done,
);
});
});
describe('removeDiscussionsFromDiff', () => {
......
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