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