Commit 8cdfa402 authored by Mark Florian's avatar Mark Florian

Merge branch 'fix-duplicated-user-popover' into 'master'

Fix duplicated user popovers

See merge request gitlab-org/gitlab!24405
parents 315f75ae db030285
...@@ -54,11 +54,17 @@ const populateUserInfo = user => { ...@@ -54,11 +54,17 @@ const populateUserInfo = user => {
); );
}; };
const initializedPopovers = new Map();
export default (elements = document.querySelectorAll('.js-user-link')) => { export default (elements = document.querySelectorAll('.js-user-link')) => {
const userLinks = Array.from(elements); const userLinks = Array.from(elements);
const UserPopoverComponent = Vue.extend(UserPopover);
return userLinks.map(el => { return userLinks.map(el => {
const UserPopoverComponent = Vue.extend(UserPopover); if (initializedPopovers.has(el)) {
return initializedPopovers.get(el);
}
const user = { const user = {
location: null, location: null,
bio: null, bio: null,
...@@ -73,6 +79,8 @@ export default (elements = document.querySelectorAll('.js-user-link')) => { ...@@ -73,6 +79,8 @@ export default (elements = document.querySelectorAll('.js-user-link')) => {
}, },
}); });
initializedPopovers.set(el, renderedPopover);
renderedPopover.$mount(); renderedPopover.$mount();
el.addEventListener('mouseenter', ({ target }) => { el.addEventListener('mouseenter', ({ target }) => {
......
---
title: Fix duplicated user popovers
merge_request: 24405
author:
type: fixed
...@@ -38,6 +38,13 @@ describe('User Popovers', () => { ...@@ -38,6 +38,13 @@ describe('User Popovers', () => {
expect(document.querySelectorAll(selector).length).toBe(popovers.length); expect(document.querySelectorAll(selector).length).toBe(popovers.length);
}); });
it('does not initialize the user popovers twice for the same element', () => {
const newPopovers = initUserPopovers(document.querySelectorAll(selector));
const samePopovers = popovers.every((popover, index) => newPopovers[index] === popover);
expect(samePopovers).toBe(true);
});
describe('when user link emits mouseenter event', () => { describe('when user link emits mouseenter event', () => {
let userLink; let userLink;
......
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