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
71bb4cc4
Commit
71bb4cc4
authored
Jan 17, 2024
by
Alejandro Celaya
Committed by
Alejandro Celaya
Jan 18, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make sure selected user is live updated on export pannel
parent
b06d0d16
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
21 deletions
+28
-21
ExportAnnotations.tsx
src/sidebar/components/ShareDialog/ExportAnnotations.tsx
+22
-10
ExportAnnotations-test.js
...bar/components/ShareDialog/test/ExportAnnotations-test.js
+6
-11
No files found.
src/sidebar/components/ShareDialog/ExportAnnotations.tsx
View file @
71bb4cc4
...
@@ -116,10 +116,17 @@ function ExportAnnotations({
...
@@ -116,10 +116,17 @@ function ExportAnnotations({
}),
}),
[
exportableAnnotations
],
[
exportableAnnotations
],
);
);
const
[
selectedUser
,
setSelectedUser
]
=
useState
(
// Try to preselect current user
// Try to preselect current user
userList
.
find
(
userInfo
=>
userInfo
.
userid
===
currentUser
)
??
const
[
selectedUserId
,
setSelectedUserId
]
=
useState
(
currentUser
);
// Re-compute selectedUserAnnotations if:
// - `userList` changes: This means annotations where created/deleted/updated
// - `selectedUserId` changes: This means user was manually changed
const
selectedUserAnnotations
=
useMemo
(
()
=>
userList
.
find
(
user
=>
user
.
userid
===
selectedUserId
)
??
allAnnotationsOption
,
allAnnotationsOption
,
[
allAnnotationsOption
,
selectedUserId
,
userList
],
);
);
const
exportFormatsEnabled
=
store
.
isFeatureEnabled
(
'export_formats'
);
const
exportFormatsEnabled
=
store
.
isFeatureEnabled
(
'export_formats'
);
...
@@ -143,7 +150,7 @@ function ExportAnnotations({
...
@@ -143,7 +150,7 @@ function ExportAnnotations({
const
buildExportContent
=
useCallback
(
const
buildExportContent
=
useCallback
(
(
format
:
ExportFormat
[
'value'
]):
string
=>
{
(
format
:
ExportFormat
[
'value'
]):
string
=>
{
const
annotationsToExport
=
const
annotationsToExport
=
selectedUser
?.
annotations
??
exportableAnnotations
;
selectedUser
Annotations
?.
annotations
??
exportableAnnotations
;
switch
(
format
)
{
switch
(
format
)
{
case
'json'
:
{
case
'json'
:
{
const
data
=
annotationsExporter
.
buildJSONExportContent
(
const
data
=
annotationsExporter
.
buildJSONExportContent
(
...
@@ -194,7 +201,7 @@ function ExportAnnotations({
...
@@ -194,7 +201,7 @@ function ExportAnnotations({
exportableAnnotations
,
exportableAnnotations
,
group
?.
name
,
group
?.
name
,
profile
,
profile
,
selectedUser
?.
annotations
,
selectedUser
Annotations
?.
annotations
,
],
],
);
);
const
exportAnnotations
=
useCallback
(
const
exportAnnotations
=
useCallback
(
...
@@ -270,21 +277,26 @@ function ExportAnnotations({
...
@@ -270,21 +277,26 @@ function ExportAnnotations({
Select which user{"'"}s annotations to export:
Select which user{"'"}s annotations to export:
</label>
</label>
<SelectNext
<SelectNext
value={selectedUser}
value={selectedUser
Id
}
onChange={setSelectedUser}
onChange={setSelectedUser
Id
}
buttonId={userSelectId}
buttonId={userSelectId}
buttonContent={
buttonContent={
<UserAnnotationsListItem userAnnotations={selectedUser} />
<UserAnnotationsListItem
userAnnotations={selectedUserAnnotations}
/>
}
}
data-testid="user-select"
data-testid="user-select"
>
>
<SelectNext.Option value={
allAnnotationsOption
}>
<SelectNext.Option value={
undefined
}>
<UserAnnotationsListItem
<UserAnnotationsListItem
userAnnotations={allAnnotationsOption}
userAnnotations={allAnnotationsOption}
/>
/>
</SelectNext.Option>
</SelectNext.Option>
{userList.map(userInfo => (
{userList.map(userInfo => (
<SelectNext.Option key={userInfo.userid} value={userInfo}>
<SelectNext.Option
key={userInfo.userid}
value={userInfo.userid}
>
<UserAnnotationsListItem userAnnotations={userInfo} />
<UserAnnotationsListItem userAnnotations={userInfo} />
</SelectNext.Option>
</SelectNext.Option>
))}
))}
...
...
src/sidebar/components/ShareDialog/test/ExportAnnotations-test.js
View file @
71bb4cc4
...
@@ -210,11 +210,12 @@ describe('ExportAnnotations', () => {
...
@@ -210,11 +210,12 @@ describe('ExportAnnotations', () => {
assert
.
equal
(
users
.
length
,
userEntries
.
length
);
assert
.
equal
(
users
.
length
,
userEntries
.
length
);
for
(
const
[
i
,
entry
]
of
userEntries
.
entries
())
{
for
(
const
[
i
,
entry
]
of
userEntries
.
entries
())
{
const
value
=
users
.
at
(
i
).
prop
(
'value'
);
const
user
=
users
.
at
(
i
);
const
value
=
user
.
prop
(
'value'
);
const
text
=
user
.
text
();
assert
.
equal
(
value
.
userid
,
entry
.
userid
);
assert
.
equal
(
value
,
entry
.
userid
);
assert
.
equal
(
value
.
displayName
,
entry
.
displayName
);
assert
.
equal
(
text
,
`
${
entry
.
displayName
}${
entry
.
annotationsCount
}
`
);
assert
.
equal
(
value
.
annotations
.
length
,
entry
.
annotationsCount
);
}
}
});
});
});
});
...
@@ -376,14 +377,8 @@ describe('ExportAnnotations', () => {
...
@@ -376,14 +377,8 @@ describe('ExportAnnotations', () => {
// Select the user whose annotations we want to export
// Select the user whose annotations we want to export
const
userList
=
await
waitForTestId
(
wrapper
,
'user-select'
);
const
userList
=
await
waitForTestId
(
wrapper
,
'user-select'
);
const
option
=
userList
.
find
(
SelectNext
.
Option
)
.
filterWhere
(
option
=>
option
.
prop
(
'value'
).
userid
===
'acct:john@example.com'
,
)
.
first
();
act
(()
=>
{
act
(()
=>
{
userList
.
prop
(
'onChange'
)(
option
.
prop
(
'value'
)
);
userList
.
prop
(
'onChange'
)(
'acct:john@example.com'
);
});
});
wrapper
.
update
();
wrapper
.
update
();
...
...
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