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) {
this.filterActive = function() {
return !!store.getState().filterQuery;
};
this.onClearSelection = function() {
store.clearSelection();
};
}
module.exports = {
controller: SearchStatusBarController,
controllerAs: 'vm',
bindings: {
onClearSelection: '&',
selectedTab: '<',
totalAnnotations: '<',
totalNotes: '<',
......
......@@ -4,7 +4,6 @@ const SearchClient = require('../search-client');
const events = require('../events');
const isThirdPartyService = require('../util/is-third-party-service');
const tabs = require('../tabs');
const uiConstants = require('../ui-constants');
/**
* Returns the group ID of the first annotation in `results` whose
......@@ -315,21 +314,6 @@ function SidebarContentController(
!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 = {
......
......@@ -24,6 +24,7 @@ describe('searchStatusBar', () => {
clearSelectedAnnotations: sinon.stub(),
clearDirectLinkedGroupFetchFailed: sinon.stub(),
clearDirectLinkedIds: sinon.stub(),
clearSelection: sinon.stub(),
};
angular.mock.module('app', {
store: fakeStore,
......
......@@ -5,7 +5,6 @@ const EventEmitter = require('tiny-emitter');
const events = require('../../events');
const sidebarContent = require('../sidebar-content');
const uiConstants = require('../../ui-constants');
const util = require('../../directive/test/util');
let searchClients;
......@@ -187,47 +186,6 @@ describe('sidebar.components.sidebar-content', function() {
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', () => {
beforeEach(() => {
setFrames([{ uri: 'http://www.example.com' }]);
......
......@@ -45,6 +45,7 @@ const threadFixtures = immutable({
});
let fakeVirtualThread;
let fakeStore;
const fakeSettings = {};
class FakeVirtualThreadList extends EventEmitter {
......@@ -86,7 +87,6 @@ describe('threadList', function() {
function createThreadList(inputs) {
const defaultInputs = {
thread: threadFixtures.thread,
onClearSelection: sinon.stub(),
onForceVisible: sinon.stub(),
onFocus: sinon.stub(),
onSelect: sinon.stub(),
......@@ -126,6 +126,10 @@ describe('threadList', function() {
}
before(function() {
fakeStore = {
clearSelection: sinon.stub(),
};
angular.module('app', []).component('threadList', threadList);
});
......@@ -133,6 +137,7 @@ describe('threadList', function() {
angular.mock.module('app', {
VirtualThreadList: FakeVirtualThreadList,
settings: fakeSettings,
store: fakeStore,
});
threadListContainers = [];
});
......@@ -201,13 +206,12 @@ describe('threadList', function() {
});
it('clears the selection', function() {
const inputs = { onClearSelection: sinon.stub() };
const element = createThreadList(inputs);
const element = createThreadList();
element.scope.$broadcast(
events.BEFORE_ANNOTATION_CREATED,
annotFixtures.annotation
);
assert.called(inputs.onClearSelection);
assert.called(fakeStore.clearSelection);
});
});
......
......@@ -49,7 +49,13 @@ const virtualThreadOptions = {
};
// @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
// 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
......@@ -162,7 +168,7 @@ function ThreadListController($element, $scope, settings, VirtualThreadList) {
if (annotation.$highlight || metadata.isReply(annotation)) {
return;
}
self.onClearSelection();
store.clearSelection();
scrollIntoView(annotation.$tag);
});
......@@ -191,8 +197,6 @@ module.exports = {
onSelect: '&',
/** Called when a user toggles the expansion state of an annotation thread. */
onChangeCollapsed: '&',
/** Called to clear the current selection. */
onClearSelection: '&',
},
template: require('../templates/thread-list.html'),
};
......@@ -10,7 +10,6 @@
<search-status-bar
ng-show="!vm.isLoading()"
on-clear-selection="vm.clearSelection()"
selected-tab="vm.selectedTab"
total-annotations="vm.totalAnnotations"
total-notes="vm.totalNotes">
......@@ -40,7 +39,6 @@
<thread-list
on-change-collapsed="vm.setCollapsed(id, collapsed)"
on-clear-selection="vm.clearSelection()"
on-focus="vm.focus(annotation)"
on-select="vm.scrollTo(annotation)"
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