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
9bebcd60
Commit
9bebcd60
authored
Jan 03, 2024
by
Alejandro Celaya
Committed by
Alejandro Celaya
Jan 04, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use display name if possible, when exporting annotations to text
parent
4e316d54
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
83 additions
and
24 deletions
+83
-24
ExportAnnotations.tsx
src/sidebar/components/ShareDialog/ExportAnnotations.tsx
+5
-1
annotation-user-test.js
src/sidebar/helpers/test/annotation-user-test.js
+4
-0
annotations-exporter.ts
src/sidebar/services/annotations-exporter.ts
+20
-8
annotations-exporter-test.js
src/sidebar/services/test/annotations-exporter-test.js
+54
-15
No files found.
src/sidebar/components/ShareDialog/ExportAnnotations.tsx
View file @
9bebcd60
...
...
@@ -139,7 +139,11 @@ function ExportAnnotations({
case 'txt': {
const exportData = annotationsExporter.buildTextExportContent(
annotationsToExport,
group?.name,
{
groupName: group?.name,
defaultAuthority,
displayNamesEnabled,
},
);
downloadTextFile(exportData, filename);
break;
...
...
src/sidebar/helpers/test/annotation-user-test.js
View file @
9bebcd60
...
...
@@ -21,6 +21,10 @@ describe('sidebar/helpers/annotation-user', () => {
});
});
afterEach
(()
=>
{
$imports
.
$restore
();
});
const
fakeAnnotations
=
{
withDisplayName
:
{
user
:
'acct:albert@victoriana.com'
,
...
...
src/sidebar/services/annotations-exporter.ts
View file @
9bebcd60
import
{
trimAndDedent
}
from
'../../shared/trim-and-dedent'
;
import
type
{
APIAnnotationData
}
from
'../../types/api'
;
import
{
username
}
from
'../helpers/account-id'
;
import
{
documentMetadata
,
isReply
,
quote
,
}
from
'../helpers/annotation-metadata'
;
import
{
annotationDisplayName
}
from
'../helpers/annotation-user'
;
import
{
stripInternalProperties
}
from
'../helpers/strip-internal-properties'
;
import
{
VersionData
}
from
'../helpers/version-data'
;
import
type
{
SidebarStore
}
from
'../store'
;
...
...
@@ -17,6 +17,13 @@ export type JSONExportContent = {
annotations
:
APIAnnotationData
[];
};
export
type
TextExportOptions
=
{
defaultAuthority
?:
string
;
displayNamesEnabled
?:
boolean
;
groupName
?:
string
;
now
?:
Date
;
};
/**
* Generates annotations exports
*
...
...
@@ -49,21 +56,26 @@ export class AnnotationsExporter {
buildTextExportContent
(
annotations
:
APIAnnotationData
[],
groupName
=
''
,
/* istanbul ignore next - test seam */
now
=
new
Date
(),
{
groupName
=
''
,
displayNamesEnabled
=
false
,
defaultAuthority
=
''
,
/* istanbul ignore next - test seam */
now
=
new
Date
(),
}:
TextExportOptions
=
{},
):
string
{
const
[
firstAnnotation
]
=
annotations
;
if
(
!
firstAnnotation
)
{
throw
new
Error
(
'No annotations to export'
);
}
const
extractUsername
=
(
annotation
:
APIAnnotationData
)
=>
annotationDisplayName
(
annotation
,
defaultAuthority
,
displayNamesEnabled
);
const
{
uri
,
title
}
=
documentMetadata
(
firstAnnotation
);
const
uniqueUsers
=
[
...
new
Set
(
annotations
.
map
(
annotation
=>
username
(
annotation
.
user
))
.
filter
(
Boolean
),
annotations
.
map
(
anno
=>
extractUsername
(
anno
)).
filter
(
Boolean
),
),
];
...
...
@@ -74,7 +86,7 @@ export class AnnotationsExporter {
Annotation
${
index
+
1
}
:
${
annotation
.
created
}
${
annotation
.
text
}
${
username
(
annotation
.
user
)}
${
extractUsername
(
annotation
)}
"
${
quote
(
annotation
)}
"
Tags:
${
annotation
.
tags
.
join
(
', '
)}
`
,
)
...
...
src/sidebar/services/test/annotations-exporter-test.js
View file @
9bebcd60
...
...
@@ -44,6 +44,18 @@ describe('AnnotationsExporter', () => {
});
describe
(
'buildTextExportContent'
,
()
=>
{
let
baseAnnotation
;
beforeEach
(()
=>
{
baseAnnotation
=
{
...
newAnnotation
(),
...
publicAnnotation
(),
created
:
now
.
toISOString
(),
};
// Title should actually be an array
baseAnnotation
.
document
.
title
=
[
baseAnnotation
.
document
.
title
];
});
it
(
'throws error when empty list of annotations is provided'
,
()
=>
{
assert
.
throws
(
()
=>
exporter
.
buildTextExportContent
([]),
...
...
@@ -52,34 +64,26 @@ describe('AnnotationsExporter', () => {
});
it
(
'generates text content with provided annotations'
,
()
=>
{
const
isoDate
=
now
.
toISOString
();
const
annotation
=
{
...
newAnnotation
(),
...
publicAnnotation
(),
created
:
isoDate
,
};
// Title should actually be an array
annotation
.
document
.
title
=
[
annotation
.
document
.
title
];
const
isoDate
=
baseAnnotation
.
created
;
const
annotations
=
[
a
nnotation
,
a
nnotation
,
baseA
nnotation
,
baseA
nnotation
,
{
...
a
nnotation
,
...
baseA
nnotation
,
user
:
'acct:jane@localhost'
,
tags
:
[
'foo'
,
'bar'
],
},
{
...
a
nnotation
,
...
baseA
nnotation
,
...
newReply
(),
},
];
const
groupName
=
'My group'
;
const
result
=
exporter
.
buildTextExportContent
(
annotations
,
const
result
=
exporter
.
buildTextExportContent
(
annotations
,
{
groupName
,
now
,
);
}
);
assert
.
equal
(
result
,
...
...
@@ -118,6 +122,41 @@ ${isoDate}
Annotation text
bill
"null"
Tags: tag_1, tag_2`
,
);
});
it
(
'uses display names if `displayNamesEnabled` is set'
,
()
=>
{
const
annotation
=
{
...
baseAnnotation
,
user_info
:
{
display_name
:
'John Doe'
,
},
};
const
isoDate
=
annotation
.
created
;
const
groupName
=
'My group'
;
const
result
=
exporter
.
buildTextExportContent
([
annotation
],
{
displayNamesEnabled
:
true
,
groupName
,
now
,
});
assert
.
equal
(
result
,
`
${
isoDate
}
A special document
http://example.com
Group:
${
groupName
}
Total users: 1
Users: John Doe
Total annotations: 1
Total replies: 0
Annotation 1:
${
isoDate
}
Annotation text
John Doe
"null"
Tags: tag_1, tag_2`
,
);
});
...
...
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