Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
adc5bad3
Commit
adc5bad3
authored
Feb 23, 2023
by
Alejandro Celaya
Committed by
Alejandro Celaya
Feb 24, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not render profile modal contents when the modal is closed
parent
f13d9fd3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
18 deletions
+7
-18
ProfileModal.tsx
src/annotator/components/ProfileModal.tsx
+2
-9
ProfileModal-test.js
src/annotator/components/test/ProfileModal-test.js
+5
-9
No files found.
src/annotator/components/ProfileModal.tsx
View file @
adc5bad3
...
...
@@ -14,15 +14,11 @@ type ProfileModalProps = {
export
default
function
ProfileModal
({
eventBus
,
config
}:
ProfileModalProps
)
{
const
[
isHidden
,
setIsHidden
]
=
useState
(
true
);
const
emitterRef
=
useRef
<
Emitter
|
null
>
(
null
);
// Used only to track when was this modal first open, delaying the iframe to
// be loaded until strictly necessary.
const
[
hasOpened
,
setHasOpened
]
=
useState
(
false
);
useEffect
(()
=>
{
const
emitter
=
eventBus
.
createEmitter
();
emitter
.
subscribe
(
'openProfile'
,
()
=>
{
setIsHidden
(
false
);
setHasOpened
(
true
);
});
emitterRef
.
current
=
emitter
;
...
...
@@ -36,16 +32,13 @@ export default function ProfileModal({ eventBus, config }: ProfileModalProps) {
emitterRef
.
current
?.
publish
(
'closeProfile'
);
};
if
(
!
hasOpened
)
{
if
(
isHidden
)
{
return
null
;
}
return
(
<
div
className=
{
classnames
(
'fixed z-max top-0 left-0 right-0 bottom-0 p-3 bg-black/50'
,
{
hidden
:
isHidden
}
)
}
className=
"fixed z-max top-0 left-0 right-0 bottom-0 p-3 bg-black/50"
data
-
testid=
"profile-outer"
>
<
div
className=
"relative w-full h-full"
data
-
testid=
"profile-inner"
>
...
...
src/annotator/components/test/ProfileModal-test.js
View file @
adc5bad3
...
...
@@ -34,7 +34,7 @@ describe('ProfileModal', () => {
components
.
forEach
(
component
=>
component
.
unmount
());
});
it
(
'does not render anything
before the modal has been opened at least once
'
,
()
=>
{
it
(
'does not render anything
while the modal is closed
'
,
()
=>
{
const
wrapper
=
createComponent
();
assert
.
equal
(
wrapper
.
find
(
outerSelector
).
length
,
0
);
});
...
...
@@ -45,29 +45,25 @@ describe('ProfileModal', () => {
emitter
.
publish
(
'openProfile'
);
wrapper
.
update
();
const
outer
=
wrapper
.
find
(
outerSelector
);
assert
.
isFalse
(
outer
.
hasClass
(
'hidden'
));
assert
.
isTrue
(
wrapper
.
find
(
outerSelector
).
exists
());
const
iframe
=
wrapper
.
find
(
'iframe'
);
assert
.
equal
(
iframe
.
prop
(
'src'
),
profileURL
);
});
it
(
'hides modal on closing'
,
()
=>
{
it
(
"removes the modal's content on closing"
,
()
=>
{
const
wrapper
=
createComponent
();
emitter
.
publish
(
'openProfile'
);
wrapper
.
update
();
let
outer
=
wrapper
.
find
(
outerSelector
);
assert
.
isFalse
(
outer
.
hasClass
(
'hidden'
));
assert
.
isTrue
(
wrapper
.
find
(
outerSelector
).
exists
());
act
(()
=>
{
wrapper
.
find
(
'IconButton'
).
prop
(
'onClick'
)();
});
wrapper
.
update
();
outer
=
wrapper
.
find
(
outerSelector
);
assert
.
isTrue
(
outer
.
hasClass
(
'hidden'
));
assert
.
isFalse
(
wrapper
.
find
(
outerSelector
).
exists
());
});
});
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