-
Notifications
You must be signed in to change notification settings - Fork 405
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(sanity): respect Studio configuration when rendering "restore" document action #6637
Merged
juice49
merged 6 commits into
next
from
fix/sdx-541-respect-restore-action-configuration
May 23, 2024
Merged
fix(sanity): respect Studio configuration when rendering "restore" document action #6637
juice49
merged 6 commits into
next
from
fix/sdx-541-respect-restore-action-configuration
May 23, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Ignored Deployment
|
No changes to documentation |
Component Testing Report Updated May 23, 2024 1:28 PM (UTC)
|
cea76ea
to
071d9f6
Compare
3e3c5c6
to
a4119a6
Compare
19b3232
to
a0c5f79
Compare
44083f4
to
fe7213d
Compare
52e091f
to
89f71b2
Compare
rexxars
previously approved these changes
May 21, 2024
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.
Looks great. Kudos on thorough tests, much appreciated!
…tatusBarActions` menu
89f71b2
to
fb42772
Compare
bjoerge
approved these changes
May 23, 2024
This was referenced Jun 24, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
The Studio document actions configuration is not currently respected when rendering the "Restore" document action.
For example, given a document actions resolver that removes the "Restore" document action:
Studio will render it anyway:
With this change in place, the document actions resolver is respected, allowing developers to remove or replace the action:
Impact on public API
In order to replace the restore action, developers must set the
action
property to"restore"
on theirDocumentActionComponent
.import {RocketIcon} from '@sanity/icons' import {type DocumentActionComponent} from 'sanity' export const TestCustomRestoreAction: ( action: DocumentActionComponent, ) => DocumentActionComponent = (restoreAction) => { const action: DocumentActionComponent = (props) => ({ ...restoreAction(props), label: 'Custom restore', tone: 'positive', icon: RocketIcon, }) + action.action = 'restore' return action }
This is because the restore action is specially handled by Studio. It does not appear alongside the other document actions, but rather, appears only when a different revision of the document is being viewed. The
action
property allows Studio to identify the restore action.I think we should begin recommending setting the
action
property when developers replace any built-in document actions. Not only does this make things more consistent, it makes it easier for us to specially handled other document actions in the future.We may wish to consider introducing a new helper to simplify this (e.g.
defineDocumentAction
). In the future, it could do other helpful things beyond setting theaction
property, such as automatically calling the built-in action'sonHandle
function if the developer is extending a built-in action.What to review
Testing
Added E2E tests in
test/e2e/tests/document-actions/restore.spec.ts
.Notes for release
Fixes a bug preventing developers removing or customising the "restore" document action using the
document.actions
Studio configuration property.Studio will now respect changes you make to the "restore" document action, but please note that you must set the
action
property to"restore"
on yourDocumentActionComponent
. Theaction
property allows Studio to identify the restore action.Example
import {RocketIcon} from '@sanity/icons' import {type DocumentActionComponent} from 'sanity' export const TestCustomRestoreAction: ( action: DocumentActionComponent, ) => DocumentActionComponent = (restoreAction) => { const action: DocumentActionComponent = (props) => ({ ...restoreAction(props), label: 'Custom restore', tone: 'positive', icon: RocketIcon, }) + action.action = 'restore' return action }