Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions __tests__/fixtures/version-3/001.json
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,11 @@
{
"id": "https://iiif.bodleian.ox.ac.uk/iiif/canvas/9cca8fdd-4a61-4429-8ac1-f648764b4d6d.json",
"type": "Canvas",
"label": "Whole Page",
"label": {
"en": [
"Whole Page"
]
},
"width": 5776,
"height": 9125,
"items": [
Expand Down Expand Up @@ -360,4 +364,4 @@
]
}
]
}
}
59 changes: 59 additions & 0 deletions __tests__/fixtures/version-3/multipleSequences.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"@context": [
"http://iiif.io/api/presentation/3/context.json"
],
"id": "http://foo.test/1/manifest",
"type": "Manifest",
"label": {
"none": ["Version 3 manifest for multiple ranges (sequences behavior) related tests"]
},
"items": [
{
"id": "http://foo.test/1/canvas/c1",
"type": "Canvas",
"label":{"none":["Test Canvas 1"]}
},
{
"id": "http://foo.test/1/canvas/c2",
"type": "Canvas",
"label":{"none":["Test Canvas 2"]}
},
{
"id": "http://foo.test/1/canvas/c3",
"type": "Canvas",
"label":{"none":["Test Canvas 3"]}
}
],
"structures": [
{
"id": "http://foo.test/1/range/root",
"type": "Range",
"behavior": "sequence",
"items": [
{
"id": "http://foo.test/1/canvas/c1",
"type": "Canvas",
"label":{"none":["Test Canvas 1"]}
}
]
},
{
"id": "http://foo.test/1/range/second",
"type": "Range",
"behavior": "sequence",
"items": [
{
"id": "http://foo.test/1/canvas/c2",
"type": "Canvas",
"label":{"none":["Test Canvas 2"]}
},
{
"id": "http://foo.test/1/canvas/c3",
"type": "Canvas",
"label":{"none":["Test Canvas 3"]}
}
]
}
]
}

34 changes: 34 additions & 0 deletions __tests__/integration/mirador/sequence_switching_v3.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* global miradorInstance */

describe('Window Sidebar Sequence Dropdown v3', () => {
beforeAll(async () => {
await page.goto('http://127.0.0.1:4488/__tests__/integration/mirador/blank.html');

await expect(page).toClick('#addBtn');
await expect(page).toClick('.mirador-add-resource-button');
await expect(page).toFill('#manifestURL', 'http://localhost:4488/__tests__/fixtures/version-3/multipleSequences.json');
await expect(page).toClick('#fetchBtn');

await expect(page).toMatchElement('[data-manifestid="http://localhost:4488/__tests__/fixtures/version-3/multipleSequences.json"] button');
await expect(page).toClick('[data-manifestid="http://localhost:4488/__tests__/fixtures/version-3/multipleSequences.json"] button');
});

it('allows the user to switch the v3 ranges (behavior sequences)', async () => {
const windows = await page.evaluate(() => (
miradorInstance.store.getState().windows
));

const windowId = Object.values(windows)
.find(window => window.manifestId === 'http://localhost:4488/__tests__/fixtures/version-3/multipleSequences.json')
.id;

await expect(page).toMatchElement(`#${windowId} button[aria-label="Toggle sidebar"]`);
await expect(page).toClick(`#${windowId} button[aria-label="Toggle sidebar"]`);
await expect(page).toMatchElement(`#${windowId} button[aria-label="Index"]`);
await expect(page).toClick(`#${windowId} button[aria-label="Index"]`);
await expect(page).toClick('#mui-component-select-sequenceId');
await expect(page).toMatchElement('[data-value="http://foo.test/1/range/second"]');
await expect(page).toClick('[data-value="http://foo.test/1/range/second"]');
await expect(page).toMatchElement('p', { text: 'Test Canvas 2' });
});
});
4 changes: 3 additions & 1 deletion __tests__/src/selectors/sequences.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
getSequenceBehaviors,
} from '../../../src/state/selectors/sequences';

jest.mock('uuid', () => ({ v4: () => '00000000-0000-0000-0000-000000000000' }));

describe('getSequences', () => {
describe('with a v2 manifest', () => {
const state = { manifests: { x: { json: manifestFixtureGau } } };
Expand Down Expand Up @@ -49,7 +51,7 @@ describe('getSequences', () => {
const state = { manifests: { x: { json: manifest } } };
const sequences = getSequences(state, { manifestId: 'x' });
expect(sequences.length).toEqual(3);
expect(sequences.map(s => s.id)).toEqual([undefined, 'a', 'b']);
expect(sequences.map(s => s.id)).toEqual(['00000000-0000-0000-0000-000000000000', 'a', 'b']);
});
});

Expand Down
5 changes: 2 additions & 3 deletions src/components/WindowSideBarCanvasPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ export class WindowSideBarCanvasPanel extends Component {
/>
);
}

return (
<CompanionWindow
title={t('canvasIndex')}
Expand All @@ -100,7 +99,7 @@ export class WindowSideBarCanvasPanel extends Component {
<>
{
sequences && sequences.length > 1 && (
<FormControl>
<FormControl className={classes.formControl}>
<Select
MenuProps={{
anchorOrigin: {
Expand All @@ -110,7 +109,7 @@ export class WindowSideBarCanvasPanel extends Component {
getContentAnchorEl: null,
}}
displayEmpty
value={sequenceId}
value={sequenceId || ''}
onChange={this.handleSequenceChange}
name="sequenceId"
classes={{ select: classes.select }}
Expand Down
9 changes: 9 additions & 0 deletions src/containers/WindowSideBarCanvasPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,24 @@ const styles = theme => ({
collectionNavigationButton: {
textTransform: 'none',
},
formControl: {
maxWidth: 190,
},
label: {
paddingLeft: theme.spacing(1),
},
select: {
'& .MuiSelect-icon': {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this works with our themed approach. Can you say more about the need to modify the color here?

Copy link
Copy Markdown
Contributor Author

@MImranAsghar MImranAsghar Nov 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Jack, this is for constraining the size of the select dropdown so it does not extend beyond the sidebar panel when there is a long sequence label.. the reasoning for setting background color to white was to make sure that the 'Arrow icon' in the select bar and the long sequence label don't overlap.

backgroundColor: theme.palette.background.paper,
},
'&:focus': {
backgroundColor: theme.palette.background.paper,
},
},
selectEmpty: {
'& .MuiSelect-icon': {
backgroundColor: theme.palette.background.paper,
},
backgroundColor: theme.palette.background.paper,
},
variantTab: {
Expand Down
4 changes: 3 additions & 1 deletion src/state/sagas/annotations.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import MiradorCanvas from '../../lib/MiradorCanvas';

/** Fetch annotations for a given canvas */
export function* fetchCanvasAnnotations({ canvasId, windowId }) {
const canvas = yield select(getCanvas, { canvasId, windowId });
let canvas = yield select(getCanvas, { canvasId, windowId });
const annotations = yield select(getAnnotations);

canvas = Array.isArray(canvas) ? canvas[0] : canvas;
const miradorCanvas = new MiradorCanvas(canvas);

return yield all([
Expand Down
35 changes: 26 additions & 9 deletions src/state/sagas/windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
getCanvasGrouping, getWindow, getManifestoInstance,
getCompanionWindowIdsForPosition, getManifestSearchService,
getCanvasForAnnotation,
getSequence,
getSelectedContentSearchAnnotationIds,
getSortedSearchAnnotationsForCompanionWindow,
getVisibleCanvasIds,
Expand All @@ -35,6 +36,9 @@ export function* fetchWindowManifest(action) {
const {
collectionPath, id, manifestId,
} = action.payload || action.window;
const {
canvasId, canvasIndex, sequenceId, manifestId
} = action.payload || action.window;

if (!manifestId) return;

Expand Down Expand Up @@ -98,16 +102,29 @@ export function* setWindowStartingCanvas(action) {
);
yield put(thunk);
} else {
const manifestoInstance = yield select(getManifestoInstance, { manifestId });
if (manifestoInstance) {
// set the startCanvas
const miradorManifest = new MiradorManifest(manifestoInstance);
const startCanvas = miradorManifest.startCanvas
|| miradorManifest.canvasAt(canvasIndex || 0)
|| miradorManifest.canvasAt(0);
const currentSequence = yield select(getSequence, { windowId, sequenceId });

if(currentSequence){
let cIndex = canvasIndex ? canvasIndex : 0
const startCanvas = currentSequence.getCanvasByIndex(cIndex)

if (startCanvas) {
const thunk = yield call(setCanvas, windowId, startCanvas.id);
yield put(thunk);
const thunk = yield call(setCanvas, windowId, startCanvas.id);
yield put(thunk);
}
} else {
const manifestoInstance = yield select(getManifestoInstance, { manifestId });

if (manifestoInstance) {
// set the startCanvas
const miradorManifest = new MiradorManifest(manifestoInstance);
const startCanvas = miradorManifest.startCanvas
|| miradorManifest.canvasAt(canvasIndex || 0)
|| miradorManifest.canvasAt(0);
if (startCanvas) {
const thunk = yield call(setCanvas, windowId, startCanvas.id);
yield put(thunk);
}
}
}
}
Expand Down
28 changes: 24 additions & 4 deletions src/state/selectors/canvases.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export const selectInfoResponses = state => miradorSlice(state).infoResponses;

export const getCanvases = createSelector(
[getSequence],
sequence => (sequence && sequence.getCanvases()) || [],
sequence => (sequence && ((sequence.getCanvases && sequence.getCanvases()) || sequence.items))
|| [],
);

/**
Expand All @@ -29,9 +30,16 @@ export const getCanvas = createSelector(
(state, { canvasId }) => canvasId,
],
(sequence, canvasId) => {
let canvas;
if (!sequence || !canvasId) return undefined;

return sequence.getCanvasById(canvasId);
if (typeof sequence.getCanvasById == 'function') {
canvas = sequence.getCanvasById(canvasId);
} else if (sequence.items) {
canvas = sequence.items.filter(c => c.id === canvasId) || [];
}

return canvas;
},
);

Expand All @@ -43,9 +51,21 @@ export const getCurrentCanvas = createSelector(
(sequence, window) => {
if (!sequence || !window) return undefined;

if (!window.canvasId) return sequence.getCanvasByIndex(0);
if (!window.canvasId && (typeof sequence.getCanvasByIndex == 'function')) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the case here that the sequence is not a manifesto Sequence object?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Jack, this is for when the sequence represents a 'Range' manifesto object here which does not provide the 'getCanvasById' or 'getCanvases' function. 'Range' manifesto object has 'items' where it lists all the canvases.

return sequence.getCanvasByIndex(0);
}

if (!window.canvasId) {
const { items } = sequence;
const [firstCanvas] = items;
return firstCanvas;
}

if (typeof sequence.getCanvasById == 'function') {
return sequence.getCanvasById(window.canvasId);
}

return sequence.getCanvasById(window.canvasId);
return sequence.items.filter(c => c.id === window.canvasId) || [];
},
);

Expand Down
52 changes: 45 additions & 7 deletions src/state/selectors/sequences.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createSelector } from 'reselect';
import { TreeNode } from 'manifesto.js/dist-esmodule/TreeNode';
import { v4 as uuid } from 'uuid';
import {
getManifestoInstance,
} from './manifests';
Expand All @@ -16,11 +17,45 @@ export const getSequences = createSelector(

if (v2TopRanges.length === 0 && topRangesOrRoot.length === 1) {
v3RangeSequences = topRangesOrRoot[0].getRanges().filter(r => r.getBehavior() === 'sequence');

/** Add manifesto canvases (items) to the ranges if 'items' property of ranges
* is empty
*/
if (v3RangeSequences.length > 0 && manifest.items && manifest.items.length > 0
&& manifest.items[0].items && manifest.items[0].items.length > 0) {
/** Use manifesto canvases provided in manifest 'items' property to populate
* range 'items'/canvases
*/
const canvases = manifest.items[0].items;

v3RangeSequences.map((sequence) => {
if (sequence.items.length === 0) {
const updatedSequence = sequence;
updatedSequence.items = sequence.canvases.map(canvasId => {
const fullCanvas = canvases.find(c => c.id === canvasId);
return fullCanvas;
});
return updatedSequence;
}
return sequence;
});
}
}

/** v3 sequence (not range sequence): assign id if not there
* Case: only sequence (not range) for v3 manifest is created by manifesto from all
* the items/canvases to display as default; this has id listed as undefined
*/
const manifestSequences = manifest.getSequences();
if (v3RangeSequences && manifestSequences && manifestSequences.length > 0
&& !manifestSequences[0].id) {
manifestSequences[0].id = uuid();
manifestSequences[0].label = 'Table of Contents';
}

const sequences = [].concat(
// v2: multi-sequence manifests, or v3: items
manifest.getSequences(),
manifestSequences,
// v3: all top-level ranges with behavior=sequence
v3RangeSequences,
);
Expand All @@ -37,10 +72,8 @@ export const getSequence = createSelector(
],
(sequences, window, sequenceId) => {
if (!sequences) return null;

if (sequenceId || (window && window.sequenceId)) {
const currentSequence = sequences.find(s => s.id === (sequenceId || window.sequenceId));

if (currentSequence) return currentSequence;
}

Expand All @@ -58,10 +91,15 @@ export const getCanvasIndex = createSelector(
getWindow,
getSequence,
],
(window, sequence) => (
(sequence && window && window.canvasId
&& sequence.getCanvasById(window.canvasId))
|| {}).index || 0,
(window, sequence) => {
let canvas = {};

if (sequence && window && window.canvasId
&& typeof sequence.getCanvasById === 'function') {
canvas = sequence.getCanvasById(window.canvasId);
}
return canvas.index || 0;
},
);

/**
Expand Down