Commit f1d34f28 authored by Lyza Danger Gardner's avatar Lyza Danger Gardner

Add `hasAppliedFilter` selector

Add selector to check if there are any applied filters on annotations
parent 18fd3307
......@@ -519,6 +519,21 @@ function getSelectedAnnotationMap(state) {
return state.selection.selectedAnnotationMap;
}
/**
* Is any sort of filtering currently applied to the list of annotations? This
* includes a search query, but also if annotations are selected or a user
* is focused.
*
* @return {boolean}
*/
const hasAppliedFilter = createSelector(
filterQuery,
focusModeFocused,
hasSelectedAnnotations,
(filterQuery, focusModeFocused, hasSelectedAnnotations) =>
!!filterQuery || focusModeFocused || hasSelectedAnnotations
);
export default {
init: init,
namespace: 'selection',
......@@ -541,7 +556,6 @@ export default {
},
selectors: {
hasSelectedAnnotations,
expandedThreads,
filterQuery,
focusModeFocused,
......@@ -553,5 +567,7 @@ export default {
isAnnotationSelected,
getFirstSelectedAnnotationId,
getSelectedAnnotationMap,
hasAppliedFilter,
hasSelectedAnnotations,
},
};
......@@ -62,6 +62,34 @@ describe('sidebar/store/modules/selection', () => {
});
});
describe('hasAppliedFilter', () => {
it('returns true if there is a search query set', () => {
store.setFilterQuery('foobar');
assert.isTrue(store.hasAppliedFilter());
});
it('returns true if in user-focused mode', () => {
store = createStore([selection], [{ focus: { user: {} } }]);
store.setFocusModeFocused(true);
assert.isTrue(store.hasAppliedFilter());
});
it('returns true if there are selected annotations', () => {
store.selectAnnotations([1]);
assert.isTrue(store.hasAppliedFilter());
});
it('returns false after selection is cleared', () => {
store.setFilterQuery('foobar');
store.clearSelection();
assert.isFalse(store.hasAppliedFilter());
});
});
describe('hasSelectedAnnotations', function () {
it('returns true if there are any selected annotations', function () {
store.selectAnnotations([1]);
......
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