Skip to content
Snippets Groups Projects
Commit ba575555 authored by Johannes Baiter's avatar Johannes Baiter Committed by Chris Beer
Browse files

Fix for canvases with no annotations

When using the Search feature, switching to a canvas without a search
hit (i.e. no annotations targeting it), Mirador would run into a
`TypeError` in the `setCurrentAnnotationsOnCurrentCanvas` saga.
The underlying cause was that the code would try to select the first
annotation for the current canvas, if the currently selected annotation
was not targeting it. This, of course, failed when there were no
annotations targeting the current canvas.

This commit fixes it by adding a check for the presence of annotations
for the current canvas before dispatching the `selectAnnotation`
action.
parent 4b1993c7
Branches
Tags
No related merge requests found
......@@ -221,6 +221,28 @@ describe('window-level sagas', () => {
.then(({ allEffects }) => allEffects.length === 0);
});
it('does nothing when there are no annotations targeting the current canvas', () => {
const action = {
type: ActionTypes.SET_CANVAS,
visibleCanvases: ['a', 'b'],
windowId: 'abc123',
};
return expectSaga(setCurrentAnnotationsOnCurrentCanvas, action)
.provide([
[select(getSearchForWindow,
{ windowId: 'abc123' }), { cwid: { } }],
[select(getAnnotationsBySearch, { canvasIds: ['a', 'b'], companionWindowIds: ['cwid'], windowId: 'abc123' }),
{ }],
])
.run()
// Assert that nothing did happen, see https://github.com/jfairbank/redux-saga-test-plan/issues/137
.then(({ effects }) => {
expect(effects.select.length).toEqual(2);
expect(effects.put).toBeUndefined();
});
});
it('selects content search annotations for the current searches', () => {
const action = {
type: ActionTypes.SET_CANVAS,
......
......
......@@ -129,9 +129,11 @@ export function* setCurrentAnnotationsOnCurrentCanvas({
)))),
);
if (Object.values(annotationBySearch).length > 0) {
// if the currently selected annotation isn't on this canvas, do a thing.
yield put(selectAnnotation(windowId, Object.values(annotationBySearch)[0][0]));
}
}
/** @private */
export function* panToFocusedWindow({ pan, windowId }) {
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment