This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(annotation): Merge pull request #415 from hopetambala/master
#162 Data Annotation
- Loading branch information
Showing
16 changed files
with
539 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { createAction, handleActions } from "redux-actions"; | ||
|
||
const defaultState = { | ||
byId:[], | ||
byHash: { | ||
} | ||
}; | ||
|
||
// ACTIONS | ||
const addNote = createAction("ADD_NOTE"); | ||
const setNotes = createAction("SET_NOTE"); | ||
const removeNote = createAction("REMOVE_NOTE"); | ||
|
||
// REDUCERS | ||
const reducer = handleActions( | ||
{ | ||
[addNote]: (state, { payload }) => { | ||
return { | ||
byId: [ ...state.byId, payload.id], | ||
byHash: { | ||
...state.byHash, | ||
[payload.id]: payload | ||
} | ||
} | ||
}, | ||
[removeNote]: (state, { payload }) => { | ||
const prunedIds = state.byId.filter(item => { | ||
return item !== payload.id | ||
}) | ||
delete state.byHash[payload.id] | ||
|
||
return { | ||
byId: prunedIds, | ||
byHash: state.byHash | ||
} | ||
}, | ||
|
||
[setNotes]: (state, { payload }) => { | ||
const byid = payload.byId || state.byId; | ||
const byhash = payload.byHash || state.byHash; | ||
return { | ||
...state, | ||
byId: byid, | ||
byHash: byhash, | ||
} | ||
}, | ||
}, | ||
defaultState | ||
); | ||
|
||
// SELECTORS | ||
const getNotesIndexedByHash = (state) => state.notes.byHash; | ||
const getAllNotes = (state) => state.notes; | ||
|
||
|
||
export default reducer; | ||
|
||
export { addNote,setNotes,removeNote, getNotesIndexedByHash, getAllNotes}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { | ||
default as notes, | ||
addNote, | ||
setNotes, | ||
removeNote, | ||
getAllNotes, | ||
} from "./notes"; | ||
import { combineReducers } from "redux"; | ||
import { expect } from "chai" | ||
|
||
const reducer = combineReducers({ notes }); | ||
|
||
describe("Notes reducer", () => { | ||
|
||
describe("add and remove notes", () => { | ||
it("add a note", (done) => { | ||
const note = { | ||
id :'TestId', | ||
note:{ | ||
title: "I'm the Title of a Notes", | ||
labels: ['label a', 'label b', 'label c'], | ||
content:" I'm the Content of a note" | ||
} | ||
}; | ||
|
||
const action = addNote(note); | ||
const result = reducer({}, action); | ||
|
||
const defaultState = { | ||
byId:[`TestId`], | ||
byHash: { | ||
'TestId': { | ||
id: "TestId", | ||
note:{ | ||
title: "I'm the Title of a Notes", | ||
labels: ['label a', 'label b', 'label c'], | ||
content:" I'm the Content of a note" | ||
} | ||
} | ||
} | ||
}; | ||
|
||
expect(getAllNotes(result)).to.deep.equal(defaultState); | ||
|
||
done(); | ||
}); | ||
|
||
it("remove a note", (done) => { | ||
const note = { | ||
id :'TestId', | ||
note:{ | ||
title: "I'm the Title of a Notes", | ||
labels: ['label a', 'label b', 'label c'], | ||
content:" I'm the Content of a note" | ||
} | ||
}; | ||
|
||
const emptyState = { | ||
byId:[], | ||
byHash: { | ||
} | ||
}; | ||
|
||
const add_action = addNote(note); | ||
|
||
const remove_action = removeNote(note.id); | ||
|
||
reducer({}, add_action); | ||
var result = reducer({}, remove_action); | ||
|
||
expect(getAllNotes(result)).to.deep.equal(emptyState); | ||
|
||
done(); | ||
}); | ||
}); | ||
|
||
describe("setNotes", () => { | ||
it("sets the Control tree", (done) => { | ||
const notes = { | ||
'byId':[], | ||
'byHash': { | ||
} | ||
} | ||
|
||
const action = setNotes(notes); | ||
const result = reducer({}, action); | ||
|
||
expect(getAllNotes(result)).to.deep.equal(notes); | ||
|
||
done(); | ||
}); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.