Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
7dcf2744
Commit
7dcf2744
authored
Feb 18, 2021
by
Thomas Randolph
Committed by
Phil Hughes
Feb 18, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Attach user popovers to DOM nodes added after the initial DOM query
parent
2595e7a6
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
5 deletions
+53
-5
app/assets/javascripts/user_popovers.js
app/assets/javascripts/user_popovers.js
+24
-2
changelogs/unreleased/tor-defect-missing-popovers-from-async-DOM.yml
...unreleased/tor-defect-missing-popovers-from-async-DOM.yml
+6
-0
spec/frontend/user_popovers_spec.js
spec/frontend/user_popovers_spec.js
+23
-3
No files found.
app/assets/javascripts/user_popovers.js
View file @
7dcf2744
...
...
@@ -59,11 +59,33 @@ const populateUserInfo = (user) => {
};
const
initializedPopovers
=
new
Map
();
let
domObservedForChanges
=
false
;
export
default
(
elements
=
document
.
querySelectorAll
(
'
.js-user-link
'
))
=>
{
const
addPopoversToModifiedTree
=
new
MutationObserver
(()
=>
{
const
userLinks
=
document
?.
querySelectorAll
(
'
.js-user-link, .gfm-project_member
'
);
if
(
userLinks
)
{
addPopovers
(
userLinks
);
/* eslint-disable-line no-use-before-define */
}
});
function
observeBody
()
{
if
(
!
domObservedForChanges
)
{
addPopoversToModifiedTree
.
observe
(
document
.
body
,
{
subtree
:
true
,
childList
:
true
,
});
domObservedForChanges
=
true
;
}
}
export
default
function
addPopovers
(
elements
=
document
.
querySelectorAll
(
'
.js-user-link
'
))
{
const
userLinks
=
Array
.
from
(
elements
);
const
UserPopoverComponent
=
Vue
.
extend
(
UserPopover
);
observeBody
();
return
userLinks
.
filter
(({
dataset
})
=>
dataset
.
user
||
dataset
.
userId
)
.
map
((
el
)
=>
{
...
...
@@ -105,4 +127,4 @@ export default (elements = document.querySelectorAll('.js-user-link')) => {
return
renderedPopover
;
});
}
;
}
changelogs/unreleased/tor-defect-missing-popovers-from-async-DOM.yml
0 → 100644
View file @
7dcf2744
---
title
:
React to new DOM nodes being added to the page to bind the user information
popover to them
merge_request
:
54411
author
:
type
:
fixed
spec/frontend/user_popovers_spec.js
View file @
7dcf2744
...
...
@@ -6,6 +6,19 @@ describe('User Popovers', () => {
preloadFixtures
(
fixtureTemplate
);
const
selector
=
'
.js-user-link, .gfm-project_member
'
;
const
findFixtureLinks
=
()
=>
{
return
Array
.
from
(
document
.
querySelectorAll
(
selector
)).
filter
(
({
dataset
})
=>
dataset
.
user
||
dataset
.
userId
,
);
};
const
createUserLink
=
()
=>
{
const
link
=
document
.
createElement
(
'
a
'
);
link
.
classList
.
add
(
'
js-user-link
'
);
link
.
setAttribute
(
'
data-user
'
,
'
1
'
);
return
link
;
};
const
dummyUser
=
{
name
:
'
root
'
};
const
dummyUserStatus
=
{
message
:
'
active
'
};
...
...
@@ -37,13 +50,20 @@ describe('User Popovers', () => {
});
it
(
'
initializes a popover for each user link with a user id
'
,
()
=>
{
const
linksWithUsers
=
Array
.
from
(
document
.
querySelectorAll
(
selector
)).
filter
(
({
dataset
})
=>
dataset
.
user
||
dataset
.
userId
,
);
const
linksWithUsers
=
findFixtureLinks
();
expect
(
linksWithUsers
.
length
).
toBe
(
popovers
.
length
);
});
it
(
'
adds popovers to user links added to the DOM tree after the initial call
'
,
async
()
=>
{
document
.
body
.
appendChild
(
createUserLink
());
document
.
body
.
appendChild
(
createUserLink
());
const
linksWithUsers
=
findFixtureLinks
();
expect
(
linksWithUsers
.
length
).
toBe
(
popovers
.
length
+
2
);
});
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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment