Introduce addAnnotation action and reducer
parent
a3dc0789fd
commit
b36ab14b24
|
@ -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)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -18,3 +18,10 @@ export const deleteAnnotation = annotation => ({
|
|||
annotation,
|
||||
},
|
||||
})
|
||||
|
||||
export const addAnnotation = annotation => ({
|
||||
type: 'ADD_ANNOTATION',
|
||||
payload: {
|
||||
annotation,
|
||||
},
|
||||
})
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
export const DEFAULT_ANNOTATION_ID = 'DEFAULT_ANNOTATION_ID'
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue