Skip to content
Snippets Groups Projects
Commit d61b13a5 authored by Jack Reed's avatar Jack Reed Committed by Chris Beer
Browse files

Move sequence canvas update to a saga

parent 4f992ece
No related branches found
No related tags found
No related merge requests found
......@@ -28,6 +28,7 @@ import {
panToFocusedWindow,
setCurrentAnnotationsOnCurrentCanvas,
fetchInfoResponses,
setCanvasOnNewSequence,
setCollectionPath,
} from '../../../src/state/sagas/windows';
import fixture from '../../fixtures/version-2/019.json';
......@@ -79,6 +80,36 @@ describe('window-level sagas', () => {
});
});
describe('setCanvasOnNewSequence', () => {
it('when a sequenceId is provided, set the canvasId', () => {
const action = {
id: 'x',
payload: {
sequenceId: 'foo',
},
};
return expectSaga(setCanvasOnNewSequence, action)
.provide([
[select(getCanvases, { windowId: 'x' }), [{ id: 'a' }, { id: 'b' }]],
[call(setCanvas, 'x', 'a'), { type: 'setCanvasThunk' }],
])
.put({ type: 'setCanvasThunk' })
.run();
});
it('when a sequenceId is not provided, return', () => {
const action = {
id: 'x',
};
return expectSaga(setCanvasOnNewSequence, action)
.provide([
])
.run()
.then(({ allEffects }) => allEffects.length === 0);
});
});
describe('setWindowStartingCanvas', () => {
it('calls setCanvas if the canvas id was provided', () => {
const action = {
......
......@@ -40,13 +40,10 @@ export class WindowSideBarCanvasPanel extends Component {
}
/** @private */
async handleSequenceChange(event) {
const { setCanvas, updateSequence } = this.props;
await updateSequence(event.target.value);
handleSequenceChange(event) {
const { updateSequence } = this.props;
const { windowId, canvases } = this.props;
const firstCanvasId = canvases[0].id;
setCanvas(windowId, firstCanvasId);
updateSequence(event.target.value);
}
/** @private */
......@@ -162,13 +159,11 @@ export class WindowSideBarCanvasPanel extends Component {
}
WindowSideBarCanvasPanel.propTypes = {
canvases: PropTypes.arrayOf(PropTypes.object),
classes: PropTypes.objectOf(PropTypes.string).isRequired,
collection: PropTypes.object, // eslint-disable-line react/forbid-prop-types
id: PropTypes.string.isRequired,
sequenceId: PropTypes.string,
sequences: PropTypes.arrayOf(PropTypes.object),
setCanvas: PropTypes.func.isRequired,
showMultipart: PropTypes.func.isRequired,
showToc: PropTypes.bool,
t: PropTypes.func.isRequired,
......
......@@ -26,7 +26,6 @@ const mapStateToProps = (state, { id, windowId }) => {
const collectionPath = window.collectionPath || [];
const collectionId = collectionPath && collectionPath[collectionPath.length - 1];
return {
canvases: getCanvases(state, { windowId }),
collection: collectionId && getManifestoInstance(state, { manifestId: collectionId }),
config,
sequenceId: getSequence(state, { windowId }).id,
......@@ -42,7 +41,6 @@ const mapStateToProps = (state, { id, windowId }) => {
* @private
*/
const mapDispatchToProps = (dispatch, { id, windowId }) => ({
setCanvas: (...args) => dispatch(actions.setCanvas(...args)),
showMultipart: () => dispatch(
actions.addOrUpdateCompanionWindow(windowId, { content: 'collection', position: 'right' }),
),
......
......@@ -52,6 +52,18 @@ export function* fetchWindowManifest(action) {
yield call(determineAndShowCollectionDialog, manifestId, id);
}
/** */
export function* setCanvasOnNewSequence(action) {
const windowId = action.id;
if (!action || !action.payload || !action.payload.sequenceId) return;
const canvases = yield select(getCanvases, { windowId });
if (!canvases || !canvases[0] || !canvases[0].id) return;
const thunk = yield call(setCanvas, windowId, canvases[0].id);
yield put(thunk);
}
/** */
export function* setCollectionPath({ manifestId, windowId }) {
const manifestoInstance = yield select(getManifestoInstance, { manifestId });
......@@ -245,6 +257,7 @@ export default function* windowsSaga() {
yield all([
takeEvery(ActionTypes.ADD_WINDOW, fetchWindowManifest),
takeEvery(ActionTypes.UPDATE_WINDOW, fetchWindowManifest),
takeEvery(ActionTypes.UPDATE_WINDOW, setCanvasOnNewSequence),
takeEvery(ActionTypes.SET_CANVAS, setCurrentAnnotationsOnCurrentCanvas),
takeEvery(ActionTypes.SET_CANVAS, fetchInfoResponses),
takeEvery(ActionTypes.UPDATE_COMPANION_WINDOW, fetchCollectionManifests),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment