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';
const NESTED_THREADS = {
id: 'top',
annotation: { $tag: 'top-tag' },
children: [
{
id: '1',
annotation: { $tag: '1-tag' },
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',
children: [{ id: '1ci', children: [], visible: false }],
annotation: { $tag: '1c-tag' },
children: [
{
id: '1ci',
annotation: { $tag: '1ci-tag' },
children: [],
visible: false,
},
],
},
],
},
{
id: '2',
annotation: { $tag: '2-tag' },
children: [
{ id: '2a', children: [] },
{ id: '2a', annotation: { $tag: '2a-tag' }, children: [] },
{
id: '2b',
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',
annotation: { $tag: '3-tag' },
children: [],
},
],
......@@ -49,17 +77,17 @@ describe('threadsService', function () {
let nonVisibleThreadIds;
beforeEach(() => {
nonVisibleThreadIds = [
'top',
'1',
'2',
'3',
'1a',
'1c',
'2a',
'2b',
'1ai',
'1ci',
'2bii',
'top-tag',
'1-tag',
'2-tag',
'3-tag',
'1a-tag',
'1c-tag',
'2a-tag',
//'2b-tag', Not visible, but also does not have an annotation
'1ai-tag',
'1ci-tag',
'2bii-tag',
];
});
it('should set the thread and its children force-visible in the store', () => {
......@@ -81,7 +109,13 @@ describe('threadsService', function () {
for (let i = 0; i < fakeStore.setForcedVisible.callCount; i++) {
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) {
thread.children.forEach(child => {
forceVisible(child);
});
if (!thread.visible) {
store.setForcedVisible(thread.id, true);
if (!thread.visible && thread.annotation) {
store.setForcedVisible(thread.annotation.$tag, true);
}
}
......
......@@ -259,7 +259,7 @@ function hasVisibleChildren(thread) {
* @typedef Options
* @prop {string[]} [selected] - List of currently-selected annotation ids, from
* 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
* match current filters
* @prop {(a: Annotation) => boolean} [filterFn] - Predicate function that
......@@ -326,11 +326,14 @@ export default function buildThread(annotations, options) {
if (hasSelection) {
// Remove threads (annotations) that are not selected or
// are not forced-visible
thread.children = thread.children.filter(
child =>
opts.selected.indexOf(child.id) !== -1 ||
opts.forcedVisible.indexOf(child.id) !== -1
);
thread.children = thread.children.filter(child => {
const isSelected = opts.selected.includes(child.id);
const isForcedVisible =
hasForcedVisible &&
child.annotation &&
opts.forcedVisible.includes(child.annotation.$tag);
return isSelected || isForcedVisible;
});
}
if (threadsFiltered) {
......@@ -347,7 +350,7 @@ export default function buildThread(annotations, options) {
} else if (annotationsFiltered) {
if (
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
// make sure it is visible because it has been forced visible by user
......
......@@ -6,15 +6,18 @@ const SIMPLE_FIXTURE = [
{
id: '1',
text: 'first annotation',
$tag: '1',
references: [],
},
{
id: '2',
$tag: '2',
text: 'second annotation',
references: [],
},
{
id: '3',
$tag: '3',
text: 'third annotation',
references: [1],
},
......@@ -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 () {
......
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