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', () => {
document.body.appendChild(fakeScrollContainer);
fakeStore = {
clearSelection: sinon.stub(),
setForcedVisible: sinon.stub(),
unsavedAnnotations: sinon.stub().returns([]),
};
......@@ -113,19 +113,11 @@ describe('ThreadList', () => {
});
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();
addNewAnnotation(wrapper);
assert.calledOnce(fakeStore.clearSelection);
});
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);
assert.calledOnce(fakeStore.setForcedVisible);
assert.calledWith(fakeStore.setForcedVisible, 'foobar', true);
});
});
......
......@@ -44,7 +44,7 @@ function getScrollContainer() {
* @param {ThreadListProps} props
*/
function ThreadList({ thread }) {
const clearSelection = useStore(store => store.clearSelection);
const setForcedVisible = useStore(store => store.setForcedVisible);
// Height of the visible area of the scroll container.
const [scrollContainerHeight, setScrollContainerHeight] = useState(
......@@ -105,10 +105,10 @@ function ThreadList({ thread }) {
// and the thread list will scroll to that.
useEffect(() => {
if (newAnnotationTag) {
clearSelection();
setForcedVisible(newAnnotationTag, true);
setScrollToId(newAnnotationTag);
}
}, [clearSelection, newAnnotationTag]);
}, [setForcedVisible, newAnnotationTag]);
// Effect to scroll a particular thread into view. This is mainly used to
// scroll a newly created annotation into view.
......
......@@ -324,9 +324,12 @@ export default function buildThread(annotations, options) {
let thread = threadAnnotations(annotations);
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(
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