Skip to content

Commit

Permalink
[base] Maintain order of documents when collating drafts/published (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars authored Dec 17, 2019
1 parent 1aca70e commit b92b6ac
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/@sanity/base/src/util/draftUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,17 @@ export function createPublishedFrom(document) {
export function collate(documents) {
const byId = documents.reduce((res, doc) => {
const id = getPublishedId(doc._id)
const entry = res[id] || (res[id] = {id})
let entry = res.get(id)
if (!entry) {
entry = {id}
res.set(id, entry)
}

entry[id === doc._id ? 'published' : 'draft'] = doc
return res
}, Object.create(null))
return Object.values(byId)
}, new Map())

return Array.from(byId.values())
}

// Removes published documents that also has a draft
Expand Down

0 comments on commit b92b6ac

Please sign in to comment.