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
e6aadd79
Commit
e6aadd79
authored
Jan 08, 2020
by
Lyza Danger Gardner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add `isHighlight` util function
parent
34d63c81
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
91 additions
and
1 deletion
+91
-1
annotation-fixtures.js
src/sidebar/test/annotation-fixtures.js
+1
-1
annotation-metadata.js
src/sidebar/util/annotation-metadata.js
+38
-0
annotation-metadata-test.js
src/sidebar/util/test/annotation-metadata-test.js
+52
-0
No files found.
src/sidebar/test/annotation-fixtures.js
View file @
e6aadd79
...
@@ -113,7 +113,7 @@ function oldHighlight() {
...
@@ -113,7 +113,7 @@ function oldHighlight() {
return
{
return
{
id
:
'annotation_id'
,
id
:
'annotation_id'
,
$highlight
:
undefined
,
$highlight
:
undefined
,
target
:
[
'foo'
,
'bar'
],
target
:
[
{
source
:
'source'
,
selector
:
[]
}
],
references
:
[],
references
:
[],
text
:
''
,
text
:
''
,
tags
:
[],
tags
:
[],
...
...
src/sidebar/util/annotation-metadata.js
View file @
e6aadd79
...
@@ -149,6 +149,43 @@ function isWaitingToAnchor(annotation) {
...
@@ -149,6 +149,43 @@ function isWaitingToAnchor(annotation) {
);
);
}
}
/**
* Is this annotation a highlight?
*
* Highlights are generally identifiable by having no text content AND no tags,
* but there is some nuance.
*
* @param {Object} annotation
* @return {boolean}
*/
function
isHighlight
(
annotation
)
{
// `$highlight` is an ephemeral attribute set by the `annotator` on new
// annotation objects (created by clicking the "highlight" button).
// It is not persisted and cannot be relied upon, but if it IS present,
// this is definitely a highlight (one which is not yet saved).
if
(
annotation
.
$highlight
)
{
return
true
;
}
if
(
isNew
(
annotation
))
{
// For new (unsaved-to-service) annotations, unless they have a truthy
// `$highlight` attribute, we don't know yet if they are a highlight.
return
false
;
}
// Note that it is possible to end up with an empty (no `text`) annotation
// that is not a highlight by adding at least one tag—thus, it is necessary
// to check for the existence of tags as well as text content.
return
(
!
isPageNote
(
annotation
)
&&
!
isReply
(
annotation
)
&&
!
annotation
.
hidden
&&
// A hidden annotation has some form of objectionable content
!
annotation
.
text
&&
!
(
annotation
.
tags
&&
annotation
.
tags
.
length
)
);
}
/** Return `true` if the given annotation is an orphan. */
/** Return `true` if the given annotation is an orphan. */
function
isOrphan
(
annotation
)
{
function
isOrphan
(
annotation
)
{
return
hasSelector
(
annotation
)
&&
annotation
.
$orphan
;
return
hasSelector
(
annotation
)
&&
annotation
.
$orphan
;
...
@@ -220,6 +257,7 @@ module.exports = {
...
@@ -220,6 +257,7 @@ module.exports = {
domainAndTitle
:
domainAndTitle
,
domainAndTitle
:
domainAndTitle
,
flagCount
:
flagCount
,
flagCount
:
flagCount
,
isAnnotation
:
isAnnotation
,
isAnnotation
:
isAnnotation
,
isHighlight
:
isHighlight
,
isNew
:
isNew
,
isNew
:
isNew
,
isOrphan
:
isOrphan
,
isOrphan
:
isOrphan
,
isPageNote
:
isPageNote
,
isPageNote
:
isPageNote
,
...
...
src/sidebar/util/test/annotation-metadata-test.js
View file @
e6aadd79
...
@@ -234,6 +234,58 @@ describe('annotation-metadata', function() {
...
@@ -234,6 +234,58 @@ describe('annotation-metadata', function() {
});
});
});
});
describe
(
'.isHighlight'
,
()
=>
{
[
{
annotation
:
fixtures
.
newEmptyAnnotation
(),
expect
:
false
,
desc
:
'new, empty annotation'
,
},
{
annotation
:
fixtures
.
newReply
(),
expect
:
false
,
desc
:
'new, reply annotation'
,
},
{
annotation
:
fixtures
.
newAnnotation
(),
expect
:
false
,
desc
:
'new, with some text'
,
},
{
annotation
:
fixtures
.
newHighlight
(),
expect
:
true
,
desc
:
'new, marked as $highlight'
,
},
{
annotation
:
fixtures
.
oldAnnotation
(),
expect
:
false
,
desc
:
'pre-existing annotation'
,
},
{
annotation
:
fixtures
.
oldHighlight
(),
expect
:
true
,
desc
:
'pre-existing higlight'
,
},
{
annotation
:
fixtures
.
oldPageNote
(),
expect
:
false
,
desc
:
'pre-existing page note'
,
},
{
annotation
:
fixtures
.
oldReply
(),
expect
:
false
,
desc
:
'pre-existing reply'
,
},
].
forEach
(
testcase
=>
{
it
(
`returns
${
testcase
.
expect
}
for isHighlight when annotation is:
${
testcase
.
desc
}
`
,
()
=>
{
assert
.
equal
(
annotationMetadata
.
isHighlight
(
testcase
.
annotation
),
testcase
.
expect
);
});
});
});
describe
(
'.isPageNote'
,
function
()
{
describe
(
'.isPageNote'
,
function
()
{
it
(
'returns true for an annotation with an empty target'
,
function
()
{
it
(
'returns true for an annotation with an empty target'
,
function
()
{
assert
.
isTrue
(
assert
.
isTrue
(
...
...
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