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({
...
@@ -139,7 +139,11 @@ function ExportAnnotations({
case 'txt': {
case 'txt': {
const exportData = annotationsExporter.buildTextExportContent(
const exportData = annotationsExporter.buildTextExportContent(
annotationsToExport,
annotationsToExport,
group?.name,
{
groupName: group?.name,
defaultAuthority,
displayNamesEnabled,
},
);
);
downloadTextFile(exportData, filename);
downloadTextFile(exportData, filename);
break;
break;
...
...
src/sidebar/helpers/test/annotation-user-test.js
View file @
9bebcd60
...
@@ -21,6 +21,10 @@ describe('sidebar/helpers/annotation-user', () => {
...
@@ -21,6 +21,10 @@ describe('sidebar/helpers/annotation-user', () => {
});
});
});
});
afterEach
(()
=>
{
$imports
.
$restore
();
});
const
fakeAnnotations
=
{
const
fakeAnnotations
=
{
withDisplayName
:
{
withDisplayName
:
{
user
:
'acct:albert@victoriana.com'
,
user
:
'acct:albert@victoriana.com'
,
...
...
src/sidebar/services/annotations-exporter.ts
View file @
9bebcd60
import
{
trimAndDedent
}
from
'../../shared/trim-and-dedent'
;
import
{
trimAndDedent
}
from
'../../shared/trim-and-dedent'
;
import
type
{
APIAnnotationData
}
from
'../../types/api'
;
import
type
{
APIAnnotationData
}
from
'../../types/api'
;
import
{
username
}
from
'../helpers/account-id'
;
import
{
import
{
documentMetadata
,
documentMetadata
,
isReply
,
isReply
,
quote
,
quote
,
}
from
'../helpers/annotation-metadata'
;
}
from
'../helpers/annotation-metadata'
;
import
{
annotationDisplayName
}
from
'../helpers/annotation-user'
;
import
{
stripInternalProperties
}
from
'../helpers/strip-internal-properties'
;
import
{
stripInternalProperties
}
from
'../helpers/strip-internal-properties'
;
import
{
VersionData
}
from
'../helpers/version-data'
;
import
{
VersionData
}
from
'../helpers/version-data'
;
import
type
{
SidebarStore
}
from
'../store'
;
import
type
{
SidebarStore
}
from
'../store'
;
...
@@ -17,6 +17,13 @@ export type JSONExportContent = {
...
@@ -17,6 +17,13 @@ export type JSONExportContent = {
annotations
:
APIAnnotationData
[];
annotations
:
APIAnnotationData
[];
};
};
export
type
TextExportOptions
=
{
defaultAuthority
?:
string
;
displayNamesEnabled
?:
boolean
;
groupName
?:
string
;
now
?:
Date
;
};
/**
/**
* Generates annotations exports
* Generates annotations exports
*
*
...
@@ -49,21 +56,26 @@ export class AnnotationsExporter {
...
@@ -49,21 +56,26 @@ export class AnnotationsExporter {
buildTextExportContent
(
buildTextExportContent
(
annotations
:
APIAnnotationData
[],
annotations
:
APIAnnotationData
[],
groupName
=
''
,
{
/* istanbul ignore next - test seam */
groupName
=
''
,
now
=
new
Date
(),
displayNamesEnabled
=
false
,
defaultAuthority
=
''
,
/* istanbul ignore next - test seam */
now
=
new
Date
(),
}:
TextExportOptions
=
{},
):
string
{
):
string
{
const
[
firstAnnotation
]
=
annotations
;
const
[
firstAnnotation
]
=
annotations
;
if
(
!
firstAnnotation
)
{
if
(
!
firstAnnotation
)
{
throw
new
Error
(
'No annotations to export'
);
throw
new
Error
(
'No annotations to export'
);
}
}
const
extractUsername
=
(
annotation
:
APIAnnotationData
)
=>
annotationDisplayName
(
annotation
,
defaultAuthority
,
displayNamesEnabled
);
const
{
uri
,
title
}
=
documentMetadata
(
firstAnnotation
);
const
{
uri
,
title
}
=
documentMetadata
(
firstAnnotation
);
const
uniqueUsers
=
[
const
uniqueUsers
=
[
...
new
Set
(
...
new
Set
(
annotations
annotations
.
map
(
anno
=>
extractUsername
(
anno
)).
filter
(
Boolean
),
.
map
(
annotation
=>
username
(
annotation
.
user
))
.
filter
(
Boolean
),
),
),
];
];
...
@@ -74,7 +86,7 @@ export class AnnotationsExporter {
...
@@ -74,7 +86,7 @@ export class AnnotationsExporter {
Annotation
${
index
+
1
}
:
Annotation
${
index
+
1
}
:
${
annotation
.
created
}
${
annotation
.
created
}
${
annotation
.
text
}
${
annotation
.
text
}
${
username
(
annotation
.
user
)}
${
extractUsername
(
annotation
)}
"
${
quote
(
annotation
)}
"
"
${
quote
(
annotation
)}
"
Tags:
${
annotation
.
tags
.
join
(
', '
)}
`
,
Tags:
${
annotation
.
tags
.
join
(
', '
)}
`
,
)
)
...
...
src/sidebar/services/test/annotations-exporter-test.js
View file @
9bebcd60
...
@@ -44,6 +44,18 @@ describe('AnnotationsExporter', () => {
...
@@ -44,6 +44,18 @@ describe('AnnotationsExporter', () => {
});
});
describe
(
'buildTextExportContent'
,
()
=>
{
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'
,
()
=>
{
it
(
'throws error when empty list of annotations is provided'
,
()
=>
{
assert
.
throws
(
assert
.
throws
(
()
=>
exporter
.
buildTextExportContent
([]),
()
=>
exporter
.
buildTextExportContent
([]),
...
@@ -52,34 +64,26 @@ describe('AnnotationsExporter', () => {
...
@@ -52,34 +64,26 @@ describe('AnnotationsExporter', () => {
});
});
it
(
'generates text content with provided annotations'
,
()
=>
{
it
(
'generates text content with provided annotations'
,
()
=>
{
const
isoDate
=
now
.
toISOString
();
const
isoDate
=
baseAnnotation
.
created
;
const
annotation
=
{
...
newAnnotation
(),
...
publicAnnotation
(),
created
:
isoDate
,
};
// Title should actually be an array
annotation
.
document
.
title
=
[
annotation
.
document
.
title
];
const
annotations
=
[
const
annotations
=
[
a
nnotation
,
baseA
nnotation
,
a
nnotation
,
baseA
nnotation
,
{
{
...
a
nnotation
,
...
baseA
nnotation
,
user
:
'acct:jane@localhost'
,
user
:
'acct:jane@localhost'
,
tags
:
[
'foo'
,
'bar'
],
tags
:
[
'foo'
,
'bar'
],
},
},
{
{
...
a
nnotation
,
...
baseA
nnotation
,
...
newReply
(),
...
newReply
(),
},
},
];
];
const
groupName
=
'My group'
;
const
groupName
=
'My group'
;
const
result
=
exporter
.
buildTextExportContent
(
const
result
=
exporter
.
buildTextExportContent
(
annotations
,
{
annotations
,
groupName
,
groupName
,
now
,
now
,
);
}
);
assert
.
equal
(
assert
.
equal
(
result
,
result
,
...
@@ -118,6 +122,41 @@ ${isoDate}
...
@@ -118,6 +122,41 @@ ${isoDate}
Annotation text
Annotation text
bill
bill
"null"
"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`
,
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