Skip to content
Snippets Groups Projects
Unverified Commit 167b8600 authored by aeschylus's avatar aeschylus Committed by GitHub
Browse files

Merge pull request #2010 from ProjectMirador/2006-annos-from-otherContent

Adds in basic otherContent annotation fetching
parents 4ec1b63e 42e021f2
Branches
Tags
No related merge requests found
Showing
with 649 additions and 5 deletions
{
"@context": "http://iiif.io/api/presentation/2/context.json",
"@id": "https://iiif.harvardartmuseums.org/manifests/object/299843",
"@type": "sc:Manifest",
"attribution": "Harvard Art Museums",
"description": "",
"label": "Self-Portrait Dedicated to Paul Gauguin",
"logo": {
"@id": "https://ids.lib.harvard.edu/ids/iiif/437958013/full/!800,800/0/native.jpg",
"service": {
"@context": "http://iiif.io/api/image/2/context.json",
"@id": "https://ids.lib.harvard.edu/ids/iiif/437958013",
"profile": "http://iiif.io/api/image/2/level2.json"
}
},
"metadata": [
{
"label": "Date",
"value": "1888"
},
{
"label": "Classification",
"value": "Paintings"
},
{
"label": "Credit Line",
"value": "Harvard Art Museums/Fogg Museum, Bequest from the Collection of Maurice Wertheim, Class of 1906"
},
{
"label": "Object Number",
"value": "1951.65"
},
{
"label": "People",
"value": [
"Artist: Vincent van Gogh, Dutch, 1853 - 1890"
]
},
{
"label": "Medium",
"value": "Oil on canvas"
},
{
"label": "Dimensions",
"value": "61.5 x 50.3 cm (24 3/16 x 19 13/16 in.)\r\nframed: 90.4 x 79.7 x 8.3 cm (35 9/16 x 31 3/8 x 3 1/4 in.)"
},
{
"label": "Provenance",
"value": "Vincent van Gogh, Arles, (1888,) gift; to Paul Gauguin, (1888-1897) sold. [Ambroise Vollard, Paris.] [Paul Cassirer Gallery, Berlin.] Dr. Hugo von Tschudi, Berlin, (1906-1911), by descent; to his widow, Angela von Tschudi, Munich (1911-1919), to Neue Staatsgalerie, Munich (1919-1938); removed from the collection by the National Socialist (Nazi) authorities in 1938, consigned; to [Theodor Fischer Gallery, Lucerne, Switzerland, for sale June 30, 1939, lot 45]; to Maurice Wertheim (1939-1951) bequest; to Fogg Art Museum, 1951.\r\n\r\n \r\n\r\nNotes:\r\nGauguin sold the painting for Fr 300\r\nHugo von Tschudi bought the painting for the Nationalgalerie, Berlin, with funds from sponsors, but did not submit it to the Kaiser for pre-approval. He took the painting to Munich when he assumed a post there.\r\nAccording to Stephanie Barron, the van Gogh was removed from the Neue Staatsgalerie on March 27, 1938 and stored at Schloss Niederschönhausen in August of that year. (Barron, 1990,pp. 135-146)\r\n"
}
],
"rendering": {
"@id": "https://www.harvardartmuseums.org/collections/object/299843",
"format": "text/html",
"label": "Full record view"
},
"sequences": [
{
"@id": "https://iiif.harvardartmuseums.org/manifests/object/299843/sequence/normal",
"@type": "sc:Sequence",
"canvases": [
{
"@id": "https://iiif.harvardartmuseums.org/manifests/object/299843/canvas/canvas-47174896",
"@type": "sc:Canvas",
"height": 2550,
"images": [
{
"@id": "https://iiif.harvardartmuseums.org/manifests/object/299843/annotation/anno-47174896",
"@type": "oa:Annotation",
"motivation": "sc:painting",
"on": "https://iiif.harvardartmuseums.org/manifests/object/299843/canvas/canvas-47174896",
"resource": {
"@id": "https://ids.lib.harvard.edu/ids/iiif/47174896/full/full/0/native.jpg",
"@type": "dctypes:Image",
"format": "image/jpeg",
"height": 2550,
"service": {
"@context": "http://iiif.io/api/image/2/context.json",
"@id": "https://ids.lib.harvard.edu/ids/iiif/47174896",
"profile": "http://iiif.io/api/image/2/level2.json"
},
"width": 2087
}
}
],
"label": "1",
"otherContent": [
{
"@id": "https://iiif.harvardartmuseums.org/manifests/object/299843/list/47174896",
"@type": "sc:AnnotationList"
}
],
"width": 2087
},
{
"@id": "https://iiif.harvardartmuseums.org/manifests/object/299843/canvas/canvas-18737483",
"@type": "sc:Canvas",
"height": 2550,
"images": [
{
"@id": "https://iiif.harvardartmuseums.org/manifests/object/299843/annotation/anno-18737483",
"@type": "oa:Annotation",
"motivation": "sc:painting",
"on": "https://iiif.harvardartmuseums.org/manifests/object/299843/canvas/canvas-18737483",
"resource": {
"@id": "https://ids.lib.harvard.edu/ids/iiif/18737483/full/full/0/native.jpg",
"@type": "dctypes:Image",
"format": "image/jpeg",
"height": 2550,
"service": {
"@context": "http://iiif.io/api/image/2/context.json",
"@id": "https://ids.lib.harvard.edu/ids/iiif/18737483",
"profile": "http://iiif.io/api/image/2/level2.json"
},
"width": 2088
}
}
],
"label": "2",
"otherContent": [
{
"@id": "https://iiif.harvardartmuseums.org/manifests/object/299843/list/18737483",
"@type": "sc:AnnotationList"
}
],
"width": 2088
},
{
"@id": "https://iiif.harvardartmuseums.org/manifests/object/299843/canvas/canvas-47174892",
"@type": "sc:Canvas",
"height": 2550,
"images": [
{
"@id": "https://iiif.harvardartmuseums.org/manifests/object/299843/annotation/anno-47174892",
"@type": "oa:Annotation",
"motivation": "sc:painting",
"on": "https://iiif.harvardartmuseums.org/manifests/object/299843/canvas/canvas-47174892",
"resource": {
"@id": "https://ids.lib.harvard.edu/ids/iiif/47174892/full/full/0/native.jpg",
"@type": "dctypes:Image",
"format": "image/jpeg",
"height": 2550,
"service": {
"@context": "http://iiif.io/api/image/2/context.json",
"@id": "https://ids.lib.harvard.edu/ids/iiif/47174892",
"profile": "http://iiif.io/api/image/2/level2.json"
},
"width": 2259
}
}
],
"label": "3",
"otherContent": [
{
"@id": "https://iiif.harvardartmuseums.org/manifests/object/299843/list/47174892",
"@type": "sc:AnnotationList"
}
],
"width": 2259
},
{
"@id": "https://iiif.harvardartmuseums.org/manifests/object/299843/canvas/canvas-43182083",
"@type": "sc:Canvas",
"height": 2550,
"images": [
{
"@id": "https://iiif.harvardartmuseums.org/manifests/object/299843/annotation/anno-43182083",
"@type": "oa:Annotation",
"motivation": "sc:painting",
"on": "https://iiif.harvardartmuseums.org/manifests/object/299843/canvas/canvas-43182083",
"resource": {
"@id": "https://ids.lib.harvard.edu/ids/iiif/43182083/full/full/0/native.jpg",
"@type": "dctypes:Image",
"format": "image/jpeg",
"height": 2550,
"service": {
"@context": "http://iiif.io/api/image/2/context.json",
"@id": "https://ids.lib.harvard.edu/ids/iiif/43182083",
"profile": "http://iiif.io/api/image/2/level2.json"
},
"width": 2100
}
}
],
"label": "4",
"otherContent": [
{
"@id": "https://iiif.harvardartmuseums.org/manifests/object/299843/list/43182083",
"@type": "sc:AnnotationList"
}
],
"width": 2100
},
{
"@id": "https://iiif.harvardartmuseums.org/manifests/object/299843/canvas/canvas-43183405",
"@type": "sc:Canvas",
"height": 2550,
"images": [
{
"@id": "https://iiif.harvardartmuseums.org/manifests/object/299843/annotation/anno-43183405",
"@type": "oa:Annotation",
"motivation": "sc:painting",
"on": "https://iiif.harvardartmuseums.org/manifests/object/299843/canvas/canvas-43183405",
"resource": {
"@id": "https://ids.lib.harvard.edu/ids/iiif/43183405/full/full/0/native.jpg",
"@type": "dctypes:Image",
"format": "image/jpeg",
"height": 2550,
"service": {
"@context": "http://iiif.io/api/image/2/context.json",
"@id": "https://ids.lib.harvard.edu/ids/iiif/43183405",
"profile": "http://iiif.io/api/image/2/level2.json"
},
"width": 2082
}
}
],
"label": "5",
"otherContent": [
{
"@id": "https://iiif.harvardartmuseums.org/manifests/object/299843/list/43183405",
"@type": "sc:AnnotationList"
}
],
"width": 2082
},
{
"@id": "https://iiif.harvardartmuseums.org/manifests/object/299843/canvas/canvas-43183422",
"@type": "sc:Canvas",
"height": 2550,
"images": [
{
"@id": "https://iiif.harvardartmuseums.org/manifests/object/299843/annotation/anno-43183422",
"@type": "oa:Annotation",
"motivation": "sc:painting",
"on": "https://iiif.harvardartmuseums.org/manifests/object/299843/canvas/canvas-43183422",
"resource": {
"@id": "https://ids.lib.harvard.edu/ids/iiif/43183422/full/full/0/native.jpg",
"@type": "dctypes:Image",
"format": "image/jpeg",
"height": 2550,
"service": {
"@context": "http://iiif.io/api/image/2/context.json",
"@id": "https://ids.lib.harvard.edu/ids/iiif/43183422",
"profile": "http://iiif.io/api/image/2/level2.json"
},
"width": 2093
}
}
],
"label": "6",
"otherContent": [
{
"@id": "https://iiif.harvardartmuseums.org/manifests/object/299843/list/43183422",
"@type": "sc:AnnotationList"
}
],
"width": 2093
}
],
"viewingHint": "individuals"
}
],
"thumbnail": {
"@id": "https://ids.lib.harvard.edu/ids/iiif/47174896/full/!170,170/0/native.jpg",
"service": {
"@context": "http://iiif.io/api/image/2/context.json",
"@id": "https://ids.lib.harvard.edu/ids/iiif/47174896",
"profile": "http://iiif.io/api/image/2/level2.json"
}
},
"within": "https://www.harvardartmuseums.org/collections"
}
/* global miradorInstance */
describe('Annotations in Mirador', () => {
beforeAll(async () => {
await page.goto('http://127.0.0.1:4488/__tests__/integration/mirador/');
await expect(page).toMatchElement('.mirador-window');
await page.waitFor(1000);
});
it('stores annotations in state by canvasId', async () => {
const annotations = await page.evaluate(() => (
miradorInstance.store.getState().annotations
));
await expect(Object.keys(annotations).length).toEqual(1);
});
});
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import * as actions from '../../../src/state/actions';
import ActionTypes from '../../../src/state/actions/action-types';
const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);
describe('annotation actions', () => {
describe('requestAnnotation', () => {
it('requests an annotation from given a url', () => {
const canvasId = 'foo';
const annotationId = 'abc123';
const expectedAction = {
type: ActionTypes.REQUEST_ANNOTATION,
canvasId,
annotationId,
};
expect(actions.requestAnnotation(canvasId, annotationId)).toEqual(expectedAction);
});
});
describe('receiveAnnotation', () => {
it('recieves an annotation', () => {
const canvasId = 'foo';
const annotationId = 'abc123';
const json = {
annotationId,
content: 'annotation request',
};
const expectedAction = {
type: ActionTypes.RECEIVE_ANNOTATION,
canvasId,
annotationId,
annotationJson: json,
};
expect(actions.receiveAnnotation(canvasId, annotationId, json)).toEqual(expectedAction);
});
});
describe('fetchAnnotation', () => {
let store = null;
beforeEach(() => {
store = mockStore({});
});
describe('success response', () => {
beforeEach(() => {
fetch.mockResponseOnce(JSON.stringify({ data: '12345' })); // eslint-disable-line no-undef
});
it('dispatches the REQUEST_ANNOTATION action', () => {
store.dispatch(actions.fetchAnnotation(
'https://iiif.harvardartmuseums.org/manifests/object/299843/canvas/canvas-47174896',
'https://iiif.harvardartmuseums.org/manifests/object/299843/list/47174896',
));
expect(store.getActions()).toEqual([
{
canvasId: 'https://iiif.harvardartmuseums.org/manifests/object/299843/canvas/canvas-47174896',
annotationId: 'https://iiif.harvardartmuseums.org/manifests/object/299843/list/47174896',
type: 'REQUEST_ANNOTATION',
},
]);
});
it('dispatches the REQUEST_ANNOTATION and then RECEIVE_ANNOTATION', () => {
store.dispatch(actions.fetchAnnotation(
'https://iiif.harvardartmuseums.org/manifests/object/299843/canvas/canvas-47174896',
'https://iiif.harvardartmuseums.org/manifests/object/299843/list/47174896',
))
.then(() => {
const expectedActions = store.getActions();
expect(expectedActions).toEqual([
{
canvasId: 'https://iiif.harvardartmuseums.org/manifests/object/299843/canvas/canvas-47174896',
annotationId: 'https://iiif.harvardartmuseums.org/manifests/object/299843/list/47174896',
type: 'REQUEST_ANNOTATION',
},
{
canvasId: 'https://iiif.harvardartmuseums.org/manifests/object/299843/canvas/canvas-47174896',
annotationId: 'https://iiif.harvardartmuseums.org/manifests/object/299843/list/47174896',
annotationJson: { data: '12345' },
type: 'RECEIVE_ANNOTATION',
},
]);
});
});
});
describe('error response', () => {
it('dispatches the REQUEST_ANNOTATION and then RECEIVE_ANNOTATION', () => {
store.dispatch(actions.fetchAnnotation(
'https://iiif.harvardartmuseums.org/manifests/object/299843/canvas/canvas-47174896',
'https://iiif.harvardartmuseums.org/manifests/object/299843/list/47174896',
))
.then(() => {
const expectedActions = store.getActions();
expect(expectedActions).toEqual([
{
canvasId: 'https://iiif.harvardartmuseums.org/manifests/object/299843/canvas/canvas-47174896',
annotationId: 'https://iiif.harvardartmuseums.org/manifests/object/299843/list/47174896',
type: 'REQUEST_ANNOTATION',
},
{
canvasId: 'https://iiif.harvardartmuseums.org/manifests/object/299843/canvas/canvas-47174896',
annotationId: 'https://iiif.harvardartmuseums.org/manifests/object/299843/list/47174896',
error: new Error('invalid json response body at undefined reason: Unexpected end of JSON input'),
type: 'RECEIVE_ANNOTATION_FAILURE',
},
]);
});
});
});
});
});
......@@ -6,6 +6,7 @@ import OSDViewer from '../../../src/containers/OpenSeadragonViewer';
import ViewerNavigation from '../../../src/containers/ViewerNavigation';
import fixture from '../../fixtures/version-2/019.json';
import emptyCanvasFixture from '../../fixtures/version-2/emptyCanvas.json';
import otherContentFixture from '../../fixtures/version-2/299843.json';
let mockManifest = {
id: 123,
......@@ -23,6 +24,7 @@ function createWrapper(props) {
<WindowViewer
infoResponses={{}}
fetchInfoResponse={() => {}}
fetchAnnotation={() => {}}
manifest={mockManifest}
window={mockWindow}
{...props}
......@@ -149,6 +151,17 @@ describe('WindowViewer', () => {
);
expect(mockFnCanvas2).toHaveBeenCalledTimes(0);
});
it('calls fetchAnnotation when otherContent is present', () => {
const mockFnAnno = jest.fn();
mockManifest = {
id: 123,
manifestation: manifesto.create(otherContentFixture),
};
wrapper = createWrapper(
{ manifest: mockManifest, fetchAnnotation: mockFnAnno },
);
expect(mockFnAnno).toHaveBeenCalledTimes(1);
});
});
describe('componentDidUpdate', () => {
......
......@@ -3,6 +3,7 @@ import ManifestoCanvas from '../../../src/lib/ManifestoCanvas';
import fixture from '../../fixtures/version-2/019.json';
import imagev1Fixture from '../../fixtures/version-2/Osbornfa1.json';
import emptyCanvasFixture from '../../fixtures/version-2/emptyCanvas.json';
import otherContentFixture from '../../fixtures/version-2/299843.json';
describe('ManifestoCanvas', () => {
let instance;
......@@ -11,6 +12,24 @@ describe('ManifestoCanvas', () => {
manifesto.create(fixture).getSequences()[0].getCanvases()[0],
);
});
describe('annotationListUris', () => {
describe('when no annotationLists are present', () => {
it('returns an empty array', () => {
expect(instance.annotationListUris).toEqual([]);
});
});
describe('when annotationLists are present', () => {
it('returns an array of uris', () => {
const otherContentInstance = new ManifestoCanvas(
manifesto.create(otherContentFixture).getSequences()[0].getCanvases()[0],
);
expect(otherContentInstance.annotationListUris.length).toEqual(1);
expect(otherContentInstance.annotationListUris).toEqual([
'https://iiif.harvardartmuseums.org/manifests/object/299843/list/47174896',
]);
});
});
});
describe('canonicalImageUri', () => {
it('calls manifestos method to return a canonical imageUri', () => {
expect(instance.canonicalImageUri).toEqual(
......
import { annotationsReducer } from '../../../src/state/reducers/annotations';
import ActionTypes from '../../../src/state/actions/action-types';
describe('annotation reducer', () => {
it('should handle REQUEST_ANNOTATION', () => {
expect(annotationsReducer({}, {
type: ActionTypes.REQUEST_ANNOTATION,
canvasId: 'foo',
annotationId: 'abc123',
})).toEqual({
foo: {
abc123: {
id: 'abc123',
isFetching: true,
},
},
});
});
it('should handle RECEIVE_ANNOTATION', () => {
expect(annotationsReducer(
{
foo: {
abc123: {
id: 'abc123',
isFetching: true,
},
},
},
{
type: ActionTypes.RECEIVE_ANNOTATION,
canvasId: 'foo',
annotationId: 'abc123',
annotationJson: {
id: 'abc123',
'@type': 'sc:AnnotationList',
content: 'anno stuff',
},
},
)).toMatchObject({
foo: {
abc123: {
id: 'abc123',
isFetching: false,
json: {},
},
},
});
});
it('should handle RECEIVE_ANNOTATION_FAILURE', () => {
expect(annotationsReducer(
{
foo: {
abc123: {
id: 'abc123',
isFetching: true,
},
},
},
{
type: ActionTypes.RECEIVE_ANNOTATION_FAILURE,
canvasId: 'foo',
annotationId: 'abc123',
error: "This institution didn't enable CORS.",
},
)).toEqual({
foo: {
abc123: {
id: 'abc123',
isFetching: false,
error: "This institution didn't enable CORS.",
},
},
});
});
});
......@@ -26,14 +26,18 @@ export class WindowViewer extends Component {
* Request the initial canvas on mount
*/
componentDidMount() {
const { fetchInfoResponse } = this.props;
const { fetchInfoResponse, fetchAnnotation } = this.props;
if (!this.infoResponseIsInStore()) {
this.currentCanvases().forEach((canvas) => {
const { imageInformationUri } = new ManifestoCanvas(canvas);
const manifestoCanvas = new ManifestoCanvas(canvas);
const { imageInformationUri } = manifestoCanvas;
if (imageInformationUri) {
fetchInfoResponse(imageInformationUri);
}
manifestoCanvas.annotationListUris.forEach((uri) => {
fetchAnnotation(manifestoCanvas.canvas.id, uri);
});
});
}
}
......@@ -43,15 +47,19 @@ export class WindowViewer extends Component {
* Request a new canvas if it is needed
*/
componentDidUpdate(prevProps) {
const { window, fetchInfoResponse } = this.props;
const { window, fetchInfoResponse, fetchAnnotation } = this.props;
if (prevProps.window.view !== window.view
|| (prevProps.window.canvasIndex !== window.canvasIndex && !this.infoResponseIsInStore())
) {
this.currentCanvases().forEach((canvas) => {
const { imageInformationUri } = new ManifestoCanvas(canvas);
const manifestoCanvas = new ManifestoCanvas(canvas);
const { imageInformationUri } = manifestoCanvas;
if (imageInformationUri) {
fetchInfoResponse(imageInformationUri);
}
manifestoCanvas.annotationListUris.forEach((uri) => {
fetchAnnotation(manifestoCanvas.canvas.id, uri);
});
});
}
// If the view changes, create a new instance
......@@ -129,6 +137,7 @@ export class WindowViewer extends Component {
WindowViewer.propTypes = {
infoResponses: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types
fetchAnnotation: PropTypes.func.isRequired,
fetchInfoResponse: PropTypes.func.isRequired,
manifest: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types
window: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types
......
......@@ -20,7 +20,10 @@ const mapStateToProps = state => (
* @memberof WindowViewer
* @private
*/
const mapDispatchToProps = { fetchInfoResponse: actions.fetchInfoResponse };
const mapDispatchToProps = {
fetchAnnotation: actions.fetchAnnotation,
fetchInfoResponse: actions.fetchInfoResponse,
};
const enhance = compose(
......
import flatten from 'lodash/flatten';
/**
* ManifestoCanvas - adds additional, testable logic around Manifesto's Canvas
* https://iiif-commons.github.io/manifesto/classes/_canvas_.manifesto.canvas.html
......@@ -22,6 +23,15 @@ export default class ManifestoCanvas {
return this.canvas.getWidth() / this.canvas.getHeight();
}
/** */
get annotationListUris() {
return flatten(
new Array(this.canvas.__jsonld.otherContent), // eslint-disable-line no-underscore-dangle
)
.filter(otherContent => otherContent && otherContent['@type'] === 'sc:AnnotationList')
.map(otherContent => otherContent['@id']);
}
/**
*/
get imageInformationUri() {
......
......@@ -4,6 +4,10 @@ const ActionTypes = {
REMOVE_COMPANION_WINDOW: 'REMOVE_COMPANION_WINDOW',
UPDATE_WINDOW: 'UPDATE_WINDOW',
REQUEST_ANNOTATION: 'REQUEST_ANNOTATION',
RECEIVE_ANNOTATION: 'RECEIVE_ANNOTATION',
RECEIVE_ANNOTATION_FAILURE: 'RECEIVE_ANNOTATION_FAILURE',
FOCUS_WINDOW: 'FOCUS_WINDOW',
SET_WORKSPACE_FULLSCREEN: 'SET_WORKSPACE_FULLSCREEN',
SET_WORKSPACE_VIEWPORT_POSITION: 'SET_WORKSPACE_VIEWPORT_POSITION',
......
import fetch from 'node-fetch';
import ActionTypes from './action-types';
/**
* requestAnnotation - action creator
*
* @param {String} canvasId
* @param {String} annotationId
* @memberof ActionCreators
*/
export function requestAnnotation(canvasId, annotationId) {
return {
type: ActionTypes.REQUEST_ANNOTATION,
canvasId,
annotationId,
};
}
/**
* receiveAnnotation - action creator
*
* @param {String} canvasId
* @param {String} annotationId
* @param {Object} annotationJson
* @memberof ActionCreators
*/
export function receiveAnnotation(canvasId, annotationId, annotationJson) {
return {
type: ActionTypes.RECEIVE_ANNOTATION,
canvasId,
annotationId,
annotationJson,
};
}
/**
* receiveAnnotationFailure - action creator
*
* @param {String} canvasId
* @param {String} annotationId
* @param {String} error
* @memberof ActionCreators
*/
export function receiveAnnotationFailure(canvasId, annotationId, error) {
return {
type: ActionTypes.RECEIVE_ANNOTATION_FAILURE,
canvasId,
annotationId,
error,
};
}
/**
* fetchAnnotation - action creator
*
* @param {String} annotationId
* @memberof ActionCreators
*/
export function fetchAnnotation(canvasId, annotationId) {
return ((dispatch) => {
dispatch(requestAnnotation(canvasId, annotationId));
return fetch(annotationId)
.then(response => response.json())
.then(json => dispatch(receiveAnnotation(canvasId, annotationId, json)))
.catch(error => dispatch(receiveAnnotationFailure(canvasId, annotationId, error)));
});
}
......@@ -9,3 +9,4 @@ export * from './manifest';
export * from './infoResponse';
export * from './canvas';
export * from './workspace';
export * from './annotation';
import ActionTypes from '../actions/action-types';
/**
* annotationReducer
*/
export const annotationsReducer = (state = {}, action) => {
switch (action.type) {
case ActionTypes.REQUEST_ANNOTATION:
return {
...state,
[action.canvasId]: {
[action.annotationId]: {
id: action.annotationId,
isFetching: true,
},
},
};
case ActionTypes.RECEIVE_ANNOTATION:
return {
...state,
[action.canvasId]: {
[action.annotationId]: {
id: action.annotationId,
json: action.annotationJson,
isFetching: false,
},
},
};
case ActionTypes.RECEIVE_ANNOTATION_FAILURE:
return {
...state,
[action.canvasId]: {
[action.annotationId]: {
id: action.annotationId,
error: action.error,
isFetching: false,
},
},
};
default: return state;
}
};
......@@ -5,3 +5,4 @@ export * from './manifests';
export * from './infoResponses';
export * from './config';
export * from './viewers';
export * from './annotations';
......@@ -7,6 +7,7 @@ import {
viewersReducer,
windowsReducer,
workspaceReducer,
annotationsReducer,
} from '.';
/**
......@@ -23,6 +24,7 @@ export default function createRootReducer(pluginReducers) {
infoResponses: infoResponsesReducer,
config: configReducer,
viewers: viewersReducer,
annotations: annotationsReducer,
...pluginReducers,
});
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment