Skip to content
Snippets Groups Projects
Commit 8c09d203 authored by Chris Beer's avatar Chris Beer
Browse files

Support the IIIF v3 beta specification for provider names

parent b26ad137
No related branches found
No related tags found
No related merge requests found
{
"@context": [
"http://www.w3.org/ns/anno.jsonld",
"http://iiif.io/api/presentation/3/context.json"
],
"id": "https://example.com/with_a_provider.json",
"type": "Manifest",
"provider": [
{
"id": "https://example.org/about",
"type": "Agent",
"label": {"en": ["Example Organization"]},
"homepage": {
"id": "https://example.org/",
"type": "Text",
"label": {"en": ["Example Organization Homepage"]},
"format": "text/html"
},
"logo": {
"id": "https://example.org/images/logo.png",
"type": "Image",
"height": 100,
"width": 120
},
"seeAlso": [
{
"id": "https://data.example.org/about/us.jsonld",
"type": "Dataset",
"format": "application/ld+json",
"profile": "https://schema.org/"
}
]
}
]
}
......@@ -42,4 +42,20 @@ describe('ManifestListItem', () => {
expect(wrapper.find('WithStyles(ButtonBase)').length).toBe(1);
expect(wrapper.find('WithStyles(ButtonBase) WithStyles(Typography)').children().text()).toEqual('http://example.com');
});
it('displays the provider information', () => {
const addWindow = jest.fn();
const wrapper = shallow(
<ManifestListItem manifestId="http://example.com" ready provider="ACME" addWindow={addWindow} />,
).dive();
expect(wrapper.find('WithStyles(Typography).mirador-manifest-list-item-provider').children().text()).toEqual('ACME');
});
it('displays a placeholder provider if no information is given', () => {
const addWindow = jest.fn();
const wrapper = shallow(
<ManifestListItem manifestId="http://example.com" ready addWindow={addWindow} />,
).dive();
expect(wrapper.find('WithStyles(Typography).mirador-manifest-list-item-provider').children().text()).toEqual('addedFromUrl');
});
});
......@@ -2,6 +2,7 @@ import manifesto from 'manifesto.js';
import manifestFixture001 from '../../fixtures/version-2/001.json';
import manifestFixture002 from '../../fixtures/version-2/002.json';
import manifestFixture019 from '../../fixtures/version-2/019.json';
import manifestFixtureWithAProvider from '../../fixtures/version-3/with_a_provider.json';
import {
getCanvasLabel,
getDestructuredMetadata,
......@@ -11,6 +12,7 @@ import {
getManifestCanvases,
getManifestDescription,
getThumbnailNavigationPosition,
getManifestProvider,
getManifestTitle,
getManifestThumbnail,
getWindowViewType,
......@@ -181,6 +183,24 @@ describe('getManifestDescription', () => {
});
});
describe('getManifestProvider', () => {
it('should return manifest provider label', () => {
const manifest = { manifestation: manifesto.create(manifestFixtureWithAProvider) };
const received = getManifestProvider(manifest);
expect(received).toBe('Example Organization');
});
it('should return undefined if manifest undefined', () => {
const received = getManifestProvider(undefined);
expect(received).toBeUndefined();
});
it('should return undefined if no manifestation', () => {
const manifest = {};
const received = getManifestProvider(manifest);
expect(received).toBeUndefined();
});
});
describe('getSelectedCanvas', () => {
const state = {
windows: {
......
......@@ -87,7 +87,7 @@ class ManifestListItem extends React.Component {
</ButtonBase>
</Grid>
<Grid item xs={8} sm={4}>
<Typography>{provider || t('addedFromUrl')}</Typography>
<Typography className={ns('manifest-list-item-provider')}>{provider || t('addedFromUrl')}</Typography>
<Typography>{`${size} items`}</Typography>
</Grid>
......
......@@ -2,7 +2,7 @@ import { compose } from 'redux';
import { connect } from 'react-redux';
import { withNamespaces } from 'react-i18next';
import {
getManifestTitle, getManifestLogo, getManifestThumbnail, getManifestCanvases,
getManifestTitle, getManifestLogo, getManifestThumbnail, getManifestCanvases, getManifestProvider,
} from '../state/selectors';
import * as actions from '../state/actions';
import ManifestListItem from '../components/ManifestListItem';
......@@ -16,6 +16,7 @@ const mapStateToProps = (state, { manifestId }) => {
title: getManifestTitle(manifest),
logo: getManifestLogo(manifest),
thumbnail: getManifestThumbnail(manifest),
provider: getManifestProvider(manifest),
size: getManifestCanvases(manifest).length,
};
};
......
import { LanguageMap } from 'manifesto.js';
/**
* Return the manifest that belongs to a certain window.
......@@ -21,6 +22,23 @@ export function getManifestLogo(manifest) {
&& manifest.manifestation.getLogo();
}
/**
* Return the IIIF v3 provider of a manifest or null
* @param {object} manifest
* @return {String|null}
*/
export function getManifestProvider(manifest) {
if (manifest && manifest.provider) {
return manifest.provider;
}
return manifest
&& manifest.manifestation
&& manifest.manifestation.getProperty('provider')
&& manifest.manifestation.getProperty('provider')[0].label
&& LanguageMap.parse(manifest.manifestation.getProperty('provider')[0].label, manifest.manifestation.options.locale).map(label => label.value)[0];
}
/**
* Return the logo of a manifest or null
* @param {object} manifest
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment