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(
let thread = threadAnnotations(annotations);
// When a selection is present, it overrides other filters.
if (hasSelection) {
// Remove threads (annotations) that are not selected or
// are not forced-visible
thread.children = thread.children.filter(child => {
const isSelected = options.selected.includes(child.id);
const isForcedVisible =
hasForcedVisible && options.forcedVisible.includes(child.id);
return isSelected || isForcedVisible;
});
}
if (options.threadFilterFn) {
} else if (options.threadFilterFn) {
// Remove threads not matching thread-level filters
thread.children = thread.children.filter(options.threadFilterFn);
}
......@@ -329,6 +326,12 @@ export function buildThread(
// are the top-level annotations.
thread.visible = false;
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;
if (options.filterFn) {
......
......@@ -413,16 +413,27 @@ describe('sidebar/helpers/build-thread', () => {
context('when there is a selection', () => {
it('shows only selected annotations', () => {
const thread = createThread(SIMPLE_FIXTURE, {
selected: ['1'],
});
const thread = createThread(
SIMPLE_FIXTURE,
{
selected: ['1'],
// Other thread and annotation-level filters should be ignored
// when there is a selection.
threadFilterFn: () => false,
filterFn: () => false,
},
['visible'],
);
assert.deepEqual(thread, [
{
annotation: SIMPLE_FIXTURE[0],
visible: true,
children: [
{
annotation: SIMPLE_FIXTURE[2],
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