diff --git a/lib/entry-state.js b/lib/entry-state.js index b825988..945c6c9 100644 --- a/lib/entry-state.js +++ b/lib/entry-state.js @@ -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 }