chore: Add comments
This commit is contained in:
committed by
Khaled Garbaya
parent
4344b6ff6b
commit
6867659853
@@ -16,16 +16,18 @@ module.exports = async function attachEntryState (entry) {
|
||||
if (!publishedEntry) {
|
||||
entry.draft = true
|
||||
}
|
||||
|
||||
// We group fields of type link (i.e. Only objects/array) from the same entry in preview and delivery
|
||||
const entriesToCompare = Object.keys(entry.fields).map((key) => {
|
||||
const field = entry.fields[key]
|
||||
if (isObject(field)) {
|
||||
return [entry.fields[key], publishedEntry.fields[key]]
|
||||
}
|
||||
}).filter(Boolean)
|
||||
|
||||
entriesToCompare.forEach((item) => {
|
||||
const originalItem = item[0]
|
||||
const publishedItem = item[1]
|
||||
// If the field is an array of reference we need to check its item if they have pending changes
|
||||
if (isArray(originalItem)) {
|
||||
originalItem.forEach((innerItem, index) => {
|
||||
if (!isArray(innerItem) && isObject(innerItem) && (!innerItem.fields || originalItem[index].sys.updatedAt !== publishedItem[index].sys.updatedAt)) {
|
||||
@@ -33,12 +35,13 @@ module.exports = async function attachEntryState (entry) {
|
||||
return
|
||||
}
|
||||
})
|
||||
// If the field is a single reference we just check if it has pending changes
|
||||
} else if (isObject(item[0]) && (!item[0].fields || item[0].sys.updatedAt !== item[1].sys.updatedAt)) {
|
||||
entry.pendingChanges = true
|
||||
return
|
||||
}
|
||||
})
|
||||
|
||||
// We check if the root element has pending changes
|
||||
if (entry && publishedEntry && (entry.sys.updatedAt !== publishedEntry.sys.updatedAt)) {
|
||||
entry.pendingChanges = true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user