Skip to content

Commit

Permalink
Add multi-seq select option to display..
Browse files Browse the repository at this point in the history
... all items including ToC for v3, other changes
- Display an option in multi seq select bar that displays all the canvases in v3 sequence along with ToC
- Constrain the size of multi seqs select bar
- Change sequences test to expect uuid instead of undefined id for first v3 sequence
- Add checkes in getSequences selector before setting id for first v3 sequence which has undefined id initially
  • Loading branch information
MImranAsghar committed Nov 10, 2020
1 parent 90c5e53 commit 1638681
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 13 deletions.
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "^4.0.0-alpha.53",
"@researchgate/react-intersection-observer": "^1.0.0",
"canvas": "^2.6.1",
"classnames": "^2.2.6",
"clsx": "^1.0.4",
"deepmerge": "^4.2.2",
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': {
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
26 changes: 18 additions & 8 deletions src/state/selectors/sequences.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createSelector } from 'reselect';
import { TreeNode } from 'manifesto.js/dist-esmodule/TreeNode';
import { v3 } from 'uuid';
import { v4 as uuid } from 'uuid';
import {
getManifestoInstance,
} from './manifests';
Expand All @@ -23,19 +23,29 @@ export const getSequences = createSelector(
const canvases = manifest.items[0].items;

v3RangeSequences.map((sequence) => {
const updatedSequence = sequence;
updatedSequence.items = sequence.canvases.map(canvasId => {
const fullCanvas = canvases.find(c => c.id === canvasId);
return fullCanvas;
});
return updatedSequence;
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) {
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 Down

0 comments on commit 1638681

Please sign in to comment.