diff --git a/__tests__/src/selectors/manifests.test.js b/__tests__/src/selectors/manifests.test.js index e946c1ed6aae4e44f8c5165043b581abaa9df3df..c51962e0d3e0811ac0733163ed9fa164a9950efa 100644 --- a/__tests__/src/selectors/manifests.test.js +++ b/__tests__/src/selectors/manifests.test.js @@ -27,6 +27,7 @@ import { getManifestUrl, getManifestViewingDirection, getManifestViewingHint, + getManifestBehaviors, getManifestTreeStructure, getMetadataLocales, getRequiredStatement, @@ -505,6 +506,13 @@ describe('getManifestViewingHint', () => { }); }); +describe('getManifestBehaviors', () => { + it('gets from the manifest', () => { + const state = { manifests: { x: { json: manifestFixturev3001 } } }; + expect(getManifestBehaviors(state, { manifestId: 'x' })).toEqual(['individuals']); + }); +}); + describe('getManifestViewingDirection', () => { it('gets from the manifest', () => { const state = { manifests: { x: { json: manifestFixture001 } } }; diff --git a/src/state/selectors/manifests.js b/src/state/selectors/manifests.js index 032d2286350dab4505b34ec9b6f56603cc324f89..7c166c30dfd79bc3cd43fee765562df70009fde6 100644 --- a/src/state/selectors/manifests.js +++ b/src/state/selectors/manifests.js @@ -418,6 +418,26 @@ export const getManifestViewingHint = createSelector( }, ); +/** + * Returns the behaviors viewing hint for the manifest + * @param {object} state + * @param {object} props + * @param {string} props.manifestId + * @param {string} props.windowId + * @return {Number} + */ +export const getManifestBehaviors = createSelector( + [getManifestoInstance], + (manifest) => { + if (!manifest) return []; + const behaviors = manifest.getProperty('behavior'); + + if (!behaviors) return []; + if (Array.isArray(behaviors)) return behaviors; + return [behaviors]; + }, +); + export const getManifestViewingDirection = createSelector( [getManifestoInstance], (manifest) => { diff --git a/src/state/selectors/windows.js b/src/state/selectors/windows.js index 8b977269c086c2d06758c1216de3dc016b0657b2..4ffbe1422d892edc4cf24a0937c86548f9c5d5cf 100644 --- a/src/state/selectors/windows.js +++ b/src/state/selectors/windows.js @@ -1,5 +1,10 @@ import { createSelector } from 'reselect'; -import { getManifestTitle, getManifestViewingHint, getManifestoInstance } from './manifests'; +import { + getManifestTitle, + getManifestBehaviors, + getManifestViewingHint, + getManifestoInstance, +} from './manifests'; import { getDefaultView } from './config'; import { getWorkspaceType } from './workspace'; @@ -78,14 +83,17 @@ export const getWindowViewType = createSelector( [ getWindow, getManifestViewingHint, + getManifestBehaviors, getDefaultView, ], - (window, manifestViewingHint, defaultView) => { + (window, manifestViewingHint, manifestBehaviors, defaultView) => { const lookup = { individuals: 'single', paged: 'book', }; - return (window && window.view) || lookup[manifestViewingHint] || defaultView; + return (window && window.view) + || lookup[manifestBehaviors.find(b => lookup[b]) || manifestViewingHint] + || defaultView; }, );