Commit 6462e0e0 authored by Robert Knight's avatar Robert Knight

Only show replies that match the search filter or contain at least one visible descendant

Given a thread like this:

    A-
     |- B
        |- C
        |- D
     |- E

Where only 'B' matches the search filter, the rendered output should be:

    View 4 more in conversation
     |- B
        View two more in conversation
parent e27a7962
...@@ -7,6 +7,13 @@ function hiddenCount(thread) { ...@@ -7,6 +7,13 @@ function hiddenCount(thread) {
}, isHidden ? 1 : 0); }, isHidden ? 1 : 0);
} }
function visibleCount(thread) {
var isVisible = thread.annotation && thread.visible;
return thread.children.reduce(function (count, reply) {
return count + visibleCount(reply);
}, isVisible ? 1 : 0);
}
function showAllChildren(thread, showFn) { function showAllChildren(thread, showFn) {
thread.children.forEach(function (child) { thread.children.forEach(function (child) {
showFn({thread: child}); showFn({thread: child});
...@@ -47,6 +54,10 @@ function AnnotationThreadController() { ...@@ -47,6 +54,10 @@ function AnnotationThreadController() {
this.hiddenCount = function () { this.hiddenCount = function () {
return hiddenCount(this.thread); return hiddenCount(this.thread);
}; };
this.shouldShowReply = function (child) {
return visibleCount(child) > 0;
};
} }
/** /**
......
...@@ -9,8 +9,8 @@ function PageObject(element) { ...@@ -9,8 +9,8 @@ function PageObject(element) {
this.annotations = function () { this.annotations = function () {
return Array.from(element[0].querySelectorAll('annotation')); return Array.from(element[0].querySelectorAll('annotation'));
}; };
this.replies = function () { this.visibleReplies = function () {
return Array.from(element[0].querySelectorAll('annotation-thread')); return Array.from(element[0].querySelectorAll('.thread:not(.ng-hide)'));
}; };
this.replyList = function () { this.replyList = function () {
return element[0].querySelector('.thread-replies'); return element[0].querySelector('.thread-replies');
...@@ -39,13 +39,14 @@ describe('annotationThread', function () { ...@@ -39,13 +39,14 @@ describe('annotationThread', function () {
id: '2', id: '2',
annotation: {id: '2', text: 'areply'}, annotation: {id: '2', text: 'areply'},
children: [], children: [],
visible: true,
}], }],
visible: true, visible: true,
}, },
}); });
var pageObject = new PageObject(element); var pageObject = new PageObject(element);
assert.equal(pageObject.annotations().length, 2); assert.equal(pageObject.annotations().length, 2);
assert.equal(pageObject.replies().length, 1); assert.equal(pageObject.visibleReplies().length, 1);
}); });
it('does not render hidden threads', function () { it('does not render hidden threads', function () {
...@@ -78,7 +79,7 @@ describe('annotationThread', function () { ...@@ -78,7 +79,7 @@ describe('annotationThread', function () {
} }
}); });
var pageObject = new PageObject(element); var pageObject = new PageObject(element);
assert.equal(pageObject.replies().length, 1); assert.isFalse(pageObject.isHidden(pageObject.replyList()));
}); });
it('does not show replies if collapsed', function () { it('does not show replies if collapsed', function () {
...@@ -100,6 +101,30 @@ describe('annotationThread', function () { ...@@ -100,6 +101,30 @@ describe('annotationThread', function () {
assert.isTrue(pageObject.isHidden(pageObject.replyList())); assert.isTrue(pageObject.isHidden(pageObject.replyList()));
}); });
it('only shows replies that match the search filter', function () {
var element = util.createDirective(document, 'annotationThread', {
thread: {
id: '1',
annotation: {id: '1'},
visible: true,
children: [{
id: '2',
annotation: {id: '2'},
children: [],
visible: false,
},{
id: '3',
annotation: {id: '3'},
children: [],
visible: true,
}],
collapsed: false,
}
});
var pageObject = new PageObject(element);
assert.equal(pageObject.visibleReplies().length, 1);
});
describe('#toggleCollapsed', function () { describe('#toggleCollapsed', function () {
it('toggles replies', function () { it('toggles replies', function () {
var onChangeCollapsed = sinon.stub(); var onChangeCollapsed = sinon.stub();
......
...@@ -39,7 +39,9 @@ ...@@ -39,7 +39,9 @@
<!-- Replies --> <!-- Replies -->
<ul class="thread-replies" ng-show="!vm.thread.collapsed"> <ul class="thread-replies" ng-show="!vm.thread.collapsed">
<li class="thread" ng-repeat="child in vm.thread.children track by child.id"> <li class="thread"
ng-repeat="child in vm.thread.children track by child.id"
ng-show="vm.shouldShowReply(child)">
<annotation-thread <annotation-thread
show-document-info="false" show-document-info="false"
thread="child" thread="child"
......
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