diff --git a/src/sidebar/helpers/build-thread.ts b/src/sidebar/helpers/build-thread.ts index 40aa898c6c9..ac80207d8db 100644 --- a/src/sidebar/helpers/build-thread.ts +++ b/src/sidebar/helpers/build-thread.ts @@ -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) { diff --git a/src/sidebar/helpers/test/build-thread-test.js b/src/sidebar/helpers/test/build-thread-test.js index fbc08e68cd5..87ed329eee3 100644 --- a/src/sidebar/helpers/test/build-thread-test.js +++ b/src/sidebar/helpers/test/build-thread-test.js @@ -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, }, ], },