-
Notifications
You must be signed in to change notification settings - Fork 445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(core): duplicate should work with version documents #8323
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
2 Skipped Deployments
|
No changes to documentation |
Component Testing Report Updated Jan 20, 2025 10:47 AM (UTC) ❌ Failed Tests (3) -- expand for details
|
⚡️ Editor Performance ReportUpdated Mon, 20 Jan 2025 10:46:11 GMT
Detailed information🏠 Reference resultThe performance result of
🧪 Experiment resultThe performance result of this branch
📚 Glossary
|
packages/sanity/src/core/store/_legacy/document/document-pair/operations/duplicate.ts
Outdated
Show resolved
Hide resolved
@@ -17,10 +20,19 @@ export const duplicate: OperationImpl<[baseDocumentId: string], 'NOTHING_TO_DUPL | |||
throw new Error('cannot execute on empty document') | |||
} | |||
|
|||
// When duplicating a version document we need to create it with a version id | |||
const versionId = snapshots.version?._id ? getVersionFromId(snapshots.version._id) : null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This process looks good, but it could be nice to get rid of that nested ternary 😅.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed, I think we will need to update the function getVersionFromId
name to something like getReleaseIdFromDocumentId
it can be confusing with the getVersionId
function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. That's a good point. I was also thinking that if getVersionFromId
and isVersionId
could accept undefined
as a parameter, this automatically becomes simpler:
- const versionId = snapshots.version?._id ? getVersionFromId(snapshots.version._id) : null
+ const versionId = getVersionFromId(snapshots.version?._id) ?? null
- release: idPair.versionId ? getVersionFromId(idPair.versionId) : undefined,
+ release: getVersionFromId(idPair.versionId),
(Not a recommended change for this PR, just a thought).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be, I like this simplicity but I also think there is something nice about making the check explicit in the consumers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Looks good to me!
Description
Duplicate action should work with versions.
This PR updates how the id is created for the new document created by the duplicate action, if it's a version id it will preserve the version and it won't create a draft document.
What to review
Is this correct?
Testing
Open a version document.
Click on duplicate, it should create a new document in the same release.
Non version documents should continue being created as draft or live documents.
Notes for release