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) -> ...@@ -32,8 +32,10 @@ Annotator.prototype.setupAnnotation = (annotation) ->
console.log "Error in setupAnnotation for", annotation.id, console.log "Error in setupAnnotation for", annotation.id,
":", exception.stack ? exception ":", 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. # Override deleteAnnotation to deal with anchors, not highlights.
Annotator.prototype.deleteAnnotation = (annotation) -> Annotator.prototype.deleteAnnotation = (annotation) ->
......
Annotator = require('annotator') Annotator = require('annotator')
require('../monkey')
Guest = require('../guest') Guest = require('../guest')
assert = chai.assert assert = chai.assert
...@@ -31,6 +32,11 @@ describe 'Guest', -> ...@@ -31,6 +32,11 @@ describe 'Guest', ->
getHighlights: sandbox.stub().returns([]) getHighlights: sandbox.stub().returns([])
getAnchors: 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 Annotator.Plugin.CrossFrame = -> fakeCrossFrame
...@@ -291,3 +297,24 @@ describe 'Guest', -> ...@@ -291,3 +297,24 @@ describe 'Guest', ->
guest = createGuest() guest = createGuest()
guest.setupAnnotation({ranges: []}) guest.setupAnnotation({ranges: []})
assert.called(fakeCrossFrame.sync) 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 ...@@ -20,7 +20,7 @@ module.exports = class CrossFrame
new Discovery($window, options) new Discovery($window, options)
createAnnotationSync = -> createAnnotationSync = ->
whitelist = ['$highlight', 'target', 'document', 'uri'] whitelist = ['$highlight', '$orphan', 'target', 'document', 'uri']
options = options =
formatter: (annotation) -> formatter: (annotation) ->
formatted = {} formatted = {}
......
...@@ -70,3 +70,5 @@ module.exports = class WidgetController ...@@ -70,3 +70,5 @@ module.exports = class WidgetController
$scope.hasFocus = (annotation) -> $scope.hasFocus = (annotation) ->
!!($scope.focusedAnnotations ? {})[annotation?.$$tag] !!($scope.focusedAnnotations ? {})[annotation?.$$tag]
$scope.notOrphan = (container) -> !container?.message?.$orphan
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
ng-mouseenter="focus(child.message)" ng-mouseenter="focus(child.message)"
ng-click="scrollTo(child.message)" ng-click="scrollTo(child.message)"
ng-mouseleave="focus()" 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())"> ng-show="shouldShowThread(child) && (count('edit') || count('match') || !threadFilter.active())">
</li> </li>
</ul> </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