Commit 6f571e9f authored by Hannah Stepanek's avatar Hannah Stepanek

Replace clearSelection w/ store.clearSelection

Use clearSelection from the store instead of from sidebar-content.
parent 83851021
...@@ -45,13 +45,16 @@ function SearchStatusBarController(store, rootThread) { ...@@ -45,13 +45,16 @@ function SearchStatusBarController(store, rootThread) {
this.filterActive = function() { this.filterActive = function() {
return !!store.getState().filterQuery; return !!store.getState().filterQuery;
}; };
this.onClearSelection = function() {
store.clearSelection();
};
} }
module.exports = { module.exports = {
controller: SearchStatusBarController, controller: SearchStatusBarController,
controllerAs: 'vm', controllerAs: 'vm',
bindings: { bindings: {
onClearSelection: '&',
selectedTab: '<', selectedTab: '<',
totalAnnotations: '<', totalAnnotations: '<',
totalNotes: '<', totalNotes: '<',
......
...@@ -4,7 +4,6 @@ const SearchClient = require('../search-client'); ...@@ -4,7 +4,6 @@ const SearchClient = require('../search-client');
const events = require('../events'); const events = require('../events');
const isThirdPartyService = require('../util/is-third-party-service'); const isThirdPartyService = require('../util/is-third-party-service');
const tabs = require('../tabs'); const tabs = require('../tabs');
const uiConstants = require('../ui-constants');
/** /**
* Returns the group ID of the first annotation in `results` whose * Returns the group ID of the first annotation in `results` whose
...@@ -315,21 +314,6 @@ function SidebarContentController( ...@@ -315,21 +314,6 @@ function SidebarContentController(
!this.isLoading() && !!selectedID && store.annotationExists(selectedID) !this.isLoading() && !!selectedID && store.annotationExists(selectedID)
); );
}; };
this.clearSelection = function() {
let selectedTab = store.getState().selectedTab;
if (
!store.getState().selectedTab ||
store.getState().selectedTab === uiConstants.TAB_ORPHANS
) {
selectedTab = uiConstants.TAB_ANNOTATIONS;
}
store.clearSelectedAnnotations();
store.selectTab(selectedTab);
store.clearDirectLinkedGroupFetchFailed();
store.clearDirectLinkedIds();
};
} }
module.exports = { module.exports = {
......
...@@ -24,6 +24,7 @@ describe('searchStatusBar', () => { ...@@ -24,6 +24,7 @@ describe('searchStatusBar', () => {
clearSelectedAnnotations: sinon.stub(), clearSelectedAnnotations: sinon.stub(),
clearDirectLinkedGroupFetchFailed: sinon.stub(), clearDirectLinkedGroupFetchFailed: sinon.stub(),
clearDirectLinkedIds: sinon.stub(), clearDirectLinkedIds: sinon.stub(),
clearSelection: sinon.stub(),
}; };
angular.mock.module('app', { angular.mock.module('app', {
store: fakeStore, store: fakeStore,
......
...@@ -5,7 +5,6 @@ const EventEmitter = require('tiny-emitter'); ...@@ -5,7 +5,6 @@ const EventEmitter = require('tiny-emitter');
const events = require('../../events'); const events = require('../../events');
const sidebarContent = require('../sidebar-content'); const sidebarContent = require('../sidebar-content');
const uiConstants = require('../../ui-constants');
const util = require('../../directive/test/util'); const util = require('../../directive/test/util');
let searchClients; let searchClients;
...@@ -187,47 +186,6 @@ describe('sidebar.components.sidebar-content', function() { ...@@ -187,47 +186,6 @@ describe('sidebar.components.sidebar-content', function() {
return sandbox.restore(); return sandbox.restore();
}); });
describe('clearSelection', () => {
it('sets selectedTab to Annotations tab if selectedTab is null', () => {
store.selectTab(uiConstants.TAB_ORPHANS);
$scope.$digest();
ctrl.clearSelection();
assert.equal(store.getState().selectedTab, uiConstants.TAB_ANNOTATIONS);
});
it('sets selectedTab to Annotations tab if selectedTab is set to orphans', () => {
store.selectTab(uiConstants.TAB_ORPHANS);
$scope.$digest();
ctrl.clearSelection();
assert.equal(store.getState().selectedTab, uiConstants.TAB_ANNOTATIONS);
});
it('clears selected annotations', () => {
ctrl.clearSelection();
assert.equal(store.getState().selectedAnnotationMap, null);
assert.equal(store.getState().filterQuery, null);
});
it('clears the directLinkedGroupFetchFailed state', () => {
store.setDirectLinkedGroupFetchFailed();
ctrl.clearSelection();
assert.isFalse(store.getState().directLinkedGroupFetchFailed);
});
it('clears the direct linked IDs in the store', () => {
ctrl.clearSelection();
assert.equal(store.getState().directLinkedAnnotationId, null);
assert.equal(store.getState().directLinkedGroupId, null);
});
});
describe('showSelectedTabs', () => { describe('showSelectedTabs', () => {
beforeEach(() => { beforeEach(() => {
setFrames([{ uri: 'http://www.example.com' }]); setFrames([{ uri: 'http://www.example.com' }]);
......
...@@ -45,6 +45,7 @@ const threadFixtures = immutable({ ...@@ -45,6 +45,7 @@ const threadFixtures = immutable({
}); });
let fakeVirtualThread; let fakeVirtualThread;
let fakeStore;
const fakeSettings = {}; const fakeSettings = {};
class FakeVirtualThreadList extends EventEmitter { class FakeVirtualThreadList extends EventEmitter {
...@@ -86,7 +87,6 @@ describe('threadList', function() { ...@@ -86,7 +87,6 @@ describe('threadList', function() {
function createThreadList(inputs) { function createThreadList(inputs) {
const defaultInputs = { const defaultInputs = {
thread: threadFixtures.thread, thread: threadFixtures.thread,
onClearSelection: sinon.stub(),
onForceVisible: sinon.stub(), onForceVisible: sinon.stub(),
onFocus: sinon.stub(), onFocus: sinon.stub(),
onSelect: sinon.stub(), onSelect: sinon.stub(),
...@@ -126,6 +126,10 @@ describe('threadList', function() { ...@@ -126,6 +126,10 @@ describe('threadList', function() {
} }
before(function() { before(function() {
fakeStore = {
clearSelection: sinon.stub(),
};
angular.module('app', []).component('threadList', threadList); angular.module('app', []).component('threadList', threadList);
}); });
...@@ -133,6 +137,7 @@ describe('threadList', function() { ...@@ -133,6 +137,7 @@ describe('threadList', function() {
angular.mock.module('app', { angular.mock.module('app', {
VirtualThreadList: FakeVirtualThreadList, VirtualThreadList: FakeVirtualThreadList,
settings: fakeSettings, settings: fakeSettings,
store: fakeStore,
}); });
threadListContainers = []; threadListContainers = [];
}); });
...@@ -201,13 +206,12 @@ describe('threadList', function() { ...@@ -201,13 +206,12 @@ describe('threadList', function() {
}); });
it('clears the selection', function() { it('clears the selection', function() {
const inputs = { onClearSelection: sinon.stub() }; const element = createThreadList();
const element = createThreadList(inputs);
element.scope.$broadcast( element.scope.$broadcast(
events.BEFORE_ANNOTATION_CREATED, events.BEFORE_ANNOTATION_CREATED,
annotFixtures.annotation annotFixtures.annotation
); );
assert.called(inputs.onClearSelection); assert.called(fakeStore.clearSelection);
}); });
}); });
......
...@@ -49,7 +49,13 @@ const virtualThreadOptions = { ...@@ -49,7 +49,13 @@ const virtualThreadOptions = {
}; };
// @ngInject // @ngInject
function ThreadListController($element, $scope, settings, VirtualThreadList) { function ThreadListController(
$element,
$scope,
settings,
store,
VirtualThreadList
) {
// `visibleThreads` keeps track of the subset of all threads matching the // `visibleThreads` keeps track of the subset of all threads matching the
// current filters which are in or near the viewport and the view then renders // current filters which are in or near the viewport and the view then renders
// only those threads, using placeholders above and below the visible threads // only those threads, using placeholders above and below the visible threads
...@@ -162,7 +168,7 @@ function ThreadListController($element, $scope, settings, VirtualThreadList) { ...@@ -162,7 +168,7 @@ function ThreadListController($element, $scope, settings, VirtualThreadList) {
if (annotation.$highlight || metadata.isReply(annotation)) { if (annotation.$highlight || metadata.isReply(annotation)) {
return; return;
} }
self.onClearSelection(); store.clearSelection();
scrollIntoView(annotation.$tag); scrollIntoView(annotation.$tag);
}); });
...@@ -191,8 +197,6 @@ module.exports = { ...@@ -191,8 +197,6 @@ module.exports = {
onSelect: '&', onSelect: '&',
/** Called when a user toggles the expansion state of an annotation thread. */ /** Called when a user toggles the expansion state of an annotation thread. */
onChangeCollapsed: '&', onChangeCollapsed: '&',
/** Called to clear the current selection. */
onClearSelection: '&',
}, },
template: require('../templates/thread-list.html'), template: require('../templates/thread-list.html'),
}; };
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
<search-status-bar <search-status-bar
ng-show="!vm.isLoading()" ng-show="!vm.isLoading()"
on-clear-selection="vm.clearSelection()"
selected-tab="vm.selectedTab" selected-tab="vm.selectedTab"
total-annotations="vm.totalAnnotations" total-annotations="vm.totalAnnotations"
total-notes="vm.totalNotes"> total-notes="vm.totalNotes">
...@@ -40,7 +39,6 @@ ...@@ -40,7 +39,6 @@
<thread-list <thread-list
on-change-collapsed="vm.setCollapsed(id, collapsed)" on-change-collapsed="vm.setCollapsed(id, collapsed)"
on-clear-selection="vm.clearSelection()"
on-focus="vm.focus(annotation)" on-focus="vm.focus(annotation)"
on-select="vm.scrollTo(annotation)" on-select="vm.scrollTo(annotation)"
show-document-info="false" show-document-info="false"
......
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