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
c9cc6e39
Commit
c9cc6e39
authored
Feb 03, 2023
by
Alejandro Celaya
Committed by
Alejandro Celaya
Feb 03, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add 'Your profile' item to UserMenu
parent
1b52ea81
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
0 deletions
+64
-0
UserMenu.tsx
src/sidebar/components/UserMenu.tsx
+8
-0
UserMenu-test.js
src/sidebar/components/test/UserMenu-test.js
+51
-0
port-rpc-events.d.ts
src/types/port-rpc-events.d.ts
+5
-0
No files found.
src/sidebar/components/UserMenu.tsx
View file @
c9cc6e39
...
...
@@ -45,10 +45,12 @@ function UserMenu({ frameSync, onLogout, settings }: UserMenuProps) {
!
isThirdParty
||
serviceSupports
(
'onProfileRequestProvided'
);
const
isLogoutEnabled
=
!
isThirdParty
||
serviceSupports
(
'onLogoutRequestProvided'
);
const
isProfileEnabled
=
store
.
isFeatureEnabled
(
'client_user_profile'
);
const
onSelectNotebook
=
()
=>
{
frameSync
.
notifyHost
(
'openNotebook'
,
store
.
focusedGroupId
());
};
const
onSelectProfile
=
()
=>
frameSync
.
notifyHost
(
'openProfile'
);
// Access to the Notebook:
// type the key 'n' when user menu is focused/open
...
...
@@ -56,6 +58,9 @@ function UserMenu({ frameSync, onLogout, settings }: UserMenuProps) {
if
(
event
.
key
===
'n'
)
{
onSelectNotebook
();
setOpen
(
false
);
}
else
if
(
isProfileEnabled
&&
event
.
key
===
'p'
)
{
onSelectProfile
();
setOpen
(
false
);
}
};
...
...
@@ -95,6 +100,9 @@ function UserMenu({ frameSync, onLogout, settings }: UserMenuProps) {
href=
{
store
.
getLink
(
'account.settings'
)
}
/>
)
}
{
isProfileEnabled
&&
(
<
MenuItem
label=
"Your profile"
onClick=
{
()
=>
onSelectProfile
()
}
/>
)
}
<
MenuItem
label=
"Open notebook"
onClick=
{
()
=>
onSelectNotebook
()
}
/>
</
MenuSection
>
{
isLogoutEnabled
&&
(
...
...
src/sidebar/components/test/UserMenu-test.js
View file @
c9cc6e39
...
...
@@ -12,6 +12,7 @@ describe('UserMenu', () => {
let
fakeServiceConfig
;
let
fakeSettings
;
let
fakeStore
;
let
fakeIsFeatureEnabled
;
const
createUserMenu
=
()
=>
{
return
mount
(
...
...
@@ -41,11 +42,13 @@ describe('UserMenu', () => {
fakeOnLogout
=
sinon
.
stub
();
fakeServiceConfig
=
sinon
.
stub
();
fakeSettings
=
{};
fakeIsFeatureEnabled
=
sinon
.
stub
().
returns
(
false
);
fakeStore
=
{
defaultAuthority
:
sinon
.
stub
().
returns
(
'hypothes.is'
),
focusedGroupId
:
sinon
.
stub
().
returns
(
'mygroup'
),
getLink
:
sinon
.
stub
(),
profile
:
sinon
.
stub
().
returns
(
fakeProfile
),
isFeatureEnabled
:
fakeIsFeatureEnabled
,
};
$imports
.
$mock
(
mockImportedComponents
());
...
...
@@ -208,6 +211,54 @@ describe('UserMenu', () => {
});
});
describe
(
'open profile item'
,
()
=>
{
[{
isFeatureEnabled
:
true
},
{
isFeatureEnabled
:
false
}].
forEach
(
({
isFeatureEnabled
})
=>
{
it
(
'includes profile item only for users with the feature flag enabled'
,
()
=>
{
fakeIsFeatureEnabled
.
returns
(
isFeatureEnabled
);
const
wrapper
=
createUserMenu
();
const
openProfileItem
=
findMenuItem
(
wrapper
,
'Your profile'
);
assert
.
equal
(
isFeatureEnabled
,
openProfileItem
.
exists
());
});
}
);
it
(
'opens the profile when clicked'
,
()
=>
{
fakeIsFeatureEnabled
.
returns
(
true
);
fakeIsThirdPartyUser
.
returns
(
true
);
const
wrapper
=
createUserMenu
();
const
openProfileItem
=
findMenuItem
(
wrapper
,
'Your profile'
);
openProfileItem
.
props
().
onClick
();
assert
.
calledOnce
(
fakeFrameSync
.
notifyHost
);
assert
.
calledWith
(
fakeFrameSync
.
notifyHost
,
'openProfile'
);
});
[{
featureIsEnabled
:
true
},
{
featureIsEnabled
:
false
}].
forEach
(
({
featureIsEnabled
})
=>
{
it
(
'responds to `p` keypress only when feature is enabled'
,
()
=>
{
fakeIsFeatureEnabled
.
returns
(
featureIsEnabled
);
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
(
'[data-testid="user-menu"]'
)
.
simulate
(
'keydown'
,
{
key
:
'p'
});
assert
.
equal
(
featureIsEnabled
,
fakeFrameSync
.
notifyHost
.
called
);
assert
.
equal
(
!
featureIsEnabled
,
wrapper
.
find
(
'Menu'
).
props
().
open
);
});
}
);
});
describe
(
'open notebook item'
,
()
=>
{
it
(
'includes the open notebook item'
,
()
=>
{
const
wrapper
=
createUserMenu
();
...
...
src/types/port-rpc-events.d.ts
View file @
c9cc6e39
...
...
@@ -193,6 +193,11 @@ export type SidebarToHostEvent =
*/
|
'openNotebook'
/**
* The sidebar is asking the host to open the user profile.
*/
|
'openProfile'
/**
* The sidebar is asking the host to open the sidebar (side-effect of creating
* an annotation).
...
...
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