Commit ad776c90 authored by Robert Knight's avatar Robert Knight

Display the total number of visible annotations and replies in the search result count

Make the behavior of the new threading implementation consistent with that of
the previous threading implementation by displaying the total number of visible
annotations (+ replies) as the search result count.
parent 936650cc
...@@ -387,4 +387,22 @@ describe('WidgetController', function () { ...@@ -387,4 +387,22 @@ describe('WidgetController', function () {
assert.equal(annotationUI.getState().expanded[thread.parent.id], true); assert.equal(annotationUI.getState().expanded[thread.parent.id], true);
}); });
}); });
describe('#visibleCount', function () {
it('returns the total number of visible annotations or replies', function () {
fakeRootThread.thread.returns({
children: [{
id: '1',
visible: true,
children: [{ id: '3', visible: true, children: [] }],
},{
id: '2',
visible: false,
children: [],
}],
});
$scope.$digest();
assert.equal($scope.visibleCount(), 2);
});
});
}); });
'use strict';
/**
* A simple memoization function which caches the last result of
* a single-argument function.
*
* The argument to the input function may be of any type and is compared
* using reference equality.
*/
function memoize(fn) {
if (fn.length !== 1) {
throw new Error('Memoize input must be a function of one argument');
}
var lastArg;
var lastResult;
return function (arg) {
if (arg === lastArg) {
return lastResult;
}
lastArg = arg;
lastResult = fn(arg);
return lastResult;
};
}
module.exports = memoize;
'use strict';
var memoize = require('../memoize');
describe('memoize', function () {
var count = 0;
var memoized;
function square(arg) {
++count;
return arg * arg;
}
beforeEach(function () {
count = 0;
memoized = memoize(square);
});
it('computes the result of the function', function () {
assert.equal(memoized(12), 144);
});
it('does not recompute if the input is unchanged', function () {
memoized(42);
memoized(42);
assert.equal(count, 1);
});
it('recomputes if the input changes', function () {
memoized(42);
memoized(39);
assert.equal(count, 2);
});
});
'use strict'; 'use strict';
var events = require('./events'); var events = require('./events');
var memoize = require('./util/memoize');
var SearchClient = require('./search-client'); var SearchClient = require('./search-client');
function firstKey(object) { function firstKey(object) {
...@@ -276,6 +277,16 @@ module.exports = function WidgetController( ...@@ -276,6 +277,16 @@ module.exports = function WidgetController(
$scope.isLoading = isLoading; $scope.isLoading = isLoading;
var visibleCount = memoize(function (thread) {
return thread.children.reduce(function (count, child) {
return count + visibleCount(child);
}, thread.visible ? 1 : 0);
});
$scope.visibleCount = function () {
return visibleCount(rootThread.thread());
};
$scope.topLevelThreadCount = function () { $scope.topLevelThreadCount = function () {
return rootThread.thread().totalChildren; return rootThread.thread().totalChildren;
}; };
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
ng-show="!isLoading()" ng-show="!isLoading()"
ng-if="!isStream" ng-if="!isStream"
filter-active="search.query" filter-active="search.query"
filter-match-count="rootThread().children.length" filter-match-count="visibleCount()"
on-clear-selection="clearSelection()" on-clear-selection="clearSelection()"
search-query="search ? search.query : ''" search-query="search ? search.query : ''"
selection-count="selectedAnnotationCount()" selection-count="selectedAnnotationCount()"
......
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