Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
items.forEach((item, index) => {
// Get the item from the list and sets the document attibute and changes the document Status to LOADED
var initialItem = newState.source[index + rowStart]
initialItem.document = item.document
initialItem.status = STATUS.LOADED
})
const { errors, notSavedIds } = action
const newState = Object.assign({}, state, {
isFetching: false,
errors: errors,
})
console.log(newState.staging)
const stagingIds = Object.keys(newState.staging)
console.log('stagingIds:', stagingIds)
for (const documentId of stagingIds) {
console.log('documentId', documentId)
if (notSavedIds && notSavedIds.includes(documentId)) {
continue
}
const stagingItem = newState.staging[documentId]
console.log('stagingItem', documentId)
if (stagingItem.status === STATUS.LOADED) {
const loadedItem = newState.source.find(
item => item.document && item.document.id === documentId
)
loadedItem.document = Object.assign(
{},
loadedItem.document,
stagingItem.document
)
delete newState.staging[documentId]
newState.stagingItems = newState.stagingItems.filter(
stagingId => stagingId !== documentId
)
continue
}
if (stagingItem.status === STATUS.NEW) {
loadedItem.document,
stagingItem.document
)
delete newState.staging[documentId]
newState.stagingItems = newState.stagingItems.filter(
stagingId => stagingId !== documentId
)
continue
}
if (stagingItem.status === STATUS.NEW) {
const newItem = Object.assign(
{},
{ document: newState.staging[documentId].document },
{
status: STATUS.LOADED,
}
)
newState.source.push(newItem)
delete newState.staging[documentId]
newState.stagingItems = newState.stagingItems.filter(
stagingId => stagingId !== documentId
)
continue
}
if (stagingItem.status === STATUS.DELETED) {
newState.source = newState.source.filter(
item => item.document.id !== documentId
)
delete newState.staging[documentId]
newState.stagingItems = newState.stagingItems.filter(