Commit 286be9cc authored by Lyza Danger Gardner's avatar Lyza Danger Gardner Committed by Lyza Gardner

Make `forcedVisible` deal only in `$tag`s

Update `forcedVisible` to use only `$tag` values, not
`id`s.
parent be332973
...@@ -2,33 +2,61 @@ import threadsService from '../threads'; ...@@ -2,33 +2,61 @@ import threadsService from '../threads';
const NESTED_THREADS = { const NESTED_THREADS = {
id: 'top', id: 'top',
annotation: { $tag: 'top-tag' },
children: [ children: [
{ {
id: '1', id: '1',
annotation: { $tag: '1-tag' },
children: [ children: [
{ id: '1a', children: [{ id: '1ai', children: [] }] }, {
{ id: '1b', children: [], visible: true }, id: '1a',
annotation: { $tag: '1a-tag' },
children: [
{ annotation: { $tag: '1ai-tag' }, id: '1ai', children: [] },
],
},
{
id: '1b',
annotation: { $tag: '1b-tag' },
children: [],
visible: true,
},
{ {
id: '1c', id: '1c',
children: [{ id: '1ci', children: [], visible: false }], annotation: { $tag: '1c-tag' },
children: [
{
id: '1ci',
annotation: { $tag: '1ci-tag' },
children: [],
visible: false,
},
],
}, },
], ],
}, },
{ {
id: '2', id: '2',
annotation: { $tag: '2-tag' },
children: [ children: [
{ id: '2a', children: [] }, { id: '2a', annotation: { $tag: '2a-tag' }, children: [] },
{ {
id: '2b', id: '2b',
children: [ children: [
{ id: '2bi', children: [], visible: true }, {
{ id: '2bii', children: [] }, id: '2bi',
annotation: { $tag: '2bi-tag' },
children: [],
visible: true,
},
{ id: '2bii', annotation: { $tag: '2bii-tag' }, children: [] },
], ],
}, },
], ],
}, },
{ {
id: '3', id: '3',
annotation: { $tag: '3-tag' },
children: [], children: [],
}, },
], ],
...@@ -49,17 +77,17 @@ describe('threadsService', function () { ...@@ -49,17 +77,17 @@ describe('threadsService', function () {
let nonVisibleThreadIds; let nonVisibleThreadIds;
beforeEach(() => { beforeEach(() => {
nonVisibleThreadIds = [ nonVisibleThreadIds = [
'top', 'top-tag',
'1', '1-tag',
'2', '2-tag',
'3', '3-tag',
'1a', '1a-tag',
'1c', '1c-tag',
'2a', '2a-tag',
'2b', //'2b-tag', Not visible, but also does not have an annotation
'1ai', '1ai-tag',
'1ci', '1ci-tag',
'2bii', '2bii-tag',
]; ];
}); });
it('should set the thread and its children force-visible in the store', () => { it('should set the thread and its children force-visible in the store', () => {
...@@ -81,7 +109,13 @@ describe('threadsService', function () { ...@@ -81,7 +109,13 @@ describe('threadsService', function () {
for (let i = 0; i < fakeStore.setForcedVisible.callCount; i++) { for (let i = 0; i < fakeStore.setForcedVisible.callCount; i++) {
calledWithThreadIds.push(fakeStore.setForcedVisible.getCall(i).args[0]); calledWithThreadIds.push(fakeStore.setForcedVisible.getCall(i).args[0]);
} }
assert.deepEqual(calledWithThreadIds, ['1ai', '1a', '1ci', '1c', '1']); assert.deepEqual(calledWithThreadIds, [
'1ai-tag',
'1a-tag',
'1ci-tag',
'1c-tag',
'1-tag',
]);
}); });
}); });
}); });
...@@ -16,8 +16,8 @@ export default function threadsService(store) { ...@@ -16,8 +16,8 @@ export default function threadsService(store) {
thread.children.forEach(child => { thread.children.forEach(child => {
forceVisible(child); forceVisible(child);
}); });
if (!thread.visible) { if (!thread.visible && thread.annotation) {
store.setForcedVisible(thread.id, true); store.setForcedVisible(thread.annotation.$tag, true);
} }
} }
......
...@@ -259,7 +259,7 @@ function hasVisibleChildren(thread) { ...@@ -259,7 +259,7 @@ function hasVisibleChildren(thread) {
* @typedef Options * @typedef Options
* @prop {string[]} [selected] - List of currently-selected annotation ids, from * @prop {string[]} [selected] - List of currently-selected annotation ids, from
* the data store * the data store
* @prop {string[]} [forcedVisible] - List of ids of annotations that have * @prop {string[]} [forcedVisible] - List of $tags of annotations that have
* been explicitly expanded by the user, even if they don't * been explicitly expanded by the user, even if they don't
* match current filters * match current filters
* @prop {(a: Annotation) => boolean} [filterFn] - Predicate function that * @prop {(a: Annotation) => boolean} [filterFn] - Predicate function that
...@@ -326,11 +326,14 @@ export default function buildThread(annotations, options) { ...@@ -326,11 +326,14 @@ export default function buildThread(annotations, options) {
if (hasSelection) { if (hasSelection) {
// Remove threads (annotations) that are not selected or // Remove threads (annotations) that are not selected or
// are not forced-visible // are not forced-visible
thread.children = thread.children.filter( thread.children = thread.children.filter(child => {
child => const isSelected = opts.selected.includes(child.id);
opts.selected.indexOf(child.id) !== -1 || const isForcedVisible =
opts.forcedVisible.indexOf(child.id) !== -1 hasForcedVisible &&
); child.annotation &&
opts.forcedVisible.includes(child.annotation.$tag);
return isSelected || isForcedVisible;
});
} }
if (threadsFiltered) { if (threadsFiltered) {
...@@ -347,7 +350,7 @@ export default function buildThread(annotations, options) { ...@@ -347,7 +350,7 @@ export default function buildThread(annotations, options) {
} else if (annotationsFiltered) { } else if (annotationsFiltered) {
if ( if (
hasForcedVisible && hasForcedVisible &&
opts.forcedVisible.indexOf(annotationId(thread.annotation)) !== -1 opts.forcedVisible.includes(thread.annotation.$tag)
) { ) {
// This annotation may or may not match the filter, but we should // This annotation may or may not match the filter, but we should
// make sure it is visible because it has been forced visible by user // make sure it is visible because it has been forced visible by user
......
...@@ -6,15 +6,18 @@ const SIMPLE_FIXTURE = [ ...@@ -6,15 +6,18 @@ const SIMPLE_FIXTURE = [
{ {
id: '1', id: '1',
text: 'first annotation', text: 'first annotation',
$tag: '1',
references: [], references: [],
}, },
{ {
id: '2', id: '2',
$tag: '2',
text: 'second annotation', text: 'second annotation',
references: [], references: [],
}, },
{ {
id: '3', id: '3',
$tag: '3',
text: 'third annotation', text: 'third annotation',
references: [1], references: [1],
}, },
...@@ -366,6 +369,28 @@ describe('sidebar/util/build-thread', function () { ...@@ -366,6 +369,28 @@ describe('sidebar/util/build-thread', function () {
}, },
]); ]);
}); });
it('shows forced-visible annotations, also', function () {
const thread = createThread(SIMPLE_FIXTURE, {
selected: ['1'],
forcedVisible: ['2'],
});
assert.deepEqual(thread, [
{
annotation: SIMPLE_FIXTURE[0],
children: [
{
annotation: SIMPLE_FIXTURE[2],
children: [],
},
],
},
{
annotation: SIMPLE_FIXTURE[1],
children: [],
},
]);
});
}); });
describe('thread filtering', function () { describe('thread filtering', function () {
......
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