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
2daa913f
Commit
2daa913f
authored
Aug 30, 2023
by
Alejandro Celaya
Committed by
Alejandro Celaya
Aug 30, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add defaultContentFrame store selector to fix importing to VitalSource
parent
ab8ec27d
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
58 additions
and
8 deletions
+58
-8
ImportAnnotations.tsx
src/sidebar/components/ShareDialog/ImportAnnotations.tsx
+1
-1
ImportAnnotations-test.js
...bar/components/ShareDialog/test/ImportAnnotations-test.js
+3
-3
import-annotations.ts
src/sidebar/services/import-annotations.ts
+1
-1
import-annotations-test.js
src/sidebar/services/test/import-annotations-test.js
+2
-2
frames.ts
src/sidebar/store/modules/frames.ts
+18
-1
frames-test.js
src/sidebar/store/modules/test/frames-test.js
+33
-0
No files found.
src/sidebar/components/ShareDialog/ImportAnnotations.tsx
View file @
2daa913f
...
...
@@ -143,7 +143,7 @@ function ImportAnnotations({
// (`importAnnotations` will be falsey if this is not the case).
const
importReady
=
Boolean
(
store
.
focusedGroup
()
&&
store
.
main
Frame
()
&&
store
.
defaultContent
Frame
()
&&
store
.
hasFetchedAnnotations
()
&&
!
store
.
isFetchingAnnotations
()
&&
importAnnotations
,
...
...
src/sidebar/components/ShareDialog/test/ImportAnnotations-test.js
View file @
2daa913f
...
...
@@ -23,7 +23,7 @@ describe('ImportAnnotations', () => {
isFeatureEnabled
:
sinon
.
stub
().
returns
(
true
),
hasFetchedAnnotations
:
sinon
.
stub
().
returns
(
true
),
isFetchingAnnotations
:
sinon
.
stub
().
returns
(
false
),
main
Frame
:
sinon
.
stub
().
returns
({}),
defaultContent
Frame
:
sinon
.
stub
().
returns
({}),
profile
:
sinon
.
stub
().
returns
({
userid
:
'acct:john@example.com'
}),
};
...
...
@@ -78,7 +78,7 @@ describe('ImportAnnotations', () => {
});
it
(
'disables import button if group, document or annotations are not loaded'
,
async
()
=>
{
fakeStore
.
main
Frame
.
returns
(
null
);
// Document metadata not available
fakeStore
.
defaultContent
Frame
.
returns
(
null
);
// Document metadata not available
fakeStore
.
focusedGroup
.
returns
(
null
);
// No group set
fakeStore
.
hasFetchedAnnotations
.
returns
(
false
);
// Annotations still loading
fakeStore
.
isFetchingAnnotations
.
returns
(
true
);
...
...
@@ -102,7 +102,7 @@ describe('ImportAnnotations', () => {
// to perform the import.
assert
.
isTrue
(
importDisabled
(
wrapper
));
fakeStore
.
main
Frame
.
returns
({});
// Document metadata available
fakeStore
.
defaultContent
Frame
.
returns
({});
// Document metadata available
wrapper
.
setProps
({});
assert
.
isTrue
(
importDisabled
(
wrapper
));
...
...
src/sidebar/services/import-annotations.ts
View file @
2daa913f
...
...
@@ -178,7 +178,7 @@ export class ImportAnnotationsService {
}
const
existingAnns
=
this
.
_store
.
allAnnotations
();
const
currentFrame
=
this
.
_store
.
main
Frame
();
const
currentFrame
=
this
.
_store
.
defaultContent
Frame
();
const
importAnn
=
async
(
ann
:
APIAnnotationData
):
Promise
<
ImportResult
>
=>
{
const
existingAnn
=
existingAnns
.
find
(
ex
=>
duplicateMatch
(
ann
,
ex
));
...
...
src/sidebar/services/test/import-annotations-test.js
View file @
2daa913f
...
...
@@ -18,7 +18,7 @@ describe('ImportAnnotationsService', () => {
beginImport
:
sinon
.
stub
(),
completeImport
:
sinon
.
stub
(),
focusedGroupId
:
sinon
.
stub
().
returns
(
'group-a'
),
main
Frame
:
sinon
.
stub
().
returns
(
null
),
defaultContent
Frame
:
sinon
.
stub
().
returns
(
null
),
profile
:
sinon
.
stub
().
returns
({
userid
:
'acct:foo@example.org'
,
}),
...
...
@@ -139,7 +139,7 @@ describe('ImportAnnotationsService', () => {
it
(
'sets annotation URI and document metadata to match current document'
,
async
()
=>
{
const
newUri
=
'new_document_uri'
;
const
newTitle
=
'new_document_title'
;
fakeStore
.
main
Frame
.
returns
({
fakeStore
.
defaultContent
Frame
.
returns
({
uri
:
newUri
,
metadata
:
{
title
:
newTitle
},
});
...
...
src/sidebar/store/modules/frames.ts
View file @
2daa913f
...
...
@@ -132,6 +132,9 @@ function frames(state: State) {
return
state
.
frames
;
}
const
firstFrameWithoutId
=
(
frames
:
Frame
[])
=>
frames
.
find
(
f
=>
!
f
.
id
)
||
null
;
/**
* Return the "main" frame that the sidebar is connected to.
*
...
...
@@ -147,7 +150,20 @@ const mainFrame = createSelector(
// Sub-frames will all have a "frame identifier" set. The main frame is the
// one with a `null` id.
frames
=>
frames
.
find
(
f
=>
!
f
.
id
)
||
null
,
firstFrameWithoutId
,
);
/**
* Return the default frame that annotations are assumed to be associated with,
* if they can't be matched to a more specific frame.
*
* For most document types this is the same as ({@see mainFrame}), but for
* eg. VitalSource books there is no main frame, but instead only a frame with
* the current chapter content.
*/
const
defaultContentFrame
=
createSelector
(
(
state
:
State
)
=>
state
.
frames
,
frames
=>
firstFrameWithoutId
(
frames
)
??
frames
[
0
]
??
null
,
);
function
searchUrisForFrame
(
frame
:
Frame
):
string
[]
{
...
...
@@ -208,6 +224,7 @@ export const framesModule = createStoreModule(initialState, {
getContentInfo
,
frames
,
mainFrame
,
defaultContentFrame
,
searchUris
,
},
});
src/sidebar/store/modules/test/frames-test.js
View file @
2daa913f
...
...
@@ -108,6 +108,39 @@ describe('sidebar/store/modules/frames', () => {
});
});
describe
(
'#defaultContentFrame'
,
()
=>
{
it
(
'returns `null` if no frames are connected'
,
()
=>
{
assert
.
isNull
(
store
.
defaultContentFrame
());
});
[
{
frames
:
[{
id
:
null
,
uri
:
'https://example.org'
}],
expectedFrame
:
0
,
},
{
frames
:
[
{
id
:
'iframe1'
,
uri
:
'https://foo.com/'
},
{
id
:
'iframe2'
,
uri
:
'https://foo.com/'
},
{
id
:
null
,
uri
:
'https://example.org'
},
],
expectedFrame
:
2
,
},
{
frames
:
[
{
id
:
'iframe1'
,
uri
:
'https://foo.com/'
},
{
id
:
'iframe2'
,
uri
:
'https://example.org'
},
],
expectedFrame
:
0
,
},
].
forEach
(({
frames
,
expectedFrame
})
=>
{
it
(
'returns the main frame or first connected frame'
,
()
=>
{
frames
.
forEach
(
frame
=>
store
.
connectFrame
(
frame
));
assert
.
equal
(
store
.
defaultContentFrame
(),
frames
[
expectedFrame
]);
});
});
});
describe
(
'#searchUris'
,
()
=>
{
[
{
...
...
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