Commit e92fe755 authored by Lyza Danger Gardner's avatar Lyza Danger Gardner Committed by Lyza Gardner

Show spinner in filter interface when loading

The only typical time that the filter interface is visible when loading
is when loading groups for a focused student-user in grading mode.
Other filtering happens client-side and doesn't involve loading.

But when we ARE loading, don't show an inaccurate count (because we
don't have all the results yet), show a spinner instead.
parent 819feb27
import { LabeledButton } from '@hypothesis/frontend-shared'; import { LabeledButton, Spinner } from '@hypothesis/frontend-shared';
import { useMemo } from 'preact/hooks'; import { useMemo } from 'preact/hooks';
...@@ -68,37 +68,44 @@ function FilterStatusPanel({ ...@@ -68,37 +68,44 @@ function FilterStatusPanel({
focusDisplayName, focusDisplayName,
resultCount, resultCount,
}) { }) {
const store = useStoreProxy();
return ( return (
<div className="FilterStatus"> <div className="FilterStatus">
<div className="hyp-u-layout-row--align-center"> {store.isLoading() ? (
<div className="FilterStatus__text"> <div className="hyp-u-layout-row--center">
{resultCount > 0 && <span>Showing </span>} <Spinner />
<span className="filter-facet"> </div>
{resultCount > 0 ? resultCount : 'No'}{' '} ) : (
{resultCount === 1 ? entitySingular : entityPlural} <div className="hyp-u-layout-row--align-center">
</span> <div className="FilterStatus__text">
{filterQuery && ( {resultCount > 0 && <span>Showing </span>}
<span> <span className="filter-facet">
{' '} {resultCount > 0 ? resultCount : 'No'}{' '}
for{' '} {resultCount === 1 ? entitySingular : entityPlural}
<span className="filter-facet--pre">&#39;{filterQuery}&#39;</span>
</span>
)}
{focusDisplayName && (
<span>
{' '}
by <span className="filter-facet">{focusDisplayName}</span>
</span>
)}
{additionalCount > 0 && (
<span className="filter-facet--muted">
{' '}
(and {additionalCount} more)
</span> </span>
)} {filterQuery && (
<span>
{' '}
for{' '}
<span className="filter-facet--pre">{`'${filterQuery}'`}</span>
</span>
)}
{focusDisplayName && (
<span>
{' '}
by <span className="filter-facet">{focusDisplayName}</span>
</span>
)}
{additionalCount > 0 && (
<span className="filter-facet--muted">
{' '}
(and {additionalCount} more)
</span>
)}
</div>
<div>{actionButton}</div>
</div> </div>
<div>{actionButton}</div> )}
</div>
</div> </div>
); );
} }
......
...@@ -44,6 +44,7 @@ describe('FilterStatus', () => { ...@@ -44,6 +44,7 @@ describe('FilterStatus', () => {
filterState: sinon.stub().returns(getFilterState()), filterState: sinon.stub().returns(getFilterState()),
focusState: sinon.stub().returns(getFocusState()), focusState: sinon.stub().returns(getFocusState()),
forcedVisibleThreads: sinon.stub().returns([]), forcedVisibleThreads: sinon.stub().returns([]),
isLoading: sinon.stub().returns(false),
selectedAnnotations: sinon.stub().returns([]), selectedAnnotations: sinon.stub().returns([]),
toggleFocusMode: sinon.stub(), toggleFocusMode: sinon.stub(),
}; };
...@@ -80,6 +81,16 @@ describe('FilterStatus', () => { ...@@ -80,6 +81,16 @@ describe('FilterStatus', () => {
}); });
} }
context('Loading', () => {
it('shows a loading spinner', () => {
fakeStore.filterQuery.returns('foobar');
fakeStore.isLoading.returns(true);
const wrapper = createComponent();
assert.isTrue(wrapper.find('Spinner').exists());
});
});
context('(State 1): no search filters active', () => { context('(State 1): no search filters active', () => {
it('should return null if filter state indicates no active filters', () => { it('should return null if filter state indicates no active filters', () => {
const wrapper = createComponent(); const wrapper = createComponent();
......
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