Skip to content
Snippets Groups Projects
Commit f6a30f9e authored by Jack Reed's avatar Jack Reed Committed by Mathias Maaß
Browse files

Update annotations reducer to be able to merge state at the canvas level

Fixes #2941

This will support asynchronous annotations from multiple sources for a
canvas. Previously this worked as a last in only out.
parent cd7ca26b
Branches
Tags
No related merge requests found
...@@ -46,6 +46,78 @@ describe('annotation reducer', () => { ...@@ -46,6 +46,78 @@ describe('annotation reducer', () => {
}, },
}); });
}); });
it('should be able to RECEIVE_ANNOTATION from multiple sources and merge state', () => {
const firstReduction = annotationsReducer(
{
foo: {
abc123: {
id: 'abc123',
isFetching: true,
},
},
},
{
annotationId: 'efg456',
annotationJson: {
'@type': 'sc:AnnotationList',
content: 'anno stuff',
id: 'efg456',
},
targetId: 'foo',
type: ActionTypes.RECEIVE_ANNOTATION,
},
);
expect(firstReduction).toMatchObject({
foo: {
abc123: {
id: 'abc123',
isFetching: true,
},
efg456: {
isFetching: false,
json: {
'@type': 'sc:AnnotationList',
content: 'anno stuff',
id: 'efg456',
},
},
},
});
const secondReduction = annotationsReducer(
firstReduction,
{
annotationId: 'abc123',
annotationJson: {
'@type': 'sc:AnnotationList',
content: 'anno stuff',
id: 'abc123',
},
targetId: 'foo',
type: ActionTypes.RECEIVE_ANNOTATION,
},
);
expect(secondReduction).toMatchObject({
foo: {
abc123: {
id: 'abc123',
isFetching: false,
json: {
'@type': 'sc:AnnotationList',
content: 'anno stuff',
id: 'abc123',
},
},
efg456: {
isFetching: false,
json: {
'@type': 'sc:AnnotationList',
content: 'anno stuff',
id: 'efg456',
},
},
},
});
});
it('should handle RECEIVE_ANNOTATION_FAILURE', () => { it('should handle RECEIVE_ANNOTATION_FAILURE', () => {
expect(annotationsReducer( expect(annotationsReducer(
{ {
......
...@@ -9,6 +9,7 @@ export const annotationsReducer = (state = {}, action) => { ...@@ -9,6 +9,7 @@ export const annotationsReducer = (state = {}, action) => {
return { return {
...state, ...state,
[action.targetId]: { [action.targetId]: {
...state[action.targetId],
[action.annotationId]: { [action.annotationId]: {
id: action.annotationId, id: action.annotationId,
isFetching: true, isFetching: true,
...@@ -19,6 +20,7 @@ export const annotationsReducer = (state = {}, action) => { ...@@ -19,6 +20,7 @@ export const annotationsReducer = (state = {}, action) => {
return { return {
...state, ...state,
[action.targetId]: { [action.targetId]: {
...state[action.targetId],
[action.annotationId]: { [action.annotationId]: {
id: action.annotationId, id: action.annotationId,
isFetching: false, isFetching: false,
...@@ -30,6 +32,7 @@ export const annotationsReducer = (state = {}, action) => { ...@@ -30,6 +32,7 @@ export const annotationsReducer = (state = {}, action) => {
return { return {
...state, ...state,
[action.targetId]: { [action.targetId]: {
...state[action.targetId],
[action.annotationId]: { [action.annotationId]: {
error: action.error, error: action.error,
id: action.annotationId, id: action.annotationId,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment