Commit 719f2284 authored by Randall Leeds's avatar Randall Leeds

Merge pull request #2034 from hypothesis/2033-fix-focusing

Fix sidebar's focusing on annotation cards
parents 9020e2d5 abe12c47
...@@ -13,7 +13,7 @@ createAnnotationUI = -> ...@@ -13,7 +13,7 @@ createAnnotationUI = ->
visibleHighlights: false visibleHighlights: false
# Contains a map of annotation id:true pairs. # Contains a map of annotation tag:true pairs.
focusedAnnotationMap: null focusedAnnotationMap: null
# Contains a map of annotation id:true pairs. # Contains a map of annotation id:true pairs.
...@@ -28,7 +28,7 @@ createAnnotationUI = -> ...@@ -28,7 +28,7 @@ createAnnotationUI = ->
### ###
focusAnnotations: (annotations) -> focusAnnotations: (annotations) ->
selection = {} selection = {}
selection[id] = true for {id} in annotations selection[$$tag] = true for {$$tag} in annotations
@focusedAnnotationMap = value(selection) @focusedAnnotationMap = value(selection)
###* ###*
......
...@@ -251,7 +251,7 @@ class ViewerController ...@@ -251,7 +251,7 @@ class ViewerController
true true
$scope.hasFocus = (annotation) -> $scope.hasFocus = (annotation) ->
annotation?.$$tag in ($scope.focusedAnnotations ? []) !!($scope.focusedAnnotations ? {})[annotation?.$$tag]
angular.module('h') angular.module('h')
.controller('AppController', AppController) .controller('AppController', AppController)
......
...@@ -17,25 +17,25 @@ describe 'AnnotationUI', -> ...@@ -17,25 +17,25 @@ describe 'AnnotationUI', ->
describe '.focusAnnotations()', -> describe '.focusAnnotations()', ->
it 'adds the passed annotations to the focusedAnnotationMap', -> it 'adds the passed annotations to the focusedAnnotationMap', ->
annotationUI.focusAnnotations([{id: 1}, {id: 2}, {id: 3}]) annotationUI.focusAnnotations([{$$tag: 1}, {$$tag: 2}, {$$tag: 3}])
assert.deepEqual(annotationUI.focusedAnnotationMap, { assert.deepEqual(annotationUI.focusedAnnotationMap, {
1: true, 2: true, 3: true 1: true, 2: true, 3: true
}) })
it 'replaces any annotations originally in the map', -> it 'replaces any annotations originally in the map', ->
annotationUI.focusedAnnotationMap = {1: true} annotationUI.focusedAnnotationMap = {1: true}
annotationUI.focusAnnotations([{id: 2}, {id: 3}]) annotationUI.focusAnnotations([{$$tag: 2}, {$$tag: 3}])
assert.deepEqual(annotationUI.focusedAnnotationMap, { assert.deepEqual(annotationUI.focusedAnnotationMap, {
2: true, 3: true 2: true, 3: true
}) })
it 'does not modify the original map object', -> it 'does not modify the original map object', ->
orig = annotationUI.focusedAnnotationMap = {1: true} orig = annotationUI.focusedAnnotationMap = {1: true}
annotationUI.focusAnnotations([{id: 2}, {id: 3}]) annotationUI.focusAnnotations([{$$tag: 2}, {$$tag: 3}])
assert.notEqual(annotationUI.focusedAnnotationMap, orig) assert.notEqual(annotationUI.focusedAnnotationMap, orig)
it 'nulls the map if no annotations are focused', -> it 'nulls the map if no annotations are focused', ->
orig = annotationUI.focusedAnnotationMap = {1: true} orig = annotationUI.focusedAnnotationMap = {$$tag: true}
annotationUI.focusAnnotations([]) annotationUI.focusAnnotations([])
assert.isNull(annotationUI.focusedAnnotationMap) assert.isNull(annotationUI.focusedAnnotationMap)
......
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