Commit ab7ceae1 authored by Nick Stenning's avatar Nick Stenning

Merge pull request #2542 from hypothesis/2525-new-annotations-disappearing

Change $anchored -> $orphan
parents 530466ae 4102d301
...@@ -197,10 +197,10 @@ module.exports = class Guest extends Annotator ...@@ -197,10 +197,10 @@ module.exports = class Guest extends Annotator
sync = (anchors) -> sync = (anchors) ->
# Store the results of anchoring. # Store the results of anchoring.
annotation.$anchored = anchors.length is 0 annotation.$orphan = anchors.length > 0
for anchor in anchors for anchor in anchors
if anchor.range? if anchor.range?
annotation.$anchored = true annotation.$orphan = false
break break
# Add the anchors for this annotation to instance storage. # Add the anchors for this annotation to instance storage.
......
...@@ -249,27 +249,27 @@ describe 'Guest', -> ...@@ -249,27 +249,27 @@ describe 'Guest', ->
afterEach -> afterEach ->
document.body.removeChild(el) document.body.removeChild(el)
it "declares annotations without targets as anchored", (done) -> it "doesn't declare annotations without targets as orphans", (done) ->
guest = createGuest() guest = createGuest()
annotation = target: [] annotation = target: []
guest.anchor(annotation).then -> guest.anchor(annotation).then ->
assert.isTrue(annotation.$anchored) assert.isFalse(annotation.$orphan)
.then(done, done) .then(done, done)
it "declares annotations with a working target anchored", (done) -> it "doesn't declare annotations with a working target orphans", (done) ->
guest = createGuest() guest = createGuest()
annotation = target: [{selector: "test"}] annotation = target: [{selector: "test"}]
sandbox.stub(anchoring, 'anchor').returns(Promise.resolve(range)) sandbox.stub(anchoring, 'anchor').returns(Promise.resolve(range))
guest.anchor(annotation).then -> guest.anchor(annotation).then ->
assert.isTrue(annotation.$anchored) assert.isFalse(annotation.$orphan)
.then(done, done) .then(done, done)
it "declares annotations with broken targets not anchored", (done) -> it "declares annotations with broken targets as orphans", (done) ->
guest = createGuest() guest = createGuest()
annotation = target: [{selector: 'broken selector'}] annotation = target: [{selector: 'broken selector'}]
sandbox.stub(anchoring, 'anchor').returns(Promise.reject()) sandbox.stub(anchoring, 'anchor').returns(Promise.reject())
guest.anchor(annotation).then -> guest.anchor(annotation).then ->
assert.isFalse(annotation.$anchored) assert.isTrue(annotation.$orphan)
.then(done, done) .then(done, done)
it 'updates the cross frame and bucket bar plugins', (done) -> it 'updates the cross frame and bucket bar plugins', (done) ->
......
...@@ -18,7 +18,7 @@ module.exports = class CrossFrame ...@@ -18,7 +18,7 @@ module.exports = class CrossFrame
new Discovery($window, options) new Discovery($window, options)
createAnnotationSync = -> createAnnotationSync = ->
whitelist = ['$anchored', '$highlight', 'target', 'document', 'uri'] whitelist = ['$orphan', '$highlight', 'target', 'document', 'uri']
options = options =
formatter: (annotation) -> formatter: (annotation) ->
formatted = {} formatted = {}
......
...@@ -86,3 +86,34 @@ describe 'WidgetController', -> ...@@ -86,3 +86,34 @@ describe 'WidgetController', ->
assert.calledWith(loadSpy, [40..59]) assert.calledWith(loadSpy, [40..59])
assert.calledWith(loadSpy, [60..79]) assert.calledWith(loadSpy, [60..79])
assert.calledWith(loadSpy, [80..99]) assert.calledWith(loadSpy, [80..99])
describe 'shouldShowThread()', ->
it 'returns false for orphan annotations', ->
# Turn the 'show_unanchored_annotations' feature off.
$scope.feature = -> false
container =
message:
$orphan: true
assert($scope.shouldShowThread(container) is false)
it 'returns true for non-orphan annotations', ->
# Turn the 'show_unanchored_annotations' feature off.
$scope.feature = -> false
container =
message:
$orphan: false
assert($scope.shouldShowThread(container) is true)
it 'returns true for orphan annotations if show_unanchored_annotations is on', ->
# Turn the 'show_unanchored_annotations' feature on.
$scope.feature = -> true
container =
message:
$orphan: true
assert($scope.shouldShowThread(container) is true)
...@@ -58,27 +58,14 @@ module.exports = class WidgetController ...@@ -58,27 +58,14 @@ module.exports = class WidgetController
crossframe.call('scrollToAnnotation', annotation.$$tag) crossframe.call('scrollToAnnotation', annotation.$$tag)
$scope.shouldShowThread = (container) -> $scope.shouldShowThread = (container) ->
# Show stubs # Show regardless of $orphan if that feature is turned on
if not container?.message?
return true
# Show replies
if container.message.references?.length
return true
# Show selected threads
if annotationUI.hasSelectedAnnotations()
return annotationUI.isAnnotationSelected(container.message.id)
# Show regardless of $anchored if that feature is turned on
if $scope.feature('show_unanchored_annotations') if $scope.feature('show_unanchored_annotations')
return true return true
# Show anchored threads if container?.message?.$orphan == true
if container.message.$anchored return false
return true
return false return true
$scope.hasFocus = (annotation) -> $scope.hasFocus = (annotation) ->
!!($scope.focusedAnnotations ? {})[annotation?.$$tag] !!($scope.focusedAnnotations ? {})[annotation?.$$tag]
...@@ -47,6 +47,6 @@ ...@@ -47,6 +47,6 @@
</ul> </ul>
<footer class="thread-anchor-notice" <footer class="thread-anchor-notice"
ng-if="feature('show_unanchored_annotations') && isSidebar && !vm.container.message.$anchored"> ng-if="feature('show_unanchored_annotations') && isSidebar && vm.container.message.$orphan">
<em>We can't find the exact position of this annotation.</em> <em>We can't find the exact position of this annotation.</em>
</footer> </footer>
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