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
be929ed2
Commit
be929ed2
authored
Mar 25, 2024
by
Alejandro Celaya
Committed by
Alejandro Celaya
Apr 02, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix mouse events in pending updates notification
parent
9eea0434
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
65 deletions
+49
-65
PendingUpdatesNotification.tsx
src/sidebar/components/PendingUpdatesNotification.tsx
+36
-16
SidebarView.tsx
src/sidebar/components/SidebarView.tsx
+13
-13
PendingUpdatesNotification-test.js
...idebar/components/test/PendingUpdatesNotification-test.js
+0
-36
No files found.
src/sidebar/components/PendingUpdatesNotification.tsx
View file @
be929ed2
import
{
Button
,
DownloadIcon
}
from
'@hypothesis/frontend-shared'
;
import
classnames
from
'classnames'
;
import
type
{
ComponentChildren
}
from
'preact'
;
import
{
useCallback
,
useEffect
,
useRef
,
useState
}
from
'preact/hooks'
;
import
{
pluralize
}
from
'../../shared/pluralize'
;
...
...
@@ -17,6 +18,27 @@ export type PendingUpdatesNotificationProps = {
clearTimeout_
?:
typeof
clearTimeout
;
};
type
HideableBlockProps
=
{
hidden
:
boolean
;
children
:
ComponentChildren
;
};
/**
* A component that can be hidden but will be unconditionally displayed when the
* group it belongs to is focused or hovered
*/
function
HideableBlock
({
hidden
,
children
}:
HideableBlockProps
)
{
return
(
<
span
className=
{
classnames
(
'group-hover:inline group-focus:inline'
,
{
hidden
,
})
}
>
{
children
}
</
span
>
);
}
const
collapseDelay
=
5000
;
function
PendingUpdatesNotification
({
...
...
@@ -66,25 +88,23 @@ function PendingUpdatesNotification({
classes=
{
classnames
(
'flex gap-1.5 items-center py-1 px-2'
,
'rounded shadow-lg bg-gray-900 text-white'
,
'group focus-visible-ring'
,
)
}
onMouseEnter=
{
()
=>
setCollapsed
(
false
)
}
onFocus=
{
()
=>
setCollapsed
(
false
)
}
onMouseLeave=
{
()
=>
!
timeout
.
current
&&
setCollapsed
(
true
)
}
onBlur=
{
()
=>
!
timeout
.
current
&&
setCollapsed
(
true
)
}
>
<
DownloadIcon
className=
"w-em h-em opacity-80"
/>
{
!
collapsed
&&
(
<
span
data
-
testid=
"full-notification"
className=
"whitespace-nowrap"
>
Load
<
span
className=
"font-bold"
>
{
pendingUpdateCount
}
</
span
>
{
' '
}
{
pluralize
(
pendingUpdateCount
,
'update'
,
'updates'
)
}{
' '
}
<
span
className=
"sr-only"
>
by pressing l
</
span
>
</
span
>
)
}
{
collapsed
&&
(
<
span
data
-
testid=
"collapsed-notification"
className=
"font-bold"
>
{
pendingUpdateCount
}
</
span
>
)
}
<
div
data
-
testid=
{
collapsed
?
'collapsed-notification'
:
'full-notification'
}
className=
"flex gap-1"
>
<
HideableBlock
hidden=
{
collapsed
}
>
Load
</
HideableBlock
>
<
span
className=
"font-bold"
>
{
pendingUpdateCount
}
</
span
>
<
HideableBlock
hidden=
{
collapsed
}
>
{
pluralize
(
pendingUpdateCount
,
'update'
,
'updates'
)
}
</
HideableBlock
>
</
div
>
<
span
className=
"sr-only"
>
by pressing l
</
span
>
</
Button
>
</
div
>
);
...
...
src/sidebar/components/SidebarView.tsx
View file @
be929ed2
...
...
@@ -133,19 +133,6 @@ function SidebarView({
return
(
<
div
className=
"relative"
>
<
h2
className=
"sr-only"
>
Annotations
</
h2
>
{
showFilterControls
&&
<
FilterControls
withCardContainer
/>
}
<
LoginPromptPanel
onLogin=
{
onLogin
}
onSignUp=
{
onSignUp
}
/>
{
hasDirectLinkedAnnotationError
&&
(
<
SidebarContentError
errorType=
"annotation"
onLoginRequest=
{
onLogin
}
showClearSelection=
{
true
}
/>
)
}
{
hasDirectLinkedGroupError
&&
(
<
SidebarContentError
errorType=
"group"
onLoginRequest=
{
onLogin
}
/>
)
}
{
!
hasContentError
&&
<
SidebarTabs
isLoading=
{
isLoading
}
/>
}
{
pendingUpdatesNotification
&&
(
<
div
className=
{
classnames
(
...
...
@@ -159,6 +146,19 @@ function SidebarView({
<
PendingUpdatesNotification
/>
</
div
>
)
}
{
showFilterControls
&&
<
FilterControls
withCardContainer
/>
}
<
LoginPromptPanel
onLogin=
{
onLogin
}
onSignUp=
{
onSignUp
}
/>
{
hasDirectLinkedAnnotationError
&&
(
<
SidebarContentError
errorType=
"annotation"
onLoginRequest=
{
onLogin
}
showClearSelection=
{
true
}
/>
)
}
{
hasDirectLinkedGroupError
&&
(
<
SidebarContentError
errorType=
"group"
onLoginRequest=
{
onLogin
}
/>
)
}
{
!
hasContentError
&&
<
SidebarTabs
isLoading=
{
isLoading
}
/>
}
{
showLoggedOutMessage
&&
<
LoggedOutMessage
onLogin=
{
onLogin
}
/>
}
</
div
>
);
...
...
src/sidebar/components/test/PendingUpdatesNotification-test.js
View file @
be929ed2
...
...
@@ -134,40 +134,4 @@ describe('PendingUpdatesNotification', () => {
}
});
});
[
'onMouseLeave'
,
'onBlur'
].
forEach
(
handler
=>
{
it
(
'collapses notification when mouse or focus leaves button'
,
()
=>
{
const
wrapper
=
createComponent
();
assert
.
isFalse
(
notificationIsCollapsed
(
wrapper
));
wrapper
.
find
(
'Button'
).
prop
(
handler
)();
wrapper
.
update
();
assert
.
isTrue
(
notificationIsCollapsed
(
wrapper
));
});
it
(
'does not collapse notification when mouse or focus leaves button if timeout is in progress'
,
()
=>
{
fakeSetTimeout
.
returns
(
1
);
const
wrapper
=
createComponent
();
assert
.
isFalse
(
notificationIsCollapsed
(
wrapper
));
wrapper
.
find
(
'Button'
).
prop
(
handler
)();
wrapper
.
update
();
assert
.
isFalse
(
notificationIsCollapsed
(
wrapper
));
});
});
[
'onMouseEnter'
,
'onFocus'
].
forEach
(
handler
=>
{
it
(
'expands notification when button is hovered or focused'
,
async
()
=>
{
const
promise
=
timeoutAsPromise
();
const
wrapper
=
createComponent
();
await
promise
;
// Wait for timeout callback to be invoked
wrapper
.
update
();
assert
.
isTrue
(
notificationIsCollapsed
(
wrapper
));
wrapper
.
find
(
'Button'
).
prop
(
handler
)();
wrapper
.
update
();
assert
.
isFalse
(
notificationIsCollapsed
(
wrapper
));
});
});
});
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