Skip to content
Snippets Groups Projects
Unverified Commit 806cf1ce authored by Jessie Keck's avatar Jessie Keck Committed by GitHub
Browse files

Merge pull request #1889 from ProjectMirador/bugfix-1880

Bugfix: clicking info panel before manifest loaded throws error. Clos…
parents 92a8e98c 20ee6b2e
No related branches found
No related tags found
No related merge requests found
......@@ -206,10 +206,10 @@ describe('getSelectedCanvas', () => {
);
});
it('should return an empty object when there is no manifestation to get a canvas from', () => {
it('should return undefined when there is no manifestation to get a canvas from', () => {
const selectedCanvas = getSelectedCanvas(noManifestationState, 'a');
expect(selectedCanvas).toEqual({});
expect(selectedCanvas).toBeUndefined();
});
});
......@@ -224,15 +224,14 @@ describe('getCanvasLabel', () => {
expect(received).toBe('Whole Page');
});
it('should return the given canvas index (+1) if the canvas is undefined', () => {
expect(getCanvasLabel(undefined)).toBe(1);
expect(getCanvasLabel(undefined, 2)).toBe(3);
it('should return undefined if the canvas is undefined', () => {
expect(getCanvasLabel(undefined)).toBeUndefined();
});
it('should return the canvas index (+1) if no manifestation', () => {
const canvas = { getLabel: () => {} };
const received = getCanvasLabel(canvas);
expect(received).toBe(1);
it('should return the canvas index as (+1) as string if no label given', () => {
const canvas = { getLabel: () => [] };
const received = getCanvasLabel(canvas, 42);
expect(received).toBe('43');
});
});
......
......@@ -9,6 +9,7 @@ import {
getManifestTitle,
getSelectedCanvas,
getWindowManifest,
getCanvasDescription,
} from '../state/selectors';
import WindowSideBarInfoPanel from '../components/WindowSideBarInfoPanel';
......@@ -22,7 +23,7 @@ const mapStateToProps = (state, { windowId }) => ({
getSelectedCanvas(state, windowId),
state.windows[windowId].canvasIndex,
),
canvasDescription: getSelectedCanvas(state, windowId).getProperty('description'),
canvasDescription: getCanvasDescription(getSelectedCanvas(state, windowId)),
canvasMetadata: getDestructuredMetadata(getSelectedCanvas(state, windowId)),
manifestLabel: getManifestTitle(getWindowManifest(state, windowId)),
manifestDescription: getManifestDescription(getWindowManifest(state, windowId)),
......
......@@ -56,11 +56,11 @@ export function getSelectedCanvas(state, windowId) {
const manifest = getWindowManifest(state, windowId);
const { canvasIndex } = state.windows[windowId];
if (!manifest.manifestation) {
return {};
}
return manifest.manifestation.getSequences()[0].getCanvasByIndex(canvasIndex);
return manifest
&& manifest.manifestation
&& manifest.manifestation
.getSequences()[0]
.getCanvasByIndex(canvasIndex);
}
......@@ -111,10 +111,13 @@ export function getManifestDescription(manifest) {
* @return {String|Integer}
*/
export function getCanvasLabel(canvas, canvasIndex) {
return (canvas
&& canvas.getLabel()
&& canvas.getLabel().map(label => label.value)[0])
|| (canvasIndex || 0) + 1;
if (!canvas) {
return undefined;
}
if (canvas.getLabel().length > 0) {
return canvas.getLabel().map(label => label.value)[0];
}
return String(canvasIndex + 1);
}
/**
......@@ -134,3 +137,13 @@ export function getDestructuredMetadata(iiifResoruce) {
}))
);
}
/**
* Return canvas description
* @param {object} canvas
* @param {String}
*/
export function getCanvasDescription(canvas) {
return canvas
&& canvas.getProperty('description');
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment