Skip to content
Snippets Groups Projects
Commit f1c8267c authored by Jure's avatar Jure
Browse files

Merge branch 'fragment-actions' into 'master'

Fix top level fragment actions

See merge request pubsweet/pubsweet!31
parents ce2acbce 128df4f4
No related branches found
No related tags found
No related merge requests found
...@@ -69,26 +69,30 @@ export default function(state = [], action) { ...@@ -69,26 +69,30 @@ export default function(state = [], action) {
} }
function addFragments() { function addFragments() {
const collection = getCollection() if (action.collection) {
const collection = getCollection()
if (collection) {
collection.fragments = union( if (collection) {
collection.fragments, collection.fragments = union(
(action.fragments || [action.fragment]).map(fragment => fragment.id), collection.fragments,
) (action.fragments || [action.fragment]).map(fragment => fragment.id),
)
}
} }
return collections return collections
} }
function removeFragments() { function removeFragments() {
const collection = getCollection() if (action.collection) {
const collection = getCollection()
if (collection) {
collection.fragments = difference( if (collection) {
collection.fragments, collection.fragments = difference(
(action.fragments || [action.fragment]).map(fragment => fragment.id), collection.fragments,
) (action.fragments || [action.fragment]).map(fragment => fragment.id),
)
}
} }
return collections return collections
......
...@@ -21,7 +21,9 @@ export default function(state = {}, action) { ...@@ -21,7 +21,9 @@ export default function(state = {}, action) {
const fragments = clone(state) const fragments = clone(state)
function replaceAll() { function replaceAll() {
unset(fragments, action.collection.fragments) if (action.collection) {
unset(fragments, action.collection.fragments)
}
action.fragments.forEach(fragment => { action.fragments.forEach(fragment => {
fragments[fragment.id] = fragment fragments[fragment.id] = fragment
}) })
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment