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
e225bc09
Commit
e225bc09
authored
Aug 28, 2023
by
Alejandro Celaya
Committed by
Alejandro Celaya
Aug 29, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make sure imported annotations use the new document metadata
parent
1d26c5c6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
14 deletions
+22
-14
import-annotations.ts
src/sidebar/services/import-annotations.ts
+11
-6
import-annotations-test.js
src/sidebar/services/test/import-annotations-test.js
+11
-8
No files found.
src/sidebar/services/import-annotations.ts
View file @
e225bc09
import
type
{
Annotation
,
APIAnnotationData
}
from
'../../types/api'
;
import
type
{
Annotation
,
APIAnnotationData
}
from
'../../types/api'
;
import
{
quote
}
from
'../helpers/annotation-metadata'
;
import
{
quote
}
from
'../helpers/annotation-metadata'
;
import
type
{
SidebarStore
}
from
'../store'
;
import
type
{
SidebarStore
}
from
'../store'
;
import
type
{
Frame
}
from
'../store/modules/frames'
;
import
type
{
AnnotationsService
}
from
'./annotations'
;
import
type
{
AnnotationsService
}
from
'./annotations'
;
import
type
{
ToastMessengerService
}
from
'./toast-messenger'
;
import
type
{
ToastMessengerService
}
from
'./toast-messenger'
;
...
@@ -35,15 +36,19 @@ type ImportData = Pick<
...
@@ -35,15 +36,19 @@ type ImportData = Pick<
/**
/**
* Return a copy of `ann` that contains only fields which can be preserved by
* Return a copy of `ann` that contains only fields which can be preserved by
* an import performed on the client.
* an import performed on the client, overwriting some of them with the ones
* from current frame, if provided
*/
*/
function
getImportData
(
ann
:
APIAnnotationData
,
uri
?:
string
):
ImportData
{
function
getImportData
(
ann
:
APIAnnotationData
,
currentFrame
:
Frame
|
null
,
):
ImportData
{
return
{
return
{
target
:
ann
.
target
,
target
:
ann
.
target
,
tags
:
ann
.
tags
,
tags
:
ann
.
tags
,
text
:
ann
.
text
,
text
:
ann
.
text
,
uri
:
uri
??
ann
.
uri
,
uri
:
currentFrame
?.
uri
??
ann
.
uri
,
document
:
ann
.
document
,
document
:
currentFrame
?.
metadata
??
ann
.
document
,
extra
:
{
extra
:
{
source
:
'import'
,
source
:
'import'
,
original_id
:
ann
.
id
,
original_id
:
ann
.
id
,
...
@@ -150,7 +155,7 @@ export class ImportAnnotationsService {
...
@@ -150,7 +155,7 @@ export class ImportAnnotationsService {
this
.
_store
.
beginImport
(
anns
.
length
);
this
.
_store
.
beginImport
(
anns
.
length
);
const
existingAnns
=
this
.
_store
.
allAnnotations
();
const
existingAnns
=
this
.
_store
.
allAnnotations
();
const
current
Uri
=
this
.
_store
.
mainFrame
()?.
uri
;
const
current
Frame
=
this
.
_store
.
mainFrame
()
;
const
importAnn
=
async
(
ann
:
APIAnnotationData
):
Promise
<
ImportResult
>
=>
{
const
importAnn
=
async
(
ann
:
APIAnnotationData
):
Promise
<
ImportResult
>
=>
{
const
existingAnn
=
existingAnns
.
find
(
ex
=>
duplicateMatch
(
ann
,
ex
));
const
existingAnn
=
existingAnns
.
find
(
ex
=>
duplicateMatch
(
ann
,
ex
));
...
@@ -161,7 +166,7 @@ export class ImportAnnotationsService {
...
@@ -161,7 +166,7 @@ export class ImportAnnotationsService {
try
{
try
{
// Strip out all the fields that are ignored in an import, and overwrite
// Strip out all the fields that are ignored in an import, and overwrite
// the URI with current document's URI.
// the URI with current document's URI.
const
importData
=
getImportData
(
ann
,
current
Uri
);
const
importData
=
getImportData
(
ann
,
current
Frame
);
// Fill out the annotation with default values for the current user and
// Fill out the annotation with default values for the current user and
// group.
// group.
...
...
src/sidebar/services/test/import-annotations-test.js
View file @
e225bc09
...
@@ -13,7 +13,7 @@ describe('ImportAnnotationsService', () => {
...
@@ -13,7 +13,7 @@ describe('ImportAnnotationsService', () => {
allAnnotations
:
sinon
.
stub
().
returns
([]),
allAnnotations
:
sinon
.
stub
().
returns
([]),
beginImport
:
sinon
.
stub
(),
beginImport
:
sinon
.
stub
(),
completeImport
:
sinon
.
stub
(),
completeImport
:
sinon
.
stub
(),
mainFrame
:
sinon
.
stub
(),
mainFrame
:
sinon
.
stub
()
.
returns
(
null
)
,
};
};
fakeToastMessenger
=
{
fakeToastMessenger
=
{
...
@@ -59,13 +59,13 @@ describe('ImportAnnotationsService', () => {
...
@@ -59,13 +59,13 @@ describe('ImportAnnotationsService', () => {
}
}
/** Return the expected imported annotation for a given annotation. */
/** Return the expected imported annotation for a given annotation. */
function
importedAnnotation
(
ann
)
{
function
importedAnnotation
(
ann
,
uri
=
undefined
,
document
=
undefined
)
{
return
{
return
{
document
:
ann
.
document
,
document
:
document
??
ann
.
document
,
tags
:
ann
.
tags
,
tags
:
ann
.
tags
,
target
:
ann
.
target
,
target
:
ann
.
target
,
text
:
ann
.
text
,
text
:
ann
.
text
,
uri
:
ann
.
uri
,
uri
:
uri
??
ann
.
uri
,
extra
:
{
extra
:
{
source
:
'import'
,
source
:
'import'
,
original_id
:
ann
.
id
,
original_id
:
ann
.
id
,
...
@@ -101,9 +101,13 @@ describe('ImportAnnotationsService', () => {
...
@@ -101,9 +101,13 @@ describe('ImportAnnotationsService', () => {
});
});
});
});
it
(
'
overwrites annotation URI with current document one
'
,
async
()
=>
{
it
(
'
sets annotation URI and document metadata to match current document
'
,
async
()
=>
{
const
newUri
=
'new_document_uri'
;
const
newUri
=
'new_document_uri'
;
fakeStore
.
mainFrame
.
returns
({
uri
:
newUri
});
const
newTitle
=
'new_document_title'
;
fakeStore
.
mainFrame
.
returns
({
uri
:
newUri
,
metadata
:
{
title
:
newTitle
},
});
const
svc
=
createService
();
const
svc
=
createService
();
const
ann
=
generateAnnotation
();
const
ann
=
generateAnnotation
();
...
@@ -112,8 +116,7 @@ describe('ImportAnnotationsService', () => {
...
@@ -112,8 +116,7 @@ describe('ImportAnnotationsService', () => {
assert
.
calledWith
(
fakeAnnotationsService
.
save
,
{
assert
.
calledWith
(
fakeAnnotationsService
.
save
,
{
$tag
:
'dummy'
,
$tag
:
'dummy'
,
...
importedAnnotation
(
ann
),
...
importedAnnotation
(
ann
,
newUri
,
{
title
:
newTitle
}),
uri
:
newUri
,
});
});
});
});
...
...
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