Commit 5caa1ce1 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'ph/fileByFileNoteLinking' into 'master'

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

See merge request gitlab-org/gitlab!37104
parents 1399d4a0 cb25a605
......@@ -235,9 +235,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,
......@@ -254,6 +256,10 @@ export const assignDiscussionsToDiff = (
});
});
if (isNoteLink) {
dispatch('setCurrentDiffFileIdFromNote', id.split('_').pop());
}
Vue.nextTick(() => {
eventHub.$emit('scrollToDiscussion');
});
......@@ -738,8 +744,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