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
9c48fa19
Commit
9c48fa19
authored
Nov 12, 2024
by
Alejandro Celaya
Committed by
Alejandro Celaya
Nov 13, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add group type icons to groups menu
parent
35a67ebf
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
73 additions
and
15 deletions
+73
-15
GroupList.tsx
src/sidebar/components/GroupList/GroupList.tsx
+1
-1
GroupListItem.tsx
src/sidebar/components/GroupList/GroupListItem.tsx
+31
-2
GroupList-test.js
src/sidebar/components/GroupList/test/GroupList-test.js
+4
-6
GroupListItem-test.js
src/sidebar/components/GroupList/test/GroupListItem-test.js
+31
-0
MenuItem.tsx
src/sidebar/components/MenuItem.tsx
+3
-5
api.ts
src/types/api.ts
+3
-1
No files found.
src/sidebar/components/GroupList/GroupList.tsx
View file @
9c48fa19
...
...
@@ -161,7 +161,7 @@ function GroupList({ settings }: GroupListProps) {
<
MenuItem
icon=
{
PlusIcon
}
href=
{
newGroupLink
}
label=
"
New private
group"
label=
"
Create new
group"
/>
)
}
</
Menu
>
...
...
src/sidebar/components/GroupList/GroupListItem.tsx
View file @
9c48fa19
...
...
@@ -2,11 +2,14 @@ import {
confirm
,
CopyIcon
,
ExternalIcon
,
GlobeAltIcon
,
GlobeAltLockIcon
,
LeaveIcon
,
LockIcon
,
}
from
'@hypothesis/frontend-shared'
;
import
classnames
from
'classnames'
;
import
type
{
Group
}
from
'../../../types/api'
;
import
type
{
Group
,
GroupType
}
from
'../../../types/api'
;
import
{
orgName
}
from
'../../helpers/group-list-item-common'
;
import
{
withServices
}
from
'../../service-context'
;
import
type
{
GroupsService
}
from
'../../services/groups'
;
...
...
@@ -15,6 +18,27 @@ import { useSidebarStore } from '../../store';
import
{
copyPlainText
}
from
'../../util/copy-to-clipboard'
;
import
MenuItem
from
'../MenuItem'
;
function
GroupIcon
({
type
}:
{
type
:
GroupType
})
{
const
title
=
type
===
'open'
?
'Public group'
:
type
===
'restricted'
?
'Restricted group'
:
'Private group'
;
return
(
<
div
className=
"text-color-text-light"
title=
{
title
}
data
-
testid=
"group-icon"
>
{
type
===
'open'
&&
<
GlobeAltIcon
/>
}
{
type
===
'restricted'
&&
<
GlobeAltLockIcon
/>
}
{
type
===
'private'
&&
<
LockIcon
/>
}
</
div
>
);
}
export
type
GroupListItemProps
=
{
group
:
Group
;
...
...
@@ -103,7 +127,12 @@ function GroupListItem({
isExpanded=
{
hasActionMenu
?
isExpanded
:
false
}
isSelected=
{
isSelected
}
isSubmenuVisible=
{
hasActionMenu
?
isExpanded
:
undefined
}
label=
{
group
.
name
}
label=
{
<
div
className=
"grow flex items-center justify-between gap-x-2"
>
{
group
.
name
}
<
GroupIcon
type=
{
group
.
type
}
/>
</
div
>
}
leftChannelContent=
{
leftChannelContent
}
onClick=
{
isSelectable
?
focusGroup
:
toggleSubmenu
}
onToggleSubmenu=
{
toggleSubmenu
}
...
...
src/sidebar/components/GroupList/test/GroupList-test.js
View file @
9c48fa19
...
...
@@ -151,23 +151,21 @@ describe('GroupList', () => {
expectNewGroupButton
:
false
,
},
].
forEach
(({
userid
,
expectNewGroupButton
})
=>
{
it
(
'displays "
New private
group" button if user is logged in with first-party account'
,
()
=>
{
it
(
'displays "
Create new
group" button if user is logged in with first-party account'
,
()
=>
{
fakeStore
.
profile
.
returns
({
userid
});
const
wrapper
=
createGroupList
();
const
newGroupButton
=
wrapper
.
find
(
'MenuItem[label="New private group"]'
,
);
const
newGroupButton
=
wrapper
.
find
(
'MenuItem[label="Create new group"]'
);
assert
.
equal
(
newGroupButton
.
length
,
expectNewGroupButton
?
1
:
0
);
});
});
it
(
'opens new window at correct URL when "
New private
group" is clicked'
,
()
=>
{
it
(
'opens new window at correct URL when "
Create new
group" is clicked'
,
()
=>
{
fakeStore
.
getLink
.
withArgs
(
'groups.new'
)
.
returns
(
'https://example.com/groups/new'
);
fakeStore
.
profile
.
returns
({
userid
:
'jsmith@hypothes.is'
});
const
wrapper
=
createGroupList
();
const
newGroupButton
=
wrapper
.
find
(
'MenuItem[label="
New private
group"]'
);
const
newGroupButton
=
wrapper
.
find
(
'MenuItem[label="
Create new
group"]'
);
assert
.
equal
(
newGroupButton
.
props
().
href
,
'https://example.com/groups/new'
);
});
...
...
src/sidebar/components/GroupList/test/GroupListItem-test.js
View file @
9c48fa19
...
...
@@ -377,4 +377,35 @@ describe('GroupListItem', () => {
assert
.
calledWith
(
fakeCopyPlainText
,
'https://annotate.com/groups/groupid'
);
assert
.
calledWith
(
fakeToastMessenger
.
error
,
'Unable to copy link'
);
});
[
{
type
:
'private'
,
expectedIcon
:
'LockIcon'
,
expectedTitle
:
'Private group'
,
},
{
type
:
'restricted'
,
expectedIcon
:
'GlobeAltLockIcon'
,
expectedTitle
:
'Restricted group'
,
},
{
type
:
'open'
,
expectedIcon
:
'GlobeAltIcon'
,
expectedTitle
:
'Public group'
,
},
].
forEach
(({
type
,
expectedIcon
,
expectedTitle
})
=>
{
it
(
'shows the right icon for the group type'
,
()
=>
{
const
wrapper
=
createGroupListItem
({
...
fakeGroup
,
type
});
const
label
=
mount
(
wrapper
.
find
(
'MenuItem'
).
prop
(
'label'
));
const
groupIcon
=
label
.
find
(
'[data-testid="group-icon"]'
);
try
{
assert
.
equal
(
groupIcon
.
prop
(
'title'
),
expectedTitle
);
assert
.
isTrue
(
groupIcon
.
exists
(
expectedIcon
));
}
finally
{
label
.
unmount
();
}
});
});
});
src/sidebar/components/MenuItem.tsx
View file @
9c48fa19
import
{
CaretUp
Icon
,
MenuCollapse
Icon
,
MenuExpandIcon
,
Slider
,
}
from
'@hypothesis/frontend-shared'
;
...
...
@@ -21,9 +21,7 @@ function SubmenuToggle({
isExpanded
,
onToggleSubmenu
,
}:
SubmenuToggleProps
)
{
// FIXME: Use `MenuCollapseIcon` instead of `CaretUpIcon` once size
// disparities are addressed
const
Icon
=
isExpanded
?
CaretUpIcon
:
MenuExpandIcon
;
const
Icon
=
isExpanded
?
MenuCollapseIcon
:
MenuExpandIcon
;
return
(
<
div
data
-
testid=
"submenu-toggle"
...
...
@@ -55,7 +53,7 @@ function SubmenuToggle({
onClick=
{
onToggleSubmenu
}
title=
{
title
}
>
<
Icon
className=
"w-3 h-3"
/>
<
Icon
className=
"w-3 h-3"
viewBox=
"0 0 16 16"
/>
</
div
>
);
}
...
...
src/types/api.ts
View file @
9c48fa19
...
...
@@ -244,6 +244,8 @@ export type Profile = {
user_info
?:
UserInfo
;
};
export
type
GroupType
=
'private'
|
'restricted'
|
'open'
;
export
type
Organization
=
{
name
:
string
;
logo
:
string
;
...
...
@@ -261,7 +263,7 @@ export type Group = {
id
:
string
;
/** Fully-qualified ID with authority. */
groupid
?:
string
;
type
:
'private'
|
'open'
;
type
:
GroupType
;
/**
* Note: This field is nullable in the API, but we assign a default organization in the client.
*/
...
...
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