Commit 838765c5 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch '28985-links-to-notes-in-collapsed-discussions-dont-work' into 'master'

Fixes links to notes in collapsed discussions

See merge request gitlab-org/gitlab!20148
parents 9557703f c7433c81
...@@ -122,6 +122,8 @@ export default { ...@@ -122,6 +122,8 @@ export default {
this.toggleAward({ awardName, noteId }); this.toggleAward({ awardName, noteId });
}); });
} }
window.addEventListener('hashchange', this.handleHashChanged);
}, },
updated() { updated() {
this.$nextTick(() => { this.$nextTick(() => {
...@@ -131,6 +133,7 @@ export default { ...@@ -131,6 +133,7 @@ export default {
}, },
beforeDestroy() { beforeDestroy() {
this.stopPolling(); this.stopPolling();
window.removeEventListener('hashchange', this.handleHashChanged);
}, },
methods: { methods: {
...mapActions([ ...mapActions([
...@@ -138,7 +141,6 @@ export default { ...@@ -138,7 +141,6 @@ export default {
'fetchDiscussions', 'fetchDiscussions',
'poll', 'poll',
'toggleAward', 'toggleAward',
'scrollToNoteIfNeeded',
'setNotesData', 'setNotesData',
'setNoteableData', 'setNoteableData',
'setUserData', 'setUserData',
...@@ -151,6 +153,13 @@ export default { ...@@ -151,6 +153,13 @@ export default {
'convertToDiscussion', 'convertToDiscussion',
'stopPolling', 'stopPolling',
]), ]),
handleHashChanged() {
const noteId = this.checkLocationHash();
if (noteId) {
this.setTargetNoteHash(getLocationHash());
}
},
fetchNotes() { fetchNotes() {
if (this.isFetching) return null; if (this.isFetching) return null;
...@@ -194,6 +203,8 @@ export default { ...@@ -194,6 +203,8 @@ export default {
this.expandDiscussion({ discussionId: discussion.id }); this.expandDiscussion({ discussionId: discussion.id });
} }
} }
return noteId;
}, },
startReplying(discussionId) { startReplying(discussionId) {
return this.convertToDiscussion(discussionId) return this.convertToDiscussion(discussionId)
......
---
title: Fix expanding collapsed threads when reference link clicked
merge_request: 20148
author:
type: fixed
...@@ -10,6 +10,7 @@ import '~/behaviors/markdown/render_gfm'; ...@@ -10,6 +10,7 @@ import '~/behaviors/markdown/render_gfm';
import { setTestTimeout } from 'helpers/timeout'; import { setTestTimeout } from 'helpers/timeout';
// TODO: use generated fixture (https://gitlab.com/gitlab-org/gitlab-foss/issues/62491) // TODO: use generated fixture (https://gitlab.com/gitlab-org/gitlab-foss/issues/62491)
import * as mockData from '../../notes/mock_data'; import * as mockData from '../../notes/mock_data';
import * as urlUtility from '~/lib/utils/url_utility';
setTestTimeout(1000); setTestTimeout(1000);
...@@ -54,7 +55,9 @@ describe('note_app', () => { ...@@ -54,7 +55,9 @@ describe('note_app', () => {
components: { components: {
NotesApp, NotesApp,
}, },
template: '<div class="js-vue-notes-event"><notes-app v-bind="$attrs" /></div>', template: `<div class="js-vue-notes-event">
<notes-app ref="notesApp" v-bind="$attrs" />
</div>`,
}, },
{ {
attachToDocument: true, attachToDocument: true,
...@@ -313,4 +316,23 @@ describe('note_app', () => { ...@@ -313,4 +316,23 @@ describe('note_app', () => {
}); });
}); });
}); });
describe('mounted', () => {
beforeEach(() => {
axiosMock.onAny().reply(mockData.getIndividualNoteResponse);
wrapper = mountComponent();
return waitForDiscussionsRequest();
});
it('should listen hashchange event', () => {
const notesApp = wrapper.find(NotesApp);
const hash = 'some dummy hash';
jest.spyOn(urlUtility, 'getLocationHash').mockReturnValueOnce(hash);
const setTargetNoteHash = jest.spyOn(notesApp.vm, 'setTargetNoteHash');
window.dispatchEvent(new Event('hashchange'), hash);
expect(setTargetNoteHash).toHaveBeenCalled();
});
});
}); });
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