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
2ffbf5f8
Commit
2ffbf5f8
authored
Mar 09, 2021
by
Lyza Danger Gardner
Committed by
Lyza Gardner
Mar 10, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ability to open the Notebook with a key command within the UserMenu
parent
eae5627e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
2 deletions
+38
-2
UserMenu.js
src/sidebar/components/UserMenu.js
+21
-2
UserMenu-test.js
src/sidebar/components/test/UserMenu-test.js
+17
-0
No files found.
src/sidebar/components/UserMenu.js
View file @
2ffbf5f8
import
{
SvgIcon
}
from
'@hypothesis/frontend-shared'
;
import
{
useState
}
from
'preact/hooks'
;
import
bridgeEvents
from
'../../shared/bridge-events'
;
import
serviceConfig
from
'../config/service-config'
;
...
...
@@ -44,6 +45,7 @@ function UserMenu({ auth, bridge, onLogout, serviceUrl, settings }) {
const
isThirdParty
=
isThirdPartyUser
(
auth
.
userid
,
settings
.
authDomain
);
const
service
=
serviceConfig
(
settings
);
const
isNotebookEnabled
=
store
.
isFeatureEnabled
(
'notebook_launch'
);
const
[
isOpen
,
setOpen
]
=
useState
(
false
);
const
serviceSupports
=
feature
=>
service
&&
!!
service
[
feature
];
...
...
@@ -56,6 +58,15 @@ function UserMenu({ auth, bridge, onLogout, serviceUrl, settings }) {
bridge
.
call
(
'openNotebook'
,
store
.
focusedGroupId
());
};
// Temporary access to the Notebook without feature flag:
// type the key 'n' when user menu is focused/open
const
onKeyDown
=
event
=>
{
if
(
event
.
key
===
'n'
)
{
onSelectNotebook
();
setOpen
(
false
);
}
};
const
onProfileSelected
=
()
=>
isThirdParty
&&
bridge
.
call
(
bridgeEvents
.
PROFILE_REQUESTED
);
...
...
@@ -77,8 +88,16 @@ function UserMenu({ auth, bridge, onLogout, serviceUrl, settings }) {
<
/span
>
);
return
(
<
div
className
=
"UserMenu"
>
<
Menu
label
=
{
menuLabel
}
title
=
{
auth
.
displayName
}
align
=
"right"
>
// FIXME: KeyDown handling is temporary for Notebook "easter egg"
/* eslint-disable-next-line jsx-a11y/no-static-element-interactions */
<
div
className
=
"UserMenu"
onKeyDown
=
{
onKeyDown
}
>
<
Menu
label
=
{
menuLabel
}
title
=
{
auth
.
displayName
}
align
=
"right"
open
=
{
isOpen
}
onOpenChanged
=
{
setOpen
}
>
<
MenuSection
>
<
MenuItem
label
=
{
auth
.
displayName
}
...
...
src/sidebar/components/test/UserMenu-test.js
View file @
2ffbf5f8
import
{
mount
}
from
'enzyme'
;
import
{
act
}
from
'preact/test-utils'
;
import
bridgeEvents
from
'../../../shared/bridge-events'
;
import
UserMenu
from
'../UserMenu'
;
...
...
@@ -206,6 +207,22 @@ describe('UserMenu', () => {
assert
.
calledOnce
(
fakeBridge
.
call
);
assert
.
calledWith
(
fakeBridge
.
call
,
'openNotebook'
,
'mygroup'
);
});
it
(
'opens the notebook and closes itself when `n` is typed'
,
()
=>
{
const
wrapper
=
createUserMenu
();
// Make the menu "open"
act
(()
=>
{
wrapper
.
find
(
'Menu'
).
props
().
onOpenChanged
(
true
);
});
wrapper
.
update
();
assert
.
isTrue
(
wrapper
.
find
(
'Menu'
).
props
().
open
);
wrapper
.
find
(
'.UserMenu'
).
simulate
(
'keydown'
,
{
key
:
'n'
});
assert
.
calledOnce
(
fakeBridge
.
call
);
assert
.
calledWith
(
fakeBridge
.
call
,
'openNotebook'
,
'mygroup'
);
// Now the menu is "closed" again
assert
.
isFalse
(
wrapper
.
find
(
'Menu'
).
props
().
open
);
});
});
context
(
'notebook feature is not enabled'
,
()
=>
{
...
...
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