Commit d1904aee authored by Lyza Danger Gardner's avatar Lyza Danger Gardner Committed by Lyza Gardner

Refactor `highlighted`

- Make internal `highlighted` property an object
- Refactor `highlightAnnotations` action
parent 36e999b8
...@@ -117,8 +117,9 @@ function init(settings) { ...@@ -117,8 +117,9 @@ function init(settings) {
// by the user even if they do not match the current search filter // by the user even if they do not match the current search filter
forcedVisible: {}, forcedVisible: {},
// IDs of annotations that should be highlighted // A map of annotations that should appear as "highlighted", e.g. the
highlighted: [], // target of a single-annotation view
highlighted: {},
filterQuery: settings.query || null, filterQuery: settings.query || null,
...@@ -355,12 +356,16 @@ function setExpanded(id, expanded) { ...@@ -355,12 +356,16 @@ function setExpanded(id, expanded) {
* Highlight annotations with the given `ids`. * Highlight annotations with the given `ids`.
* *
* This is used to indicate the specific annotation in a thread that was * This is used to indicate the specific annotation in a thread that was
* linked to for example. * linked to for example. Replaces the current map of highlighted annotations.
*
* @param {string[ids]} - ids of annotations to highlight
*/ */
function highlightAnnotations(ids) { function highlightAnnotations(ids) {
const highlighted = {};
ids.forEach(id => (highlighted[id] = true));
return { return {
type: actions.HIGHLIGHT_ANNOTATIONS, type: actions.HIGHLIGHT_ANNOTATIONS,
highlighted: ids, highlighted,
}; };
} }
......
...@@ -380,7 +380,16 @@ describe('sidebar/store/modules/selection', () => { ...@@ -380,7 +380,16 @@ describe('sidebar/store/modules/selection', () => {
describe('highlightAnnotations()', function () { describe('highlightAnnotations()', function () {
it('sets the highlighted annotations', function () { it('sets the highlighted annotations', function () {
store.highlightAnnotations(['id1', 'id2']); store.highlightAnnotations(['id1', 'id2']);
assert.deepEqual(getSelectionState().highlighted, ['id1', 'id2']); assert.deepEqual(getSelectionState().highlighted, {
id1: true,
id2: true,
});
});
it('replaces the current set of highlighted annotations', () => {
store.highlightAnnotations(['id1', 'id2']);
store.highlightAnnotations(['id3']);
assert.deepEqual(getSelectionState().highlighted, { id3: true });
}); });
}); });
......
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