Commit 298ea35d authored by Randall Leeds's avatar Randall Leeds

Merge pull request #2080 from hypothesis/1612-hide-orphans

Hide orphan annotations in the sidebar
parents 5b861c1f 15607e16
......@@ -32,8 +32,10 @@ Annotator.prototype.setupAnnotation = (annotation) ->
console.log "Error in setupAnnotation for", annotation.id,
":", exception.stack ? exception
annotation
if annotation.target?.length and not annotation.anchors?.length
annotation.$orphan = true
annotation
# Override deleteAnnotation to deal with anchors, not highlights.
Annotator.prototype.deleteAnnotation = (annotation) ->
......
Annotator = require('annotator')
require('../monkey')
Guest = require('../guest')
assert = chai.assert
......@@ -31,6 +32,11 @@ describe 'Guest', ->
getHighlights: sandbox.stub().returns([])
getAnchors: sandbox.stub().returns([])
createAnchor: sandbox.spy (annotation, target) ->
anchor = "anchor for " + target
annotation.anchors.push anchor
result: anchor
}
Annotator.Plugin.CrossFrame = -> fakeCrossFrame
......@@ -291,3 +297,24 @@ describe 'Guest', ->
guest = createGuest()
guest.setupAnnotation({ranges: []})
assert.called(fakeCrossFrame.sync)
describe 'Annotator monkey patch', ->
describe 'setupAnnotation()', ->
it "doesn't declare annotation without targets as orphans", ->
guest = createGuest()
annotation = target: []
guest.setupAnnotation(annotation)
assert.isFalse !!annotation.$orphan
it "doesn't declare annotations with a working target as orphans", ->
guest = createGuest()
annotation = target: ["test target"]
guest.setupAnnotation(annotation)
assert.isFalse !!annotation.$orphan
it "declares annotations with broken targets as orphans", ->
guest = createGuest()
guest.anchoring.createAnchor = -> result: null
annotation = target: ["broken target"]
guest.setupAnnotation(annotation)
assert !!annotation.$orphan
......@@ -20,7 +20,7 @@ module.exports = class CrossFrame
new Discovery($window, options)
createAnnotationSync = ->
whitelist = ['$highlight', 'target', 'document', 'uri']
whitelist = ['$highlight', '$orphan', 'target', 'document', 'uri']
options =
formatter: (annotation) ->
formatted = {}
......
......@@ -70,3 +70,5 @@ module.exports = class WidgetController
$scope.hasFocus = (annotation) ->
!!($scope.focusedAnnotations ? {})[annotation?.$$tag]
$scope.notOrphan = (container) -> !container?.message?.$orphan
......@@ -40,7 +40,7 @@
ng-mouseenter="focus(child.message)"
ng-click="scrollTo(child.message)"
ng-mouseleave="focus()"
ng-repeat="child in threadRoot.children | orderBy : sort.predicate"
ng-repeat="child in threadRoot.children | filter:notOrphan | orderBy : sort.predicate"
ng-show="shouldShowThread(child) && (count('edit') || count('match') || !threadFilter.active())">
</li>
</ul>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment