Commit 169f4689 authored by Hannah Stepanek's avatar Hannah Stepanek

Use store rather than groups to get focusedGroupId

Instead of going through a layer of indirection (aka the groups
service) to get the focusedGroupId use the store directly.
parent fd46c7d8
...@@ -233,16 +233,20 @@ function SidebarContentController( ...@@ -233,16 +233,20 @@ function SidebarContentController(
// Re-fetch annotations when focused group, logged-in user or connected frames // Re-fetch annotations when focused group, logged-in user or connected frames
// change. // change.
$scope.$watch( $scope.$watch(
() => [groups.focused(), store.profile().userid, ...store.searchUris()], () => [
([currentGroup], [prevGroup]) => { store.focusedGroupId(),
if (!currentGroup) { store.profile().userid,
// When switching accounts, groups are cleared and so the focused group ...store.searchUris(),
],
([currentGroupId], [prevGroupId]) => {
if (!currentGroupId) {
// When switching accounts, groups are cleared and so the focused group id
// will be null for a brief period of time. // will be null for a brief period of time.
store.clearSelectedAnnotations(); store.clearSelectedAnnotations();
return; return;
} }
if (!prevGroup || currentGroup.id !== prevGroup.id) { if (!prevGroupId || currentGroupId !== prevGroupId) {
// The focused group may be changed during loading annotations as a result // The focused group may be changed during loading annotations as a result
// of switching to the group containing a direct-linked annotation. // of switching to the group containing a direct-linked annotation.
// //
......
...@@ -168,6 +168,10 @@ describe('sidebar.components.sidebar-content', function() { ...@@ -168,6 +168,10 @@ describe('sidebar.components.sidebar-content', function() {
$scope = $rootScope.$new(); $scope = $rootScope.$new();
store = _store_; store = _store_;
store.updateFrameAnnotationFetchStatus = sinon.stub(); store.updateFrameAnnotationFetchStatus = sinon.stub();
store.clearGroups();
store.loadGroups([{ id: 'group-id' }]);
store.focusGroup('group-id');
ctrl = $componentController( ctrl = $componentController(
'sidebarContent', 'sidebarContent',
{ $scope: $scope }, { $scope: $scope },
...@@ -491,15 +495,12 @@ describe('sidebar.components.sidebar-content', function() { ...@@ -491,15 +495,12 @@ describe('sidebar.components.sidebar-content', function() {
$scope.$digest(); $scope.$digest();
}); });
function changeGroup() {
fakeGroups.focused.returns({ id: 'different-group' });
$scope.$digest();
}
it('should load annotations for the new group', () => { it('should load annotations for the new group', () => {
const loadSpy = fakeAnnotationMapper.loadAnnotations; const loadSpy = fakeAnnotationMapper.loadAnnotations;
store.loadGroups([{ id: 'different-group' }]);
store.focusGroup('different-group');
changeGroup(); $scope.$digest();
assert.calledWith(fakeAnnotationMapper.unloadAnnotations, [ assert.calledWith(fakeAnnotationMapper.unloadAnnotations, [
sinon.match({ id: '123' }), sinon.match({ id: '123' }),
...@@ -511,8 +512,10 @@ describe('sidebar.components.sidebar-content', function() { ...@@ -511,8 +512,10 @@ describe('sidebar.components.sidebar-content', function() {
it('should clear the selection', () => { it('should clear the selection', () => {
store.selectAnnotations(['123']); store.selectAnnotations(['123']);
store.loadGroups([{ id: 'different-group' }]);
store.focusGroup('different-group');
changeGroup(); $scope.$digest();
assert.isFalse(store.hasSelectedAnnotations()); assert.isFalse(store.hasSelectedAnnotations());
}); });
......
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