Skip to content

Commit

Permalink
[desk-tool] Omit _createdAt, _updatedAt when creating duplicate docum…
Browse files Browse the repository at this point in the history
…ent (#1379)
  • Loading branch information
rexxars committed Jun 20, 2019
1 parent 1570999 commit a9372e3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions packages/@sanity/desk-tool/src/pane/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,11 @@ export default withRouterHOC(
handleCreateCopy = () => {
const {router, draft, published, paneIndex} = this.props
const prevId = getPublishedId((draft || published)._id)
const omit = ['_createdAt', '_updatedAt']

const duplicatedDocument = this.isLiveEditEnabled()
? copyDocument(published)
: newDraftFrom(copyDocument(draft || published))
? copyDocument(published, {omit})
: newDraftFrom(copyDocument(draft || published, {omit}))

this.duplicate$ = documentStore.create(duplicatedDocument).subscribe(copied => {
const copyDocId = getPublishedId(copied._id)
Expand Down
3 changes: 2 additions & 1 deletion packages/@sanity/desk-tool/src/utils/copyDocument.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@ function copyAny(value, options) {
}

export default function copyDocument(doc, options = {}) {
return copyAny(omit(doc, '_id'), options)
const omitProps = ['_id'].concat(options.omit)
return copyAny(omit(doc, omitProps), options)
}

0 comments on commit a9372e3

Please sign in to comment.