Unverified Commit 3bc44117 authored by Hannah Stepanek's avatar Hannah Stepanek Committed by GitHub

Merge pull request #1155 from hypothesis/move-force-visible

Move onForceVisible to annotation-thread
parents 7479fadd 699a6fe3
...@@ -21,21 +21,21 @@ function visibleCount(thread) { ...@@ -21,21 +21,21 @@ function visibleCount(thread) {
} }
function showAllChildren(thread, showFn) { function showAllChildren(thread, showFn) {
thread.children.forEach(function(child) { thread.children.forEach(child => {
showFn({ thread: child }); showFn(child);
showAllChildren(child, showFn); showAllChildren(child, showFn);
}); });
} }
function showAllParents(thread, showFn) { function showAllParents(thread, showFn) {
while (thread.parent && thread.parent.annotation) { while (thread.parent && thread.parent.annotation) {
showFn({ thread: thread.parent }); showFn(thread.parent);
thread = thread.parent; thread = thread.parent;
} }
} }
// @ngInject // @ngInject
function AnnotationThreadController() { function AnnotationThreadController(store) {
// Flag that tracks whether the content of the annotation is hovered, // Flag that tracks whether the content of the annotation is hovered,
// excluding any replies. // excluding any replies.
this.annotationHovered = false; this.annotationHovered = false;
...@@ -78,7 +78,7 @@ function AnnotationThreadController() { ...@@ -78,7 +78,7 @@ function AnnotationThreadController() {
*/ */
this.showThreadAndReplies = function() { this.showThreadAndReplies = function() {
showAllParents(this.thread, this.onForceVisible); showAllParents(this.thread, this.onForceVisible);
this.onForceVisible({ thread: this.thread }); this.onForceVisible(this.thread);
showAllChildren(this.thread, this.onForceVisible); showAllChildren(this.thread, this.onForceVisible);
}; };
...@@ -98,6 +98,13 @@ function AnnotationThreadController() { ...@@ -98,6 +98,13 @@ function AnnotationThreadController() {
this.shouldShowReply = function(child) { this.shouldShowReply = function(child) {
return visibleCount(child) > 0; return visibleCount(child) > 0;
}; };
this.onForceVisible = function(thread) {
store.setForceVisible(thread.id, true);
if (thread.parent) {
store.setCollapsed(thread.parent.id, false);
}
};
} }
/** /**
...@@ -116,11 +123,6 @@ module.exports = { ...@@ -116,11 +123,6 @@ module.exports = {
showDocumentInfo: '<', showDocumentInfo: '<',
/** Called when the user clicks on the expand/collapse replies toggle. */ /** Called when the user clicks on the expand/collapse replies toggle. */
onChangeCollapsed: '&', onChangeCollapsed: '&',
/**
* Called when the user clicks the button to show this thread or
* one of its replies.
*/
onForceVisible: '&',
}, },
template: require('../templates/annotation-thread.html'), template: require('../templates/annotation-thread.html'),
}; };
...@@ -276,13 +276,6 @@ function SidebarContentController( ...@@ -276,13 +276,6 @@ function SidebarContentController(
store.setCollapsed(id, collapsed); store.setCollapsed(id, collapsed);
}; };
this.forceVisible = function(thread) {
store.setForceVisible(thread.id, true);
if (thread.parent) {
store.setCollapsed(thread.parent.id, false);
}
};
this.focus = focusAnnotation; this.focus = focusAnnotation;
this.scrollTo = scrollToAnnotation; this.scrollTo = scrollToAnnotation;
......
...@@ -59,9 +59,6 @@ function StreamContentController( ...@@ -59,9 +59,6 @@ function StreamContentController(
fetch(20); fetch(20);
this.setCollapsed = store.setCollapsed; this.setCollapsed = store.setCollapsed;
this.forceVisible = function(id) {
store.setForceVisible(id, true);
};
store.subscribe(function() { store.subscribe(function() {
self.rootThread = rootThread.thread(store.getState()); self.rootThread = rootThread.thread(store.getState());
......
...@@ -36,8 +36,16 @@ describe('annotationThread', function() { ...@@ -36,8 +36,16 @@ describe('annotationThread', function() {
}); });
}); });
let fakeStore;
beforeEach(function() { beforeEach(function() {
angular.mock.module('app'); fakeStore = {
setForceVisible: sinon.stub(),
setCollapsed: sinon.stub(),
getState: sinon.stub(),
};
angular.mock.module('app', { store: fakeStore });
}); });
it('renders the tree structure of parent and child annotations', function() { it('renders the tree structure of parent and child annotations', function() {
...@@ -75,6 +83,33 @@ describe('annotationThread', function() { ...@@ -75,6 +83,33 @@ describe('annotationThread', function() {
assert.isTrue(pageObject.isHidden(pageObject.annotations()[0])); assert.isTrue(pageObject.isHidden(pageObject.annotations()[0]));
}); });
describe('onForceVisible', () => {
it('shows the thread', () => {
const thread = {
id: '1',
children: [],
};
const element = util.createDirective(document, 'annotationThread', {
thread: thread,
});
element.ctrl.onForceVisible(thread);
assert.calledWith(fakeStore.setForceVisible, thread.id, true);
});
it('uncollapses the parent', () => {
const thread = {
id: '2',
children: [],
parent: { id: '3' },
};
const element = util.createDirective(document, 'annotationThread', {
thread: thread,
});
element.ctrl.onForceVisible(thread);
assert.calledWith(fakeStore.setCollapsed, thread.parent.id, false);
});
});
it('shows replies if not collapsed', function() { it('shows replies if not collapsed', function() {
const element = util.createDirective(document, 'annotationThread', { const element = util.createDirective(document, 'annotationThread', {
thread: { thread: {
...@@ -166,7 +201,6 @@ describe('annotationThread', function() { ...@@ -166,7 +201,6 @@ describe('annotationThread', function() {
describe('#showThreadAndReplies', function() { describe('#showThreadAndReplies', function() {
it('reveals all parents and replies', function() { it('reveals all parents and replies', function() {
const onForceVisible = sinon.stub();
const thread = { const thread = {
id: '123', id: '123',
annotation: { id: '123' }, annotation: { id: '123' },
...@@ -184,15 +218,12 @@ describe('annotationThread', function() { ...@@ -184,15 +218,12 @@ describe('annotationThread', function() {
}; };
const element = util.createDirective(document, 'annotationThread', { const element = util.createDirective(document, 'annotationThread', {
thread: thread, thread: thread,
onForceVisible: {
args: ['thread'],
callback: onForceVisible,
},
}); });
element.ctrl.showThreadAndReplies(); element.ctrl.showThreadAndReplies();
assert.calledWith(onForceVisible, thread.parent); assert.calledWith(fakeStore.setForceVisible, thread.parent.id, true);
assert.calledWith(onForceVisible, thread); assert.calledWith(fakeStore.setForceVisible, thread.id, true);
assert.calledWith(onForceVisible, thread.children[0]); assert.calledWith(fakeStore.setForceVisible, thread.children[0].id, true);
assert.calledWith(fakeStore.setCollapsed, thread.parent.id, false);
}); });
}); });
......
...@@ -717,24 +717,6 @@ describe('sidebar.components.sidebar-content', function() { ...@@ -717,24 +717,6 @@ describe('sidebar.components.sidebar-content', function() {
}); });
}); });
describe('#forceVisible', function() {
it('shows the thread', function() {
const thread = { id: '1' };
ctrl.forceVisible(thread);
assert.deepEqual(store.getState().forceVisible, { 1: true });
});
it('uncollapses the parent', function() {
const thread = {
id: '2',
parent: { id: '3' },
};
assert.equal(store.getState().expanded[thread.parent.id], undefined);
ctrl.forceVisible(thread);
assert.equal(store.getState().expanded[thread.parent.id], true);
});
});
describe('#visibleCount', function() { describe('#visibleCount', function() {
it('returns the total number of visible annotations or replies', function() { it('returns the total number of visible annotations or replies', function() {
fakeRootThread.thread.returns({ fakeRootThread.thread.returns({
......
...@@ -185,11 +185,6 @@ module.exports = { ...@@ -185,11 +185,6 @@ module.exports = {
thread: '<', thread: '<',
showDocumentInfo: '<', showDocumentInfo: '<',
/**
* Called when the user clicks a link to show an annotation that does not
* match the current filter.
*/
onForceVisible: '&',
/** Called when the user focuses an annotation by hovering it. */ /** Called when the user focuses an annotation by hovering it. */
onFocus: '&', onFocus: '&',
/** Called when a user selects an annotation. */ /** Called when a user selects an annotation. */
......
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
show-document-info="false" show-document-info="false"
thread="child" thread="child"
on-change-collapsed="vm.onChangeCollapsed({id:id, collapsed:collapsed})" on-change-collapsed="vm.onChangeCollapsed({id:id, collapsed:collapsed})"
on-force-visible="vm.onForceVisible({thread:thread})"> on-force-visible="vm.onForceVisible(thread)">
</annotation-thread> </annotation-thread>
</li> </li>
</ul> </ul>
......
...@@ -47,7 +47,6 @@ ...@@ -47,7 +47,6 @@
on-change-collapsed="vm.setCollapsed(id, collapsed)" on-change-collapsed="vm.setCollapsed(id, collapsed)"
on-clear-selection="vm.clearSelection()" on-clear-selection="vm.clearSelection()"
on-focus="vm.focus(annotation)" on-focus="vm.focus(annotation)"
on-force-visible="vm.forceVisible(thread)"
on-select="vm.scrollTo(annotation)" on-select="vm.scrollTo(annotation)"
show-document-info="false" show-document-info="false"
ng-if="!vm.selectedGroupUnavailable()" ng-if="!vm.selectedGroupUnavailable()"
......
<span window-scroll="vm.loadMore(20)"> <span window-scroll="vm.loadMore(20)">
<thread-list <thread-list
on-change-collapsed="vm.setCollapsed(id, collapsed)" on-change-collapsed="vm.setCollapsed(id, collapsed)"
on-force-visible="vm.forceVisible(thread)"
show-document-info="true" show-document-info="true"
thread="vm.rootThread"> thread="vm.rootThread">
</thread-list> </thread-list>
......
...@@ -11,8 +11,7 @@ ...@@ -11,8 +11,7 @@
<annotation-thread <annotation-thread
thread="child" thread="child"
show-document-info="vm.showDocumentInfo" show-document-info="vm.showDocumentInfo"
on-change-collapsed="vm.onChangeCollapsed({id: id, collapsed: collapsed})" on-change-collapsed="vm.onChangeCollapsed({id: id, collapsed: collapsed})">
on-force-visible="vm.onForceVisible({thread: thread})">
</annotation-thread> </annotation-thread>
</div> </div>
<hr ng-if="vm.isThemeClean" <hr ng-if="vm.isThemeClean"
......
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