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
77c2259f
Commit
77c2259f
authored
Nov 14, 2023
by
Alejandro Celaya
Committed by
Alejandro Celaya
Nov 15, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Restrict annotations export to JSON
parent
3bd366f0
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
26 deletions
+33
-26
ExportAnnotations.tsx
src/sidebar/components/ShareDialog/ExportAnnotations.tsx
+24
-17
ExportAnnotations-test.js
...bar/components/ShareDialog/test/ExportAnnotations-test.js
+7
-7
annotations-exporter.ts
src/sidebar/services/annotations-exporter.ts
+1
-1
annotations-exporter-test.js
src/sidebar/services/test/annotations-exporter-test.js
+1
-1
No files found.
src/sidebar/components/ShareDialog/ExportAnnotations.tsx
View file @
77c2259f
...
@@ -27,7 +27,8 @@ export type ExportAnnotationsProps = {
...
@@ -27,7 +27,8 @@ export type ExportAnnotationsProps = {
};
};
type
ExportFormat
=
{
type
ExportFormat
=
{
value
:
'json'
|
'csv'
|
'text'
|
'html'
;
/** Unique format identifier used also as file extension */
value
:
'json'
|
'csv'
|
'txt'
|
'html'
;
name
:
string
;
name
:
string
;
};
};
...
@@ -36,18 +37,20 @@ const exportFormats: ExportFormat[] = [
...
@@ -36,18 +37,20 @@ const exportFormats: ExportFormat[] = [
value
:
'json'
,
value
:
'json'
,
name
:
'JSON'
,
name
:
'JSON'
,
},
},
{
value
:
'csv'
,
// TODO Enable these formats when implemented
name
:
'CSV'
,
// {
},
// value: 'csv',
{
// name: 'CSV',
value
:
'text'
,
// },
name
:
'Text'
,
// {
},
// value: 'txt',
{
// name: 'Text',
value
:
'html'
,
// },
name
:
'HTML'
,
// {
},
// value: 'html',
// name: 'HTML',
// },
];
];
/**
/**
...
@@ -118,12 +121,16 @@ function ExportAnnotations({
...
@@ -118,12 +121,16 @@ function ExportAnnotations({
e
.
preventDefault
();
e
.
preventDefault
();
try
{
try
{
const
format
=
exportFormat
.
value
;
const
annotationsToExport
=
const
annotationsToExport
=
selectedUser
?.
annotations
??
exportableAnnotations
;
selectedUser
?.
annotations
??
exportableAnnotations
;
const
filename
=
`
${
customFilename
??
defaultFilename
}.
json
`;
const
filename
=
`
${
customFilename
??
defaultFilename
}.
$
{
format
}
`;
if (format === 'json') {
const exportData =
const exportData =
annotationsExporter.build
ExportContent(annotationsToExport);
annotationsExporter.buildJSON
ExportContent(annotationsToExport);
downloadJSONFile(exportData, filename);
downloadJSONFile(exportData, filename);
}
} catch (e) {
} catch (e) {
toastMessenger.error('Exporting annotations failed');
toastMessenger.error('Exporting annotations failed');
}
}
...
...
src/sidebar/components/ShareDialog/test/ExportAnnotations-test.js
View file @
77c2259f
...
@@ -34,7 +34,7 @@ describe('ExportAnnotations', () => {
...
@@ -34,7 +34,7 @@ describe('ExportAnnotations', () => {
beforeEach
(()
=>
{
beforeEach
(()
=>
{
fakeAnnotationsExporter
=
{
fakeAnnotationsExporter
=
{
buildExportContent
:
sinon
.
stub
().
returns
({}),
build
JSON
ExportContent
:
sinon
.
stub
().
returns
({}),
};
};
fakeToastMessenger
=
{
fakeToastMessenger
=
{
error
:
sinon
.
stub
(),
error
:
sinon
.
stub
(),
...
@@ -240,9 +240,9 @@ describe('ExportAnnotations', () => {
...
@@ -240,9 +240,9 @@ describe('ExportAnnotations', () => {
submitExportForm
(
wrapper
);
submitExportForm
(
wrapper
);
assert
.
calledOnce
(
fakeAnnotationsExporter
.
buildExportContent
);
assert
.
calledOnce
(
fakeAnnotationsExporter
.
build
JSON
ExportContent
);
assert
.
calledWith
(
assert
.
calledWith
(
fakeAnnotationsExporter
.
buildExportContent
,
fakeAnnotationsExporter
.
build
JSON
ExportContent
,
annotationsToExport
,
annotationsToExport
,
);
);
assert
.
notCalled
(
fakeToastMessenger
.
error
);
assert
.
notCalled
(
fakeToastMessenger
.
error
);
...
@@ -298,9 +298,9 @@ describe('ExportAnnotations', () => {
...
@@ -298,9 +298,9 @@ describe('ExportAnnotations', () => {
submitExportForm
(
wrapper
);
submitExportForm
(
wrapper
);
assert
.
calledOnce
(
fakeAnnotationsExporter
.
buildExportContent
);
assert
.
calledOnce
(
fakeAnnotationsExporter
.
build
JSON
ExportContent
);
assert
.
calledWith
(
assert
.
calledWith
(
fakeAnnotationsExporter
.
buildExportContent
,
fakeAnnotationsExporter
.
build
JSON
ExportContent
,
selectedUserAnnotations
,
selectedUserAnnotations
,
);
);
});
});
...
@@ -326,7 +326,7 @@ describe('ExportAnnotations', () => {
...
@@ -326,7 +326,7 @@ describe('ExportAnnotations', () => {
context
(
'when exporting annotations fails'
,
()
=>
{
context
(
'when exporting annotations fails'
,
()
=>
{
it
(
'displays error toast message'
,
()
=>
{
it
(
'displays error toast message'
,
()
=>
{
fakeAnnotationsExporter
.
buildExportContent
.
throws
(
fakeAnnotationsExporter
.
build
JSON
ExportContent
.
throws
(
new
Error
(
'Error exporting'
),
new
Error
(
'Error exporting'
),
);
);
...
@@ -335,7 +335,7 @@ describe('ExportAnnotations', () => {
...
@@ -335,7 +335,7 @@ describe('ExportAnnotations', () => {
submitExportForm
(
wrapper
);
submitExportForm
(
wrapper
);
assert
.
notCalled
(
fakeDownloadJSONFile
);
assert
.
notCalled
(
fakeDownloadJSONFile
);
assert
.
calledOnce
(
fakeAnnotationsExporter
.
buildExportContent
);
assert
.
calledOnce
(
fakeAnnotationsExporter
.
build
JSON
ExportContent
);
assert
.
calledWith
(
assert
.
calledWith
(
fakeToastMessenger
.
error
,
fakeToastMessenger
.
error
,
'Exporting annotations failed'
,
'Exporting annotations failed'
,
...
...
src/sidebar/services/annotations-exporter.ts
View file @
77c2259f
...
@@ -22,7 +22,7 @@ export class AnnotationsExporter {
...
@@ -22,7 +22,7 @@ export class AnnotationsExporter {
this
.
_store
=
store
;
this
.
_store
=
store
;
}
}
buildExportContent
(
build
JSON
ExportContent
(
annotations
:
APIAnnotationData
[],
annotations
:
APIAnnotationData
[],
/* istanbul ignore next - test seam */
/* istanbul ignore next - test seam */
now
=
new
Date
(),
now
=
new
Date
(),
...
...
src/sidebar/services/test/annotations-exporter-test.js
View file @
77c2259f
...
@@ -27,7 +27,7 @@ describe('AnnotationsExporter', () => {
...
@@ -27,7 +27,7 @@ describe('AnnotationsExporter', () => {
},
},
];
];
const
result
=
exporter
.
buildExportContent
(
annotations
,
now
);
const
result
=
exporter
.
build
JSON
ExportContent
(
annotations
,
now
);
assert
.
deepEqual
(
result
,
{
assert
.
deepEqual
(
result
,
{
export_date
:
now
.
toISOString
(),
export_date
:
now
.
toISOString
(),
...
...
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