-
Notifications
You must be signed in to change notification settings - Fork 255
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
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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"]} | ||
} | ||
] | ||
} | ||
] | ||
} | ||
|
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' }); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)) | ||
|| [], | ||
); | ||
|
||
/** | ||
|
@@ -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; | ||
}, | ||
); | ||
|
||
|
@@ -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')) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
}, | ||
); | ||
|
||
|
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'; | ||
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
); | ||
|
@@ -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; | ||
} | ||
|
||
|
@@ -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; | ||
}, | ||
); | ||
|
||
/** | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.