Commit 68027f45 authored by Hannah Stepanek's avatar Hannah Stepanek

Instead of using search.query use store directly

Previously a search object was built inside the hypothesis-app
component and passed down to its child components. Now, just use
the store.getState().filterQuery directly. This avoids unnecessarily
passing things between components and a layer of indirection between
the search object and the value in the store. Rename searchQuery to
filterQuery.
parent cda20580
...@@ -37,15 +37,21 @@ function SearchStatusBarController(store, rootThread) { ...@@ -37,15 +37,21 @@ function SearchStatusBarController(store, rootThread) {
} }
return Object.keys(selection).length > 0; return Object.keys(selection).length > 0;
}; };
this.filterQuery = function() {
return store.getState().filterQuery;
};
this.filterActive = function() {
return !!store.getState().filterQuery;
};
} }
module.exports = { module.exports = {
controller: SearchStatusBarController, controller: SearchStatusBarController,
controllerAs: 'vm', controllerAs: 'vm',
bindings: { bindings: {
filterActive: '<',
onClearSelection: '&', onClearSelection: '&',
searchQuery: '<',
selectedTab: '<', selectedTab: '<',
totalAnnotations: '<', totalAnnotations: '<',
totalNotes: '<', totalNotes: '<',
......
...@@ -264,7 +264,7 @@ function SidebarContentController( ...@@ -264,7 +264,7 @@ function SidebarContentController(
if ( if (
this.selectedAnnotationUnavailable() || this.selectedAnnotationUnavailable() ||
this.selectedGroupUnavailable() || this.selectedGroupUnavailable() ||
this.search.query() store.getState().filterQuery
) { ) {
return false; return false;
} }
...@@ -337,7 +337,6 @@ module.exports = { ...@@ -337,7 +337,6 @@ module.exports = {
controllerAs: 'vm', controllerAs: 'vm',
bindings: { bindings: {
auth: '<', auth: '<',
search: '<',
onLogin: '&', onLogin: '&',
}, },
template: require('../templates/sidebar-content.html'), template: require('../templates/sidebar-content.html'),
......
...@@ -31,6 +31,39 @@ describe('searchStatusBar', () => { ...@@ -31,6 +31,39 @@ describe('searchStatusBar', () => {
}); });
}); });
describe('filterQuery', () => {
['tag:foo', null].forEach(filterQuery => {
it('returns the `filterQuery`', () => {
fakeStore.getState.returns({ filterQuery });
const elem = util.createDirective(document, 'searchStatusBar', {});
const ctrl = elem.ctrl;
assert.equal(ctrl.filterQuery(), filterQuery);
});
});
});
describe('filterActive', () => {
it('returns true if there is a `filterQuery`', () => {
fakeStore.getState.returns({ filterQuery: 'tag:foo' });
const elem = util.createDirective(document, 'searchStatusBar', {});
const ctrl = elem.ctrl;
assert.isTrue(ctrl.filterActive());
});
it('returns false if `filterQuery` is null', () => {
fakeStore.getState.returns({ filterQuery: null });
const elem = util.createDirective(document, 'searchStatusBar', {});
const ctrl = elem.ctrl;
assert.isFalse(ctrl.filterActive());
});
});
describe('filterMatchCount', () => { describe('filterMatchCount', () => {
it('returns the total number of visible annotations or replies', () => { it('returns the total number of visible annotations or replies', () => {
fakeRootThread.thread.returns({ fakeRootThread.thread.returns({
...@@ -47,10 +80,11 @@ describe('searchStatusBar', () => { ...@@ -47,10 +80,11 @@ describe('searchStatusBar', () => {
}, },
], ],
}); });
fakeStore.getState.returns({
const elem = util.createDirective(document, 'searchStatusBar', { filterQuery: 'tag:foo',
filterActive: true,
}); });
const elem = util.createDirective(document, 'searchStatusBar', {});
const ctrl = elem.ctrl; const ctrl = elem.ctrl;
assert.equal(ctrl.filterMatchCount(), 2); assert.equal(ctrl.filterMatchCount(), 2);
...@@ -121,9 +155,11 @@ describe('searchStatusBar', () => { ...@@ -121,9 +155,11 @@ describe('searchStatusBar', () => {
], ],
}); });
const elem = util.createDirective(document, 'searchStatusBar', { fakeStore.getState.returns({
filterActive: true, filterQuery: 'tag:foo',
}); });
const elem = util.createDirective(document, 'searchStatusBar', {});
assert.include(elem[0].textContent, '2 search results'); assert.include(elem[0].textContent, '2 search results');
}); });
}); });
......
...@@ -231,11 +231,10 @@ describe('sidebar.components.sidebar-content', function() { ...@@ -231,11 +231,10 @@ describe('sidebar.components.sidebar-content', function() {
describe('showSelectedTabs', () => { describe('showSelectedTabs', () => {
beforeEach(() => { beforeEach(() => {
setFrames([{ uri: 'http://www.example.com' }]); setFrames([{ uri: 'http://www.example.com' }]);
ctrl.search = { query: sinon.stub().returns(undefined) };
}); });
it('returns false if there is a search query', () => { it('returns false if there is a search query', () => {
ctrl.search = { query: sinon.stub().returns('tag:foo') }; store.setFilterQuery('tag:foo');
assert.isFalse(ctrl.showSelectedTabs()); assert.isFalse(ctrl.showSelectedTabs());
}); });
......
...@@ -91,7 +91,7 @@ function configureRoutes($routeProvider) { ...@@ -91,7 +91,7 @@ function configureRoutes($routeProvider) {
}); });
$routeProvider.otherwise({ $routeProvider.otherwise({
template: template:
'<sidebar-content search="vm.search" auth="vm.auth" on-login="vm.login()"></sidebar-content>', '<sidebar-content auth="vm.auth" on-login="vm.login()"></sidebar-content>',
reloadOnSearch: false, reloadOnSearch: false,
resolve: resolve, resolve: resolve,
}); });
......
<div class="search-status-bar" ng-if="vm.filterActive"> <div class="search-status-bar" ng-if="vm.filterActive()">
<button class="primary-action-btn primary-action-btn--short" <button class="primary-action-btn primary-action-btn--short"
ng-click="vm.onClearSelection()" ng-click="vm.onClearSelection()"
title="Clear the search filter and show all annotations" title="Clear the search filter and show all annotations"
...@@ -7,11 +7,11 @@ ...@@ -7,11 +7,11 @@
</button> </button>
<span ng-pluralize <span ng-pluralize
count="vm.filterMatchCount()" count="vm.filterMatchCount()"
when="{'0': 'No results for “{{vm.searchQuery}}”', when="{'0': 'No results for “{{vm.filterQuery()}}”',
'one': '1 search result', 'one': '1 search result',
'other': '{} search results'}"></span> 'other': '{} search results'}"></span>
</div> </div>
<div class="search-status-bar" ng-if="!vm.filterActive && vm.areAllAnnotationsVisible()"> <div class="search-status-bar" ng-if="!vm.filterActive() && vm.areAllAnnotationsVisible()">
<button class="primary-action-btn primary-action-btn--short" <button class="primary-action-btn primary-action-btn--short"
ng-click="vm.onClearSelection()" ng-click="vm.onClearSelection()"
title="Clear the selection and show all annotations"> title="Clear the selection and show all annotations">
......
...@@ -10,9 +10,7 @@ ...@@ -10,9 +10,7 @@
<search-status-bar <search-status-bar
ng-show="!vm.isLoading()" ng-show="!vm.isLoading()"
filter-active="!!vm.search.query()"
on-clear-selection="vm.clearSelection()" on-clear-selection="vm.clearSelection()"
search-query="vm.search.query()"
selected-tab="vm.selectedTab" selected-tab="vm.selectedTab"
total-annotations="vm.totalAnnotations" total-annotations="vm.totalAnnotations"
total-notes="vm.totalNotes"> total-notes="vm.totalNotes">
......
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