Skip to content

Commit 4646070

Browse files
committed
Make forcedVisible logic act on threads, not annotations
Change `forcedVisibleAnnotations` => `forcedVisibleThreads` and use thread ids instead of annotation $tags. This allows the forcing-visible of threads that lack an annotation and is more appropriate overall: threads are forced-visible, not annotations.
1 parent 86a27a7 commit 4646070

File tree

10 files changed

+58
-72
lines changed

10 files changed

+58
-72
lines changed

src/sidebar/components/FilterStatus.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ export default function FilterStatus() {
279279

280280
const store = useStoreProxy();
281281
const focusState = store.focusState();
282-
const forcedVisibleCount = store.forcedVisibleAnnotations().length;
282+
const forcedVisibleCount = store.forcedVisibleThreads().length;
283283
const filterQuery = store.filterQuery();
284284
const selectedCount = store.selectedAnnotations().length;
285285

src/sidebar/components/NotebookResultCount.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import Spinner from './Spinner';
1818
function NotebookResultCount() {
1919
const store = useStoreProxy();
2020

21-
const forcedVisibleCount = store.forcedVisibleAnnotations().length;
21+
const forcedVisibleCount = store.forcedVisibleThreads().length;
2222
const hasAppliedFilter = store.hasAppliedFilter();
2323
const resultCount = store.annotationResultCount();
2424
const isLoading = store.isLoading();

src/sidebar/components/test/FilterStatus-test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe('FilterStatus', () => {
4444
filterQuery: sinon.stub().returns(null),
4545
filterState: sinon.stub().returns(getFilterState()),
4646
focusState: sinon.stub().returns(getFocusState()),
47-
forcedVisibleAnnotations: sinon.stub().returns([]),
47+
forcedVisibleThreads: sinon.stub().returns([]),
4848
selectedAnnotations: sinon.stub().returns([]),
4949
toggleFocusMode: sinon.stub(),
5050
};
@@ -116,7 +116,7 @@ describe('FilterStatus', () => {
116116
context('(State 3): filtered by query with force-expanded threads', () => {
117117
beforeEach(() => {
118118
fakeStore.filterQuery.returns('foobar');
119-
fakeStore.forcedVisibleAnnotations.returns([1, 2, 3]);
119+
fakeStore.forcedVisibleThreads.returns([1, 2, 3]);
120120
fakeThreadUtil.countVisible.returns(5);
121121
});
122122

@@ -284,7 +284,7 @@ describe('FilterStatus', () => {
284284
displayName: 'Ebenezer Studentolog',
285285
});
286286
fakeStore.filterQuery.returns('biscuits');
287-
fakeStore.forcedVisibleAnnotations.returns([1, 2]);
287+
fakeStore.forcedVisibleThreads.returns([1, 2]);
288288
fakeThreadUtil.countVisible.returns(3);
289289
});
290290

@@ -331,7 +331,7 @@ describe('FilterStatus', () => {
331331
configured: true,
332332
displayName: 'Ebenezer Studentolog',
333333
});
334-
fakeStore.forcedVisibleAnnotations.returns([1, 2, 3]);
334+
fakeStore.forcedVisibleThreads.returns([1, 2, 3]);
335335
fakeThreadUtil.countVisible.returns(7);
336336
});
337337

@@ -343,7 +343,7 @@ describe('FilterStatus', () => {
343343
});
344344

345345
it('should handle cases when there are no focused-user annotations', () => {
346-
fakeStore.forcedVisibleAnnotations.returns([1, 2, 3, 4, 5, 6, 7]);
346+
fakeStore.forcedVisibleThreads.returns([1, 2, 3, 4, 5, 6, 7]);
347347
assertFilterText(
348348
createComponent(),
349349
'No annotations by Ebenezer Studentolog (and 7 more)'

src/sidebar/components/test/NotebookResultCount-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('NotebookResultCount', () => {
2222
fakeAnnotationResultCount = sinon.stub().returns(0);
2323

2424
fakeStore = {
25-
forcedVisibleAnnotations: sinon.stub().returns([]),
25+
forcedVisibleThreads: sinon.stub().returns([]),
2626
hasAppliedFilter: sinon.stub().returns(false),
2727
isLoading: fakeIsLoading,
2828
annotationResultCount: fakeAnnotationResultCount,
@@ -111,7 +111,7 @@ describe('NotebookResultCount', () => {
111111
].forEach(test => {
112112
it('should render a count of results', () => {
113113
fakeStore.hasAppliedFilter.returns(true);
114-
fakeStore.forcedVisibleAnnotations.returns(test.forcedVisible);
114+
fakeStore.forcedVisibleThreads.returns(test.forcedVisible);
115115
fakeUseRootThread.returns(test.thread);
116116
fakeCountVisible.returns(test.visibleCount);
117117

src/sidebar/helpers/build-thread.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,7 @@ export default function buildThread(annotations, options) {
296296
thread.children = thread.children.filter(child => {
297297
const isSelected = options.selected.includes(child.id);
298298
const isForcedVisible =
299-
hasForcedVisible &&
300-
child.annotation &&
301-
options.forcedVisible.includes(child.annotation.$tag);
299+
hasForcedVisible && options.forcedVisible.includes(child.id);
302300
return isSelected || isForcedVisible;
303301
});
304302
}
@@ -312,19 +310,16 @@ export default function buildThread(annotations, options) {
312310
thread = mapThread(thread, thread => {
313311
let threadIsVisible = thread.visible;
314312

315-
if (!thread.annotation) {
316-
threadIsVisible = false; // Nothing to show
317-
} else if (options.filterFn) {
318-
if (
319-
hasForcedVisible &&
320-
options.forcedVisible.includes(thread.annotation.$tag)
321-
) {
322-
// This annotation may or may not match the filter, but we should
313+
if (options.filterFn) {
314+
if (hasForcedVisible && options.forcedVisible.includes(thread.id)) {
315+
// This thread may or may not match the filter, but we should
323316
// make sure it is visible because it has been forced visible by user
324317
threadIsVisible = true;
325-
} else {
326-
// Otherwise, visibility depends on whether it matches the filter
318+
} else if (thread.annotation) {
319+
// Otherwise, visibility depends on whether its annotation matches the filter
327320
threadIsVisible = !!options.filterFn(thread.annotation);
321+
} else {
322+
threadIsVisible = false;
328323
}
329324
}
330325
return { ...thread, visible: threadIsVisible };

src/sidebar/helpers/thread.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ import { notNull } from '../util/typing';
1313
* @return {number}
1414
*/
1515
function countByVisibility(thread, visibility) {
16-
const matchesVisibility =
17-
!!thread.annotation && thread.visible === visibility;
16+
const matchesVisibility = thread.visible === visibility;
1817
return thread.children.reduce(
1918
(count, reply) => count + countByVisibility(reply, visibility),
2019
matchesVisibility ? 1 : 0

src/sidebar/services/test/threads-test.js

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,30 @@ import threadsService from '../threads';
22

33
const NESTED_THREADS = {
44
id: 'top',
5-
annotation: { $tag: 'top-tag' },
5+
annotation: {},
66
children: [
77
{
88
id: '1',
9-
annotation: { $tag: '1-tag' },
9+
annotation: {},
1010
children: [
1111
{
1212
id: '1a',
13-
annotation: { $tag: '1a-tag' },
14-
children: [
15-
{ annotation: { $tag: '1ai-tag' }, id: '1ai', children: [] },
16-
],
13+
annotation: {},
14+
children: [{ annotation: {}, id: '1ai', children: [] }],
1715
},
1816
{
1917
id: '1b',
20-
annotation: { $tag: '1b-tag' },
18+
annotation: {},
2119
children: [],
2220
visible: true,
2321
},
2422
{
2523
id: '1c',
26-
annotation: { $tag: '1c-tag' },
24+
annotation: {},
2725
children: [
2826
{
2927
id: '1ci',
30-
annotation: { $tag: '1ci-tag' },
28+
annotation: {},
3129
children: [],
3230
visible: false,
3331
},
@@ -37,32 +35,32 @@ const NESTED_THREADS = {
3735
},
3836
{
3937
id: '2',
40-
annotation: { $tag: '2-tag' },
38+
annotation: {},
4139
children: [
42-
{ id: '2a', annotation: { $tag: '2a-tag' }, children: [] },
40+
{ id: '2a', annotation: {}, children: [] },
4341
{
4442
id: '2b',
4543
children: [
4644
{
4745
id: '2bi',
48-
annotation: { $tag: '2bi-tag' },
46+
annotation: {},
4947
children: [],
5048
visible: true,
5149
},
52-
{ id: '2bii', annotation: { $tag: '2bii-tag' }, children: [] },
50+
{ id: '2bii', annotation: {}, children: [] },
5351
],
5452
},
5553
],
5654
},
5755
{
5856
id: '3',
59-
annotation: { $tag: '3-tag' },
57+
annotation: {},
6058
children: [],
6159
},
6260
],
6361
};
6462

65-
describe('threadsService', function () {
63+
describe('threadsService', () => {
6664
let fakeStore;
6765
let service;
6866

@@ -77,17 +75,17 @@ describe('threadsService', function () {
7775
let nonVisibleThreadIds;
7876
beforeEach(() => {
7977
nonVisibleThreadIds = [
80-
'top-tag',
81-
'1-tag',
82-
'2-tag',
83-
'3-tag',
84-
'1a-tag',
85-
'1c-tag',
86-
'2a-tag',
87-
//'2b-tag', Not visible, but also does not have an annotation
88-
'1ai-tag',
89-
'1ci-tag',
90-
'2bii-tag',
78+
'top',
79+
'1',
80+
'2',
81+
'3',
82+
'1a',
83+
'1c',
84+
'2a',
85+
'2b',
86+
'1ai',
87+
'1ci',
88+
'2bii',
9189
];
9290
});
9391
it('should set the thread and its children force-visible in the store', () => {
@@ -109,13 +107,7 @@ describe('threadsService', function () {
109107
for (let i = 0; i < fakeStore.setForcedVisible.callCount; i++) {
110108
calledWithThreadIds.push(fakeStore.setForcedVisible.getCall(i).args[0]);
111109
}
112-
assert.deepEqual(calledWithThreadIds, [
113-
'1ai-tag',
114-
'1a-tag',
115-
'1ci-tag',
116-
'1c-tag',
117-
'1-tag',
118-
]);
110+
assert.deepEqual(calledWithThreadIds, ['1ai', '1a', '1ci', '1c', '1']);
119111
});
120112
});
121113
});

src/sidebar/services/threads.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export default function threadsService(store) {
1616
thread.children.forEach(child => {
1717
forceVisible(child);
1818
});
19-
if (!thread.visible && thread.annotation) {
20-
store.setForcedVisible(thread.annotation.$tag, true);
19+
if (!thread.visible) {
20+
store.setForcedVisible(thread.id, true);
2121
}
2222
}
2323

src/sidebar/store/modules/selection.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function init(settings) {
6565
// until explicitly expanded.
6666
expanded: initialSelection(settings) || {},
6767

68-
// Set of annotations that have been "forced" visible by the user
68+
// Set of threads that have been "forced" visible by the user
6969
// (e.g. by clicking on "Show x more" button) even though they may not
7070
// match the currently-applied filters
7171
forcedVisible: {},
@@ -261,11 +261,11 @@ function setExpanded(id, expanded) {
261261
}
262262

263263
/**
264-
* A user may "force" an annotation to be visible, even if it would be otherwise
264+
* A user may "force" an thread to be visible, even if it would be otherwise
265265
* not be visible because of applied filters. Set the force-visibility for a
266-
* single annotation, without affecting other forced-visible annotations.
266+
* single thread, without affecting other forced-visible threads.
267267
*
268-
* @param {string} id
268+
* @param {string} id - Thread id
269269
* @param {boolean} visible - Should this annotation be visible, even if it
270270
* conflicts with current filters?
271271
*/
@@ -312,7 +312,7 @@ function expandedMap(state) {
312312
/**
313313
* @type {(state: any) => string[]}
314314
*/
315-
const forcedVisibleAnnotations = createSelector(
315+
const forcedVisibleThreads = createSelector(
316316
state => state.forcedVisible,
317317
forcedVisible => trueKeys(forcedVisible)
318318
);
@@ -352,7 +352,7 @@ const selectionState = createSelector(
352352
selection => {
353353
return {
354354
expanded: expandedMap(selection),
355-
forcedVisible: forcedVisibleAnnotations(selection),
355+
forcedVisible: forcedVisibleThreads(selection),
356356
selected: selectedAnnotations(selection),
357357
sortKey: sortKey(selection),
358358
selectedTab: selectedTab(selection),
@@ -404,7 +404,7 @@ export default storeModule({
404404

405405
selectors: {
406406
expandedMap,
407-
forcedVisibleAnnotations,
407+
forcedVisibleThreads,
408408
hasSelectedAnnotations,
409409
selectedAnnotations,
410410
selectedTab,

src/sidebar/store/modules/test/selection-test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('sidebar/store/modules/selection', () => {
3030
id1: true,
3131
id2: false,
3232
});
33-
assert.deepEqual(store.forcedVisibleAnnotations(), ['id1']);
33+
assert.deepEqual(store.forcedVisibleThreads(), ['id1']);
3434
});
3535
});
3636

@@ -154,7 +154,7 @@ describe('sidebar/store/modules/selection', () => {
154154
});
155155

156156
assert.isEmpty(store.selectedAnnotations());
157-
assert.isEmpty(store.forcedVisibleAnnotations());
157+
assert.isEmpty(store.forcedVisibleThreads());
158158
});
159159
});
160160

@@ -166,7 +166,7 @@ describe('sidebar/store/modules/selection', () => {
166166
store.setFilter('user', { value: 'dingbat', display: 'Ding Bat' });
167167

168168
assert.isEmpty(store.selectedAnnotations());
169-
assert.isEmpty(store.forcedVisibleAnnotations());
169+
assert.isEmpty(store.forcedVisibleThreads());
170170
});
171171
});
172172

@@ -178,7 +178,7 @@ describe('sidebar/store/modules/selection', () => {
178178
store.setFilterQuery('foobar');
179179

180180
assert.isEmpty(store.selectedAnnotations());
181-
assert.isEmpty(store.forcedVisibleAnnotations());
181+
assert.isEmpty(store.forcedVisibleThreads());
182182
});
183183
});
184184

@@ -190,7 +190,7 @@ describe('sidebar/store/modules/selection', () => {
190190
store.toggleFocusMode(true);
191191

192192
assert.isEmpty(store.selectedAnnotations());
193-
assert.isEmpty(store.forcedVisibleAnnotations());
193+
assert.isEmpty(store.forcedVisibleThreads());
194194
});
195195
});
196196

@@ -206,7 +206,7 @@ describe('sidebar/store/modules/selection', () => {
206206
1: true,
207207
3: true,
208208
});
209-
assert.deepEqual(store.forcedVisibleAnnotations(), ['1']);
209+
assert.deepEqual(store.forcedVisibleThreads(), ['1']);
210210
assert.deepEqual(store.expandedMap(), { 1: true });
211211
});
212212
});

0 commit comments

Comments
 (0)