From 21e53d9f36e6eac3bcdeaccaa12068dae4f8dab0 Mon Sep 17 00:00:00 2001 From: Chris Beer <cabeer@stanford.edu> Date: Thu, 14 May 2020 07:50:12 -0700 Subject: [PATCH] Support manifest-level behaviors when selecting a default window view type Fixes #3028 --- __tests__/src/selectors/manifests.test.js | 8 ++++++++ src/state/selectors/manifests.js | 20 ++++++++++++++++++++ src/state/selectors/windows.js | 14 +++++++++++--- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/__tests__/src/selectors/manifests.test.js b/__tests__/src/selectors/manifests.test.js index e946c1ed6..c51962e0d 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 032d22863..7c166c30d 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 8b977269c..4ffbe1422 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; }, ); -- GitLab