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
202e8670
Commit
202e8670
authored
Aug 25, 2023
by
Alejandro Celaya
Committed by
Alejandro Celaya
Aug 25, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Overwrite imported annotations URI with target document one
parent
da7b94c9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
4 deletions
+23
-4
import-annotations.ts
src/sidebar/services/import-annotations.ts
+6
-4
import-annotations-test.js
src/sidebar/services/test/import-annotations-test.js
+17
-0
No files found.
src/sidebar/services/import-annotations.ts
View file @
202e8670
...
...
@@ -37,12 +37,12 @@ type ImportData = Pick<
* Return a copy of `ann` that contains only fields which can be preserved by
* an import performed on the client.
*/
function
getImportData
(
ann
:
APIAnnotationData
):
ImportData
{
function
getImportData
(
ann
:
APIAnnotationData
,
uri
?:
string
):
ImportData
{
return
{
target
:
ann
.
target
,
tags
:
ann
.
tags
,
text
:
ann
.
text
,
uri
:
ann
.
uri
,
uri
:
uri
??
ann
.
uri
,
document
:
ann
.
document
,
extra
:
{
source
:
'import'
,
...
...
@@ -150,6 +150,7 @@ export class ImportAnnotationsService {
this
.
_store
.
beginImport
(
anns
.
length
);
const
existingAnns
=
this
.
_store
.
allAnnotations
();
const
currentUri
=
this
.
_store
.
mainFrame
()?.
uri
;
const
importAnn
=
async
(
ann
:
APIAnnotationData
):
Promise
<
ImportResult
>
=>
{
const
existingAnn
=
existingAnns
.
find
(
ex
=>
duplicateMatch
(
ann
,
ex
));
...
...
@@ -158,8 +159,9 @@ export class ImportAnnotationsService {
}
try
{
// Strip out all the fields that are ignored in an import.
const
importData
=
getImportData
(
ann
);
// Strip out all the fields that are ignored in an import, and overwrite
// the URI with current document's URI.
const
importData
=
getImportData
(
ann
,
currentUri
);
// Fill out the annotation with default values for the current user and
// group.
...
...
src/sidebar/services/test/import-annotations-test.js
View file @
202e8670
...
...
@@ -13,6 +13,7 @@ describe('ImportAnnotationsService', () => {
allAnnotations
:
sinon
.
stub
().
returns
([]),
beginImport
:
sinon
.
stub
(),
completeImport
:
sinon
.
stub
(),
mainFrame
:
sinon
.
stub
(),
};
fakeToastMessenger
=
{
...
...
@@ -100,6 +101,22 @@ describe('ImportAnnotationsService', () => {
});
});
it
(
'overwrites annotation URI with current document one'
,
async
()
=>
{
const
newUri
=
'new_document_uri'
;
fakeStore
.
mainFrame
.
returns
({
uri
:
newUri
});
const
svc
=
createService
();
const
ann
=
generateAnnotation
();
await
svc
.
import
([
ann
]);
assert
.
calledWith
(
fakeAnnotationsService
.
save
,
{
$tag
:
'dummy'
,
...
ann
,
uri
:
newUri
,
});
});
it
(
'can save many annotations'
,
async
()
=>
{
const
svc
=
createService
();
const
anns
=
[];
...
...
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