Skip to content
Snippets Groups Projects
Unverified Commit d1ef9941 authored by Jack Reed's avatar Jack Reed Committed by GitHub
Browse files

Merge pull request #3030 from ProjectMirador/3028-behavior

Support manifest-level behaviors when selecting a default window view type
parents b56d147d 21e53d9f
No related branches found
No related tags found
No related merge requests found
......@@ -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 } } };
......
......@@ -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) => {
......
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;
},
);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment