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

Fix structure display for section items with Canvas references #284

Merged
merged 2 commits into from
Nov 10, 2023
Merged
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
4 changes: 4 additions & 0 deletions public/manifests/dev/lunchroom_manners.json
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,10 @@
]
},
"items": [
{
"id": "http://localhost:3003/dev/lunchroom_manners/canvas/1#t=0,572.034",
"type": "Canvas"
},
{
"id": "http://localhost:3003/dev/lunchroom_manners/range/1-1",
"type": "Range",
Expand Down
4 changes: 4 additions & 0 deletions public/manifests/prod/lunchroom_manners.json
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@
]
},
"items": [
{
"id": "https://iiif-react-media-player.netlify.app/prod/lunchroom_manners/canvas/1#t=0,572.034",
"type": "Canvas"
},
{
"id": "https://iiif-react-media-player.netlify.app/prod/lunchroom_manners/range/1-1",
"type": "Range",
Expand Down
11 changes: 0 additions & 11 deletions src/components/MediaPlayer/VideoJS/VideoJSPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,17 +335,6 @@ function VideoJSPlayer({
]);
}
}
} else if (startTime === null && canvasSegmentsRef.current.length > 0 && isReady) {
// When canvas gets loaded into the player, set the currentNavItem and startTime
// if there's a media fragment starting from time 0.0.
// This then triggers the creation of a fragment highlight in the player's timerail
const firsItem = canvasSegmentsRef.current[0];
const timeFragment = getMediaFragment(firsItem.id, canvasDuration);
if (timeFragment && timeFragment.start === 0) {
manifestDispatch({
item: firsItem, type: 'switchItem'
});
}
}
}, [currentNavItem, isReady, canvasSegments]);

Expand Down
2 changes: 1 addition & 1 deletion src/components/StructuredNavigation/NavUtils/ListItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const ListItem = ({
});

React.useEffect(() => {
if (liRef.current) {
if (liRef.current && !isCanvas) {
if (currentNavItem && currentNavItem.id == itemIdRef.current) {
liRef.current.className += ' active';

Expand Down
7 changes: 6 additions & 1 deletion src/components/StructuredNavigation/StructuredNavigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ const StructuredNavigation = () => {
if (isClicked) {
const clickedItem = canvasSegments.filter(c => c.id === clickedUrl);
if (clickedItem?.length > 0) {
manifestDispatch({ item: clickedItem[0], type: 'switchItem' });
// Only update the current nav item for timespans
// Eliminate Canvas level items unless the structure is empty
const { isCanvas, items } = clickedItem[0];
if (!isCanvas || (items.length == 0 && isCanvas)) {
manifestDispatch({ item: clickedItem[0], type: 'switchItem' });
}
}
const currentCanvasIndex = getCanvasIndex(manifest, getCanvasId(clickedUrl));
const timeFragment = getMediaFragment(clickedUrl, canvasDuration);
Expand Down
43 changes: 39 additions & 4 deletions src/components/StructuredNavigation/StructuredNavigation.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import StructuredNavigation from './StructuredNavigation';
import manifestWoCanvasRefs from '@TestData/transcript-annotation';
import manifest from '@TestData/lunchroom-manners';
import {
withManifestProvider,
Expand All @@ -11,7 +12,7 @@ import playlist from '@TestData/playlist';

describe('StructuredNavigation component', () => {
describe('with manifest', () => {
describe('with structures', () => {
describe('with structures including Canvas references for sections', () => {
beforeEach(() => {
// An example of how we could pass props into
// the tested(in this case: StructuredNavigation) component directly
Expand Down Expand Up @@ -41,17 +42,51 @@ describe('StructuredNavigation component', () => {
expect(screen.getAllByTestId('list').length).toBeGreaterThan(0);
});

test('first item is a section title', () => {
test('first item is a section title as a button', () => {
const firstItem = screen.getAllByTestId('list-item')[0];
expect(firstItem.children[0]).toHaveTextContent(
'Lunchroom Manners'
);
expect(firstItem.children[0]).toHaveClass(
'ramp--structured-nav__section'
);
expect(firstItem.children[0].children[0]).toHaveClass(
'ramp--structured-nav__section-title'
expect(firstItem.children[0].children[0].tagName).toBe('BUTTON');
});
});

describe('with structures without Canvas references for sections', () => {
beforeEach(() => {
const NavWithPlayer = withPlayerProvider(StructuredNavigation, {
initialState: {},
});
const NavWithManifest = withManifestProvider(NavWithPlayer, {
initialState: {
manifest: manifestWoCanvasRefs,
canvasIndex: 0,
canvasSegments: [],
playlist: { isPlaylist: false }
},
});
render(<NavWithManifest />);
});

test('renders successfully', () => {
expect(screen.getByTestId('structured-nav'));
});

test('returns a List of items when structures are present in the manifest', () => {
expect(screen.getAllByTestId('list').length).toBeGreaterThan(0);
});

test('first item is a section title as a span', () => {
const firstItem = screen.getAllByTestId('list-item')[0];
expect(firstItem.children[0]).toHaveTextContent(
'CD1 - Mahler, Symphony No.3'
);
expect(firstItem.children[0]).toHaveClass(
'ramp--structured-nav__section'
);
expect(firstItem.children[0].children[0].tagName).toBe('SPAN');
});
});

Expand Down
4 changes: 3 additions & 1 deletion src/services/iiif-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,9 @@ export function getStructureRanges(manifest) {
label: label,
isTitle: canvases.length === 0 ? true : false,
rangeId: range.id,
id: canvases.length > 0 ? canvases[0] : undefined,
id: canvases.length > 0
? isCanvas ? `${canvases[0].split(',')[0]},` : canvases[0]
: undefined,
isEmpty: isEmpty,
isCanvas: isCanvas,
itemIndex: isCanvas ? cIndex : undefined,
Expand Down
18 changes: 18 additions & 0 deletions src/services/iiif-parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,24 @@ describe('iiif-parser', () => {
expect(firstTimespan).toEqual(firstStructCanvas);
});

it('returns mediafragment with only start time for sections with structure', () => {
const { structures, timespans } = iiifParser.getStructureRanges(lunchroomManifest);
expect(structures).toHaveLength(1);
expect(timespans).toHaveLength(12);

const firstStructCanvas = structures[0];
expect(firstStructCanvas.label).toEqual('Lunchroom Manners');
expect(firstStructCanvas.items).toHaveLength(3);
expect(firstStructCanvas.isCanvas).toBeTruthy();
expect(firstStructCanvas.isEmpty).toBeFalsy();
expect(firstStructCanvas.isTitle).toBeFalsy();
expect(firstStructCanvas.rangeId).toEqual('https://example.com/manifest/lunchroom_manners/range/1');
expect(firstStructCanvas.id).toEqual('https://example.com/manifest/lunchroom_manners/canvas/1#t=0,');
expect(firstStructCanvas.isClickable).toBeTruthy();
expect(firstStructCanvas.duration).toEqual('11:00');

});

it('returns [] when structure is not present', () => {
const { structures, timespans } = iiifParser.getStructureRanges(manifestWoStructure);
expect(structures).toEqual([]);
Expand Down
6 changes: 5 additions & 1 deletion src/test_data/lunchroom-manners.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ export default {
type: 'Range',
label: { en: ['Lunchroom Manners'] },
items: [
{
id: 'https://example.com/manifest/lunchroom_manners/canvas/1#t=0,660',
type: 'Canvas',
},
{
id: 'https://example.com/manifest/lunchroom_manners/range/1-1',
type: 'Range',
Expand All @@ -273,7 +277,7 @@ export default {
label: { en: ['Using Soap'] },
items: [
{
id: 'https://example.com/manifest/lunchroom_manners/canvas/1#t=157,160',
id: 'https://example.com/manifest/lunchroom_manners/canvas/1#t=0,160',
type: 'Canvas',
},
],
Expand Down