Commit befe424f authored by Robert Knight's avatar Robert Knight

Make selection override other filters

When the user clicks highlight(s) in the document and makes a "selection" in the
sidebar, we want the selected threads to always be visible. Previously this was
handled by clearing other types of filter when the selection was made, in
addition to setting the selection. This however meant that after the selection
was cleared, the state was different than prior to making the selection, with
any non-selection filters being disabled.

This commit changes the behavior so that the selection, if present, temporarily
overrides other filters rather than being combined with them. This allows the
selection to later be removed to revert back to the previous state.
parent bbd6408d
...@@ -307,18 +307,15 @@ export function buildThread( ...@@ -307,18 +307,15 @@ export function buildThread(
let thread = threadAnnotations(annotations); let thread = threadAnnotations(annotations);
// When a selection is present, it overrides other filters.
if (hasSelection) { if (hasSelection) {
// Remove threads (annotations) that are not selected or
// are not forced-visible
thread.children = thread.children.filter(child => { thread.children = thread.children.filter(child => {
const isSelected = options.selected.includes(child.id); const isSelected = options.selected.includes(child.id);
const isForcedVisible = const isForcedVisible =
hasForcedVisible && options.forcedVisible.includes(child.id); hasForcedVisible && options.forcedVisible.includes(child.id);
return isSelected || isForcedVisible; return isSelected || isForcedVisible;
}); });
} } else if (options.threadFilterFn) {
if (options.threadFilterFn) {
// Remove threads not matching thread-level filters // Remove threads not matching thread-level filters
thread.children = thread.children.filter(options.threadFilterFn); thread.children = thread.children.filter(options.threadFilterFn);
} }
...@@ -329,6 +326,12 @@ export function buildThread( ...@@ -329,6 +326,12 @@ export function buildThread(
// are the top-level annotations. // are the top-level annotations.
thread.visible = false; thread.visible = false;
thread = mapThread(thread, thread => { thread = mapThread(thread, thread => {
if (hasSelection) {
// When a selection is active, make the full conversation thread for
// each selected annotation visible.
return { ...thread, visible: true };
}
let threadIsVisible = thread.visible; let threadIsVisible = thread.visible;
if (options.filterFn) { if (options.filterFn) {
......
...@@ -413,16 +413,27 @@ describe('sidebar/helpers/build-thread', () => { ...@@ -413,16 +413,27 @@ describe('sidebar/helpers/build-thread', () => {
context('when there is a selection', () => { context('when there is a selection', () => {
it('shows only selected annotations', () => { it('shows only selected annotations', () => {
const thread = createThread(SIMPLE_FIXTURE, { const thread = createThread(
SIMPLE_FIXTURE,
{
selected: ['1'], selected: ['1'],
});
// Other thread and annotation-level filters should be ignored
// when there is a selection.
threadFilterFn: () => false,
filterFn: () => false,
},
['visible'],
);
assert.deepEqual(thread, [ assert.deepEqual(thread, [
{ {
annotation: SIMPLE_FIXTURE[0], annotation: SIMPLE_FIXTURE[0],
visible: true,
children: [ children: [
{ {
annotation: SIMPLE_FIXTURE[2], annotation: SIMPLE_FIXTURE[2],
children: [], children: [],
visible: true,
}, },
], ],
}, },
......
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