Commit dc510fbf authored by Tom Quirk's avatar Tom Quirk

Call scrollIntoView for note on next tick

Also, add a `url` source for active discussion in Apollo
parent feaae37e
...@@ -66,12 +66,16 @@ export default { ...@@ -66,12 +66,16 @@ export default {
if (this.discussion.resolved && !this.resolvedDiscussionsExpanded) { if (this.discussion.resolved && !this.resolvedDiscussionsExpanded) {
return; return;
} }
this.$nextTick(() => {
// We watch any changes to the active discussion from the design pins and scroll to this discussion if it exists // We watch any changes to the active discussion from the design pins and scroll to this discussion if it exists
// We don't want scrollIntoView to be triggered from the discussion click itself // We don't want scrollIntoView to be triggered from the discussion click itself
if ( if (
this.$el && this.$el &&
activeDiscussionId && activeDiscussionId &&
data.activeDiscussion.source === ACTIVE_DISCUSSION_SOURCE_TYPES.pin && [ACTIVE_DISCUSSION_SOURCE_TYPES.pin, ACTIVE_DISCUSSION_SOURCE_TYPES.url].includes(
data.activeDiscussion.source,
) &&
activeDiscussionId === this.discussion.notes[0].id activeDiscussionId === this.discussion.notes[0].id
) { ) {
this.$el.scrollIntoView({ this.$el.scrollIntoView({
...@@ -79,6 +83,7 @@ export default { ...@@ -79,6 +83,7 @@ export default {
inline: 'start', inline: 'start',
}); });
} }
});
}, },
}, },
}, },
......
...@@ -60,9 +60,11 @@ export default { ...@@ -60,9 +60,11 @@ export default {
}, },
}, },
mounted() { mounted() {
this.$nextTick(() => {
if (this.isNoteLinked) { if (this.isNoteLinked) {
this.$el.scrollIntoView({ behavior: 'smooth', inline: 'start' }); this.$el.scrollIntoView({ behavior: 'smooth', inline: 'start' });
} }
});
}, },
methods: { methods: {
hideForm() { hideForm() {
......
...@@ -11,6 +11,7 @@ export const VALID_DATA_TRANSFER_TYPE = 'Files'; ...@@ -11,6 +11,7 @@ export const VALID_DATA_TRANSFER_TYPE = 'Files';
export const ACTIVE_DISCUSSION_SOURCE_TYPES = { export const ACTIVE_DISCUSSION_SOURCE_TYPES = {
pin: 'pin', pin: 'pin',
discussion: 'discussion', discussion: 'discussion',
url: 'url',
}; };
export const DESIGN_DETAIL_LAYOUT_CLASSLIST = ['design-detail-layout', 'overflow-hidden', 'm-0']; export const DESIGN_DETAIL_LAYOUT_CLASSLIST = ['design-detail-layout', 'overflow-hidden', 'm-0'];
...@@ -271,19 +271,19 @@ export default { ...@@ -271,19 +271,19 @@ export default {
this.isLatestVersion, this.isLatestVersion,
); );
}, },
updateActiveDiscussion(id) { updateActiveDiscussion(id, source = ACTIVE_DISCUSSION_SOURCE_TYPES.discussion) {
this.$apollo.mutate({ this.$apollo.mutate({
mutation: updateActiveDiscussionMutation, mutation: updateActiveDiscussionMutation,
variables: { variables: {
id, id,
source: ACTIVE_DISCUSSION_SOURCE_TYPES.discussion, source,
}, },
}); });
}, },
updateActiveDiscussionFromUrl() { updateActiveDiscussionFromUrl() {
const noteId = parseDesignRouteHash(this.$route.hash); const noteId = parseDesignRouteHash(this.$route.hash);
const diffNoteGid = noteId ? toDiffNoteGid(noteId) : undefined; const diffNoteGid = noteId ? toDiffNoteGid(noteId) : undefined;
return this.updateActiveDiscussion(diffNoteGid); return this.updateActiveDiscussion(diffNoteGid, ACTIVE_DISCUSSION_SOURCE_TYPES.url);
}, },
toggleResolvedComments() { toggleResolvedComments() {
this.resolvedDiscussionsExpanded = !this.resolvedDiscussionsExpanded; this.resolvedDiscussionsExpanded = !this.resolvedDiscussionsExpanded;
......
...@@ -91,8 +91,10 @@ describe('Design note component', () => { ...@@ -91,8 +91,10 @@ describe('Design note component', () => {
note, note,
}); });
return wrapper.vm.$nextTick().then(() => {
expect(scrollIntoViewMock).toHaveBeenCalled(); expect(scrollIntoViewMock).toHaveBeenCalled();
}); });
});
it('should not render edit icon when user does not have a permission', () => { it('should not render edit icon when user does not have a permission', () => {
createComponent({ createComponent({
......
...@@ -315,7 +315,7 @@ describe('Design management design index page', () => { ...@@ -315,7 +315,7 @@ describe('Design management design index page', () => {
expect(mutate).toHaveBeenCalledTimes(1); expect(mutate).toHaveBeenCalledTimes(1);
expect(mutate).toHaveBeenCalledWith({ expect(mutate).toHaveBeenCalledWith({
mutation: updateActiveDiscussion, mutation: updateActiveDiscussion,
variables: { id: 'gid://gitlab/DiffNote/123', source: 'discussion' }, variables: { id: 'gid://gitlab/DiffNote/123', source: 'url' },
}); });
}); });
}); });
......
...@@ -579,7 +579,9 @@ describe('Design management index page', () => { ...@@ -579,7 +579,9 @@ describe('Design management index page', () => {
}); });
createComponent(true); createComponent(true);
return wrapper.vm.$nextTick().then(() => {
expect(scrollIntoViewMock).toHaveBeenCalled(); expect(scrollIntoViewMock).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