Skip to content

Commit

Permalink
Make selection override other filters
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
robertknight committed Jan 19, 2024
1 parent bbd6408 commit befe424
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
13 changes: 8 additions & 5 deletions src/sidebar/helpers/build-thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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) {
Expand Down
17 changes: 14 additions & 3 deletions src/sidebar/helpers/test/build-thread-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
],
},
Expand Down

0 comments on commit befe424

Please sign in to comment.