Skip to content

Commit

Permalink
Take into account the forced-visible set when filtering threads
Browse files Browse the repository at this point in the history
When filtering annotations the `forcedVisible` list was taken into account, but
not when filtering threads. Consult this list when filtering threads as well.

This fixes an issue where newly created annotations would not be shown if they
did not match a thread filter. Note that newly added annotations are added to
the forced-visible set by the `ThreadList` component.
  • Loading branch information
robertknight committed Sep 20, 2024
1 parent 3c90f0c commit 7e9a65e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/sidebar/helpers/build-thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,13 @@ export function buildThread(
});
} else if (options.threadFilterFn) {
// Remove threads not matching thread-level filters
thread.children = thread.children.filter(options.threadFilterFn);
const threadFilterFn = options.threadFilterFn;
thread.children = thread.children.filter(thread => {
if (hasForcedVisible && options.forcedVisible.includes(thread.id)) {
return true;
}
return threadFilterFn(thread);
});
}

// Set visibility for threads.
Expand Down
12 changes: 11 additions & 1 deletion src/sidebar/helpers/test/build-thread-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,18 +475,28 @@ describe('sidebar/helpers/build-thread', () => {
text: 'note',
target: [{ selector: undefined }],
},
{
id: '3',
text: 'annotation',
target: [{ selector: undefined }],
},
];

it('shows only annotations matching the thread filter', () => {
it('shows only annotations matching the thread filter and forced-visible threads', () => {
const thread = createThread(fixture, {
threadFilterFn: thread => metadata.isPageNote(thread.annotation),
forcedVisible: ['3'],
});

assert.deepEqual(thread, [
{
annotation: fixture[1],
children: [],
},
{
annotation: fixture[2],
children: [],
},
]);
});
});
Expand Down

0 comments on commit 7e9a65e

Please sign in to comment.