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 = {
...
@@ -14,15 +14,11 @@ type ProfileModalProps = {
export
default
function
ProfileModal
({
eventBus
,
config
}:
ProfileModalProps
)
{
export
default
function
ProfileModal
({
eventBus
,
config
}:
ProfileModalProps
)
{
const
[
isHidden
,
setIsHidden
]
=
useState
(
true
);
const
[
isHidden
,
setIsHidden
]
=
useState
(
true
);
const
emitterRef
=
useRef
<
Emitter
|
null
>
(
null
);
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
(()
=>
{
useEffect
(()
=>
{
const
emitter
=
eventBus
.
createEmitter
();
const
emitter
=
eventBus
.
createEmitter
();
emitter
.
subscribe
(
'openProfile'
,
()
=>
{
emitter
.
subscribe
(
'openProfile'
,
()
=>
{
setIsHidden
(
false
);
setIsHidden
(
false
);
setHasOpened
(
true
);
});
});
emitterRef
.
current
=
emitter
;
emitterRef
.
current
=
emitter
;
...
@@ -36,16 +32,13 @@ export default function ProfileModal({ eventBus, config }: ProfileModalProps) {
...
@@ -36,16 +32,13 @@ export default function ProfileModal({ eventBus, config }: ProfileModalProps) {
emitterRef
.
current
?.
publish
(
'closeProfile'
);
emitterRef
.
current
?.
publish
(
'closeProfile'
);
};
};
if
(
!
hasOpened
)
{
if
(
isHidden
)
{
return
null
;
return
null
;
}
}
return
(
return
(
<
div
<
div
className=
{
classnames
(
className=
"fixed z-max top-0 left-0 right-0 bottom-0 p-3 bg-black/50"
'fixed z-max top-0 left-0 right-0 bottom-0 p-3 bg-black/50'
,
{
hidden
:
isHidden
}
)
}
data
-
testid=
"profile-outer"
data
-
testid=
"profile-outer"
>
>
<
div
className=
"relative w-full h-full"
data
-
testid=
"profile-inner"
>
<
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', () => {
...
@@ -34,7 +34,7 @@ describe('ProfileModal', () => {
components
.
forEach
(
component
=>
component
.
unmount
());
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
();
const
wrapper
=
createComponent
();
assert
.
equal
(
wrapper
.
find
(
outerSelector
).
length
,
0
);
assert
.
equal
(
wrapper
.
find
(
outerSelector
).
length
,
0
);
});
});
...
@@ -45,29 +45,25 @@ describe('ProfileModal', () => {
...
@@ -45,29 +45,25 @@ describe('ProfileModal', () => {
emitter
.
publish
(
'openProfile'
);
emitter
.
publish
(
'openProfile'
);
wrapper
.
update
();
wrapper
.
update
();
const
outer
=
wrapper
.
find
(
outerSelector
);
assert
.
isTrue
(
wrapper
.
find
(
outerSelector
).
exists
());
assert
.
isFalse
(
outer
.
hasClass
(
'hidden'
));
const
iframe
=
wrapper
.
find
(
'iframe'
);
const
iframe
=
wrapper
.
find
(
'iframe'
);
assert
.
equal
(
iframe
.
prop
(
'src'
),
profileURL
);
assert
.
equal
(
iframe
.
prop
(
'src'
),
profileURL
);
});
});
it
(
'hides modal on closing'
,
()
=>
{
it
(
"removes the modal's content on closing"
,
()
=>
{
const
wrapper
=
createComponent
();
const
wrapper
=
createComponent
();
emitter
.
publish
(
'openProfile'
);
emitter
.
publish
(
'openProfile'
);
wrapper
.
update
();
wrapper
.
update
();
let
outer
=
wrapper
.
find
(
outerSelector
);
assert
.
isTrue
(
wrapper
.
find
(
outerSelector
).
exists
());
assert
.
isFalse
(
outer
.
hasClass
(
'hidden'
));
act
(()
=>
{
act
(()
=>
{
wrapper
.
find
(
'IconButton'
).
prop
(
'onClick'
)();
wrapper
.
find
(
'IconButton'
).
prop
(
'onClick'
)();
});
});
wrapper
.
update
();
wrapper
.
update
();
outer
=
wrapper
.
find
(
outerSelector
);
assert
.
isFalse
(
wrapper
.
find
(
outerSelector
).
exists
());
assert
.
isTrue
(
outer
.
hasClass
(
'hidden'
));
});
});
});
});
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