Introduce addAnnotation action and reducer

pull/10616/head
Andrew Watkins 2018-01-19 14:18:57 -08:00
parent a3dc0789fd
commit b36ab14b24
4 changed files with 27 additions and 0 deletions

View File

@ -1,11 +1,14 @@
import reducer from 'shared/reducers/annotations'
import {
addAnnotation,
deleteAnnotation,
loadAnnotations,
updateAnnotation,
} from 'shared/actions/annotations'
import {DEFAULT_ANNOTATION_ID} from 'src/shared/constants/annotations'
const a1 = {
id: '1',
group: '',
@ -48,4 +51,12 @@ describe.only('Shared.Reducers.annotations', () => {
expect(actual).to.deep.equal(expected)
})
it('can add an annotation', () => {
const state = []
const expected = [{...a1, id: DEFAULT_ANNOTATION_ID}]
const actual = reducer(state, addAnnotation(a1))
expect(actual).to.deep.equal(expected)
})
})

View File

@ -18,3 +18,10 @@ export const deleteAnnotation = annotation => ({
annotation,
},
})
export const addAnnotation = annotation => ({
type: 'ADD_ANNOTATION',
payload: {
annotation,
},
})

View File

@ -0,0 +1 @@
export const DEFAULT_ANNOTATION_ID = 'DEFAULT_ANNOTATION_ID'

View File

@ -1,3 +1,5 @@
import {DEFAULT_ANNOTATION_ID} from 'src/shared/constants/annotations'
const initialState = [
{
id: '0',
@ -36,6 +38,12 @@ const annotationsReducer = (state = initialState, action) => {
return newState
}
case 'ADD_ANNOTATION': {
const {annotation} = action.payload
return [...state, {...annotation, id: DEFAULT_ANNOTATION_ID}]
}
}
return state