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

Don't clear selection when creating new annotations

Don't clear selection (filters) when a user creates a new
annotation or reply. Instead, force the new annotaiton/reply
visible and make sure that forced-visible threads are
honored during thread-building.
parent 42a399a3
...@@ -40,7 +40,7 @@ describe('ThreadList', () => { ...@@ -40,7 +40,7 @@ describe('ThreadList', () => {
document.body.appendChild(fakeScrollContainer); document.body.appendChild(fakeScrollContainer);
fakeStore = { fakeStore = {
clearSelection: sinon.stub(), setForcedVisible: sinon.stub(),
unsavedAnnotations: sinon.stub().returns([]), unsavedAnnotations: sinon.stub().returns([]),
}; };
...@@ -113,19 +113,11 @@ describe('ThreadList', () => { ...@@ -113,19 +113,11 @@ describe('ThreadList', () => {
}); });
context('new annotation created in application', () => { context('new annotation created in application', () => {
it('clears the current selection in the store', () => { it('sets the new annotation to forced-visible', () => {
const wrapper = createComponent(); const wrapper = createComponent();
addNewAnnotation(wrapper); addNewAnnotation(wrapper);
assert.calledOnce(fakeStore.clearSelection); assert.calledOnce(fakeStore.setForcedVisible);
}); assert.calledWith(fakeStore.setForcedVisible, 'foobar', true);
it('does not clear the selection in the store if new annotation is a highlight', () => {
fakeMetadata.isHighlight.returns(true);
const wrapper = createComponent();
addNewAnnotation(wrapper);
assert.notCalled(fakeStore.clearSelection);
}); });
}); });
......
...@@ -44,7 +44,7 @@ function getScrollContainer() { ...@@ -44,7 +44,7 @@ function getScrollContainer() {
* @param {ThreadListProps} props * @param {ThreadListProps} props
*/ */
function ThreadList({ thread }) { function ThreadList({ thread }) {
const clearSelection = useStore(store => store.clearSelection); const setForcedVisible = useStore(store => store.setForcedVisible);
// Height of the visible area of the scroll container. // Height of the visible area of the scroll container.
const [scrollContainerHeight, setScrollContainerHeight] = useState( const [scrollContainerHeight, setScrollContainerHeight] = useState(
...@@ -105,10 +105,10 @@ function ThreadList({ thread }) { ...@@ -105,10 +105,10 @@ function ThreadList({ thread }) {
// and the thread list will scroll to that. // and the thread list will scroll to that.
useEffect(() => { useEffect(() => {
if (newAnnotationTag) { if (newAnnotationTag) {
clearSelection(); setForcedVisible(newAnnotationTag, true);
setScrollToId(newAnnotationTag); setScrollToId(newAnnotationTag);
} }
}, [clearSelection, newAnnotationTag]); }, [setForcedVisible, newAnnotationTag]);
// Effect to scroll a particular thread into view. This is mainly used to // Effect to scroll a particular thread into view. This is mainly used to
// scroll a newly created annotation into view. // scroll a newly created annotation into view.
......
...@@ -324,9 +324,12 @@ export default function buildThread(annotations, options) { ...@@ -324,9 +324,12 @@ export default function buildThread(annotations, options) {
let thread = threadAnnotations(annotations); let thread = threadAnnotations(annotations);
if (hasSelection) { if (hasSelection) {
// Remove threads (annotations) that are not selected // Remove threads (annotations) that are not selected or
// are not forced-visible
thread.children = thread.children.filter( thread.children = thread.children.filter(
child => opts.selected.indexOf(child.id) !== -1 child =>
opts.selected.indexOf(child.id) !== -1 ||
opts.forcedVisible.indexOf(child.id) !== -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