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
Hide 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({
...
@@ -84,7 +84,8 @@ function ExportAnnotations({
);
);
// User whose annotations are going to be exported.
// 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
(
const
allAnnotationsOption
:
Omit
<
UserAnnotations
,
'userid'
>
=
useMemo
(
()
=>
({
()
=>
({
annotations
:
exportableAnnotations
,
annotations
:
exportableAnnotations
,
...
@@ -131,8 +132,10 @@ function ExportAnnotations({
...
@@ -131,8 +132,10 @@ function ExportAnnotations({
switch (format) {
switch (format) {
case 'json': {
case 'json': {
const exportData =
const exportData = annotationsExporter.buildJSONExportContent(
annotationsExporter.buildJSONExportContent(annotationsToExport);
annotationsToExport,
{ profile },
);
downloadJSONFile(exportData, filename);
downloadJSONFile(exportData, filename);
break;
break;
}
}
...
...
src/sidebar/services/annotations-exporter.ts
View file @
31c1555b
import
{
trimAndDedent
}
from
'../../shared/trim-and-dedent'
;
import
{
trimAndDedent
}
from
'../../shared/trim-and-dedent'
;
import
type
{
APIAnnotationData
}
from
'../../types/api'
;
import
type
{
APIAnnotationData
,
Profile
}
from
'../../types/api'
;
import
{
import
{
documentMetadata
,
documentMetadata
,
isReply
,
isReply
,
...
@@ -9,7 +9,6 @@ import {
...
@@ -9,7 +9,6 @@ import {
import
{
annotationDisplayName
}
from
'../helpers/annotation-user'
;
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'
;
export
type
JSONExportContent
=
{
export
type
JSONExportContent
=
{
export_date
:
string
;
export_date
:
string
;
...
@@ -18,6 +17,11 @@ export type JSONExportContent = {
...
@@ -18,6 +17,11 @@ export type JSONExportContent = {
annotations
:
APIAnnotationData
[];
annotations
:
APIAnnotationData
[];
};
};
export
type
JSONExportOptions
=
{
profile
:
Profile
;
now
?:
Date
;
};
export
type
TextExportOptions
=
{
export
type
TextExportOptions
=
{
defaultAuthority
?:
string
;
defaultAuthority
?:
string
;
displayNamesEnabled
?:
boolean
;
displayNamesEnabled
?:
boolean
;
...
@@ -31,18 +35,14 @@ export type TextExportOptions = {
...
@@ -31,18 +35,14 @@ export type TextExportOptions = {
* @inject
* @inject
*/
*/
export
class
AnnotationsExporter
{
export
class
AnnotationsExporter
{
private
_store
:
SidebarStore
;
constructor
(
store
:
SidebarStore
)
{
this
.
_store
=
store
;
}
buildJSONExportContent
(
buildJSONExportContent
(
annotations
:
APIAnnotationData
[],
annotations
:
APIAnnotationData
[],
/* istanbul ignore next - test seam */
{
now
=
new
Date
(),
profile
,
/* istanbul ignore next - test seam */
now
=
new
Date
(),
}:
JSONExportOptions
,
):
JSONExportContent
{
):
JSONExportContent
{
const
profile
=
this
.
_store
.
profile
();
const
versionData
=
new
VersionData
(
profile
,
[]);
const
versionData
=
new
VersionData
(
profile
,
[]);
return
{
return
{
...
...
src/sidebar/services/test/annotations-exporter-test.js
View file @
31c1555b
...
@@ -6,40 +6,41 @@ import {
...
@@ -6,40 +6,41 @@ import {
import
{
AnnotationsExporter
}
from
'../annotations-exporter'
;
import
{
AnnotationsExporter
}
from
'../annotations-exporter'
;
describe
(
'AnnotationsExporter'
,
()
=>
{
describe
(
'AnnotationsExporter'
,
()
=>
{
let
fakeStore
;
let
now
;
let
now
;
let
exporter
;
let
exporter
;
beforeEach
(()
=>
{
beforeEach
(()
=>
{
fakeStore
=
{
profile
:
sinon
.
stub
().
returns
({
userid
:
'userId'
}),
};
now
=
new
Date
();
now
=
new
Date
();
exporter
=
new
AnnotationsExporter
();
exporter
=
new
AnnotationsExporter
(
fakeStore
);
});
});
it
(
'generates JSON content with provided annotations'
,
()
=>
{
describe
(
'buildJSONExportContent'
,
()
=>
{
const
firstBaseAnnotation
=
publicAnnotation
();
it
(
'generates JSON content with provided annotations'
,
()
=>
{
const
secondBaseAnnotation
=
publicAnnotation
();
const
profile
=
{
userid
:
'userId'
};
const
annotations
=
[
const
firstBaseAnnotation
=
publicAnnotation
();
{
const
secondBaseAnnotation
=
publicAnnotation
();
...
firstBaseAnnotation
,
const
annotations
=
[
$tag
:
''
,
{
},
...
firstBaseAnnotation
,
{
$tag
:
''
,
...
secondBaseAnnotation
,
},
$highlight
:
true
,
{
},
...
secondBaseAnnotation
,
];
$highlight
:
true
,
},
const
result
=
exporter
.
buildJSONExportContent
(
annotations
,
now
);
];
assert
.
deepEqual
(
result
,
{
const
result
=
exporter
.
buildJSONExportContent
(
annotations
,
{
export_date
:
now
.
toISOString
(),
now
,
export_userid
:
'userId'
,
profile
,
client_version
:
'__VERSION__'
,
});
annotations
:
[
firstBaseAnnotation
,
secondBaseAnnotation
],
assert
.
deepEqual
(
result
,
{
export_date
:
now
.
toISOString
(),
export_userid
:
'userId'
,
client_version
:
'__VERSION__'
,
annotations
:
[
firstBaseAnnotation
,
secondBaseAnnotation
],
});
});
});
});
});
...
...
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