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,19 +66,24 @@ export default { ...@@ -66,19 +66,24 @@ export default {
if (this.discussion.resolved && !this.resolvedDiscussionsExpanded) { if (this.discussion.resolved && !this.resolvedDiscussionsExpanded) {
return; return;
} }
// 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 this.$nextTick(() => {
if ( // We watch any changes to the active discussion from the design pins and scroll to this discussion if it exists
this.$el && // We don't want scrollIntoView to be triggered from the discussion click itself
activeDiscussionId && if (
data.activeDiscussion.source === ACTIVE_DISCUSSION_SOURCE_TYPES.pin && this.$el &&
activeDiscussionId === this.discussion.notes[0].id activeDiscussionId &&
) { [ACTIVE_DISCUSSION_SOURCE_TYPES.pin, ACTIVE_DISCUSSION_SOURCE_TYPES.url].includes(
this.$el.scrollIntoView({ data.activeDiscussion.source,
behavior: 'smooth', ) &&
inline: 'start', activeDiscussionId === this.discussion.notes[0].id
}); ) {
} this.$el.scrollIntoView({
behavior: 'smooth',
inline: 'start',
});
}
});
}, },
}, },
}, },
......
...@@ -60,9 +60,11 @@ export default { ...@@ -60,9 +60,11 @@ export default {
}, },
}, },
mounted() { mounted() {
if (this.isNoteLinked) { this.$nextTick(() => {
this.$el.scrollIntoView({ behavior: 'smooth', inline: 'start' }); if (this.isNoteLinked) {
} 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,7 +91,9 @@ describe('Design note component', () => { ...@@ -91,7 +91,9 @@ describe('Design note component', () => {
note, note,
}); });
expect(scrollIntoViewMock).toHaveBeenCalled(); return wrapper.vm.$nextTick().then(() => {
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', () => {
......
...@@ -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);
expect(scrollIntoViewMock).toHaveBeenCalled(); return wrapper.vm.$nextTick().then(() => {
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