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
31c1555b
Commit
31c1555b
authored
Jan 05, 2024
by
Alejandro Celaya
Committed by
Alejandro Celaya
Jan 05, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make AnnotationsExporter not depend on SidebarStore
parent
8ad4483e
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
41 deletions
+45
-41
ExportAnnotations.tsx
src/sidebar/components/ShareDialog/ExportAnnotations.tsx
+6
-3
annotations-exporter.ts
src/sidebar/services/annotations-exporter.ts
+11
-11
annotations-exporter-test.js
src/sidebar/services/test/annotations-exporter-test.js
+28
-27
No files found.
src/sidebar/components/ShareDialog/ExportAnnotations.tsx
View file @
31c1555b
...
...
@@ -84,7 +84,8 @@ function ExportAnnotations({
);
// User whose annotations are going to be exported.
const
currentUser
=
store
.
profile
().
userid
;
const
profile
=
store
.
profile
();
const
currentUser
=
profile
.
userid
;
const
allAnnotationsOption
:
Omit
<
UserAnnotations
,
'userid'
>
=
useMemo
(
()
=>
({
annotations
:
exportableAnnotations
,
...
...
@@ -131,8 +132,10 @@ function ExportAnnotations({
switch (format) {
case 'json': {
const exportData =
annotationsExporter.buildJSONExportContent(annotationsToExport);
const exportData = annotationsExporter.buildJSONExportContent(
annotationsToExport,
{ profile },
);
downloadJSONFile(exportData, filename);
break;
}
...
...
src/sidebar/services/annotations-exporter.ts
View file @
31c1555b
import
{
trimAndDedent
}
from
'../../shared/trim-and-dedent'
;
import
type
{
APIAnnotationData
}
from
'../../types/api'
;
import
type
{
APIAnnotationData
,
Profile
}
from
'../../types/api'
;
import
{
documentMetadata
,
isReply
,
...
...
@@ -9,7 +9,6 @@ import {
import
{
annotationDisplayName
}
from
'../helpers/annotation-user'
;
import
{
stripInternalProperties
}
from
'../helpers/strip-internal-properties'
;
import
{
VersionData
}
from
'../helpers/version-data'
;
import
type
{
SidebarStore
}
from
'../store'
;
export
type
JSONExportContent
=
{
export_date
:
string
;
...
...
@@ -18,6 +17,11 @@ export type JSONExportContent = {
annotations
:
APIAnnotationData
[];
};
export
type
JSONExportOptions
=
{
profile
:
Profile
;
now
?:
Date
;
};
export
type
TextExportOptions
=
{
defaultAuthority
?:
string
;
displayNamesEnabled
?:
boolean
;
...
...
@@ -31,18 +35,14 @@ export type TextExportOptions = {
* @inject
*/
export
class
AnnotationsExporter
{
private
_store
:
SidebarStore
;
constructor
(
store
:
SidebarStore
)
{
this
.
_store
=
store
;
}
buildJSONExportContent
(
annotations
:
APIAnnotationData
[],
{
profile
,
/* istanbul ignore next - test seam */
now
=
new
Date
(),
}:
JSONExportOptions
,
):
JSONExportContent
{
const
profile
=
this
.
_store
.
profile
();
const
versionData
=
new
VersionData
(
profile
,
[]);
return
{
...
...
src/sidebar/services/test/annotations-exporter-test.js
View file @
31c1555b
...
...
@@ -6,20 +6,17 @@ import {
import
{
AnnotationsExporter
}
from
'../annotations-exporter'
;
describe
(
'AnnotationsExporter'
,
()
=>
{
let
fakeStore
;
let
now
;
let
exporter
;
beforeEach
(()
=>
{
fakeStore
=
{
profile
:
sinon
.
stub
().
returns
({
userid
:
'userId'
}),
};
now
=
new
Date
();
exporter
=
new
AnnotationsExporter
(
fakeStore
);
exporter
=
new
AnnotationsExporter
();
});
describe
(
'buildJSONExportContent'
,
()
=>
{
it
(
'generates JSON content with provided annotations'
,
()
=>
{
const
profile
=
{
userid
:
'userId'
};
const
firstBaseAnnotation
=
publicAnnotation
();
const
secondBaseAnnotation
=
publicAnnotation
();
const
annotations
=
[
...
...
@@ -33,7 +30,10 @@ describe('AnnotationsExporter', () => {
},
];
const
result
=
exporter
.
buildJSONExportContent
(
annotations
,
now
);
const
result
=
exporter
.
buildJSONExportContent
(
annotations
,
{
now
,
profile
,
});
assert
.
deepEqual
(
result
,
{
export_date
:
now
.
toISOString
(),
...
...
@@ -42,6 +42,7 @@ describe('AnnotationsExporter', () => {
annotations
:
[
firstBaseAnnotation
,
secondBaseAnnotation
],
});
});
});
describe
(
'buildTextExportContent'
,
()
=>
{
let
baseAnnotation
;
...
...
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