Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get multi-sequences to work for v3 ranges/seqs #3333

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
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
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
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: 'white',
},
'&:focus': {
backgroundColor: theme.palette.background.paper,
},
},
selectEmpty: {
'& .MuiSelect-icon': {
backgroundColor: 'white',
},
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
29 changes: 25 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 @@ -41,11 +49,24 @@ export const getCurrentCanvas = createSelector(
getWindow,
],
(sequence, window) => {
let canvas;
if (!sequence || !window) return undefined;

if (!window.canvasId) return sequence.getCanvasByIndex(0);
if (!window.canvasId && (typeof sequence.getCanvasByIndex == 'function')) {
Copy link
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
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.

canvas = sequence.getCanvasByIndex(0);
} else if (!window.canvasId) {
const { items } = sequence;
const [firstCanvas] = items;
canvas = firstCanvas;
}

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

return sequence.getCanvasById(window.canvasId);
return canvas;
},
);

Expand Down
45 changes: 38 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,35 @@ export const getSequences = createSelector(

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

if (v3RangeSequences.length > 0 && manifest.items && manifest.items.length > 0
&& manifest.items[0].items && manifest.items[0].items.length > 0) {
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
const manifestSequences = manifest.getSequences();
if (v3RangeSequences && manifestSequences && manifestSequences.length > 0
&& !manifestSequences[0].id) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you say more about the case where an id would not be present?

Copy link
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.

For a v3 range, manifest.getSequences() always seems to return a sequence manifesto object with all the items/manifesto canvases listed by default, even if it is not listed as range sequence. I thought displaying this as an option in the select dropdown (in addition to ranges with sequence behavior) would allow users to view all the canvases and, more importantly, the top-level Table of Contents can be displayed when this option is selected. This sequence object has the id as undefined because manifesto tries to get it from the 'items' property.

manifestSequences[0].id = uuid();
}

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 +62,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 +81,18 @@ 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);
} else {
canvas = {};
}

return canvas.index || 0;
},
);

/**
Expand Down