Skip to content
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
merged 6 commits into from
May 23, 2024

Conversation

juice49
Copy link
Contributor

@juice49 juice49 commented May 13, 2024

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:

actions.filter((action) => action.action !== 'restore')

Studio will render it anyway:

Screenshot 2024-05-13 at 16 33 42

With this change in place, the document actions resolver is respected, allowing developers to remove or replace the action:

Screenshot 2024-05-13 at 16 35 43

Impact on public API

In order to replace the restore action, developers must set the action property to "restore" on their DocumentActionComponent.

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 the action property, such as automatically calling the built-in action's onHandle function if the developer is extending a built-in action.

What to review

  • That we should allow developers to customise the "restore" action.
  • That the approach taken seems reasonable.
  • That the proposed change to the public API seems reasonable.

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 your DocumentActionComponent. The action 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
}

Copy link

vercel bot commented May 13, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
page-building-studio ❌ Failed (Inspect) May 23, 2024 1:28pm
performance-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 23, 2024 1:28pm
test-next-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 23, 2024 1:28pm
test-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 23, 2024 1:28pm
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
studio-workshop ⬜️ Ignored (Inspect) Visit Preview May 23, 2024 1:28pm

Copy link
Contributor

No changes to documentation

Copy link
Contributor

github-actions bot commented May 13, 2024

Component Testing Report Updated May 23, 2024 1:28 PM (UTC)

File Status Duration Passed Skipped Failed
comments/CommentInput.spec.tsx ✅ Passed (Inspect) 35s 15 0 0
formBuilder/ArrayInput.spec.tsx ✅ Passed (Inspect) 6s 3 0 0
formBuilder/inputs/PortableText/Annotations.spec.tsx ✅ Passed (Inspect) 26s 6 0 0
formBuilder/inputs/PortableText/copyPaste/CopyPaste.spec.tsx ✅ Passed (Inspect) 31s 11 7 0
formBuilder/inputs/PortableText/Decorators.spec.tsx ✅ Passed (Inspect) 14s 6 0 0
formBuilder/inputs/PortableText/DisableFocusAndUnset.spec.tsx ✅ Passed (Inspect) 8s 3 0 0
formBuilder/inputs/PortableText/FocusTracking.spec.tsx ✅ Passed (Inspect) 35s 15 0 0
formBuilder/inputs/PortableText/Input.spec.tsx ✅ Passed (Inspect) 1m 17s 21 0 0
formBuilder/inputs/PortableText/ObjectBlock.spec.tsx ✅ Passed (Inspect) 1m 1s 18 0 0
formBuilder/inputs/PortableText/PresenceCursors.spec.tsx ✅ Passed (Inspect) 7s 3 9 0
formBuilder/inputs/PortableText/RangeDecoration.spec.tsx ✅ Passed (Inspect) 21s 9 0 0
formBuilder/inputs/PortableText/Styles.spec.tsx ✅ Passed (Inspect) 14s 6 0 0
formBuilder/inputs/PortableText/Toolbar.spec.tsx ✅ Passed (Inspect) 30s 12 0 0

@juice49 juice49 changed the title fix(sanity): respect Studio configuration when rendering "restore" do… fix(sanity): respect Studio configuration when rendering "restore" document action May 13, 2024
@juice49 juice49 force-pushed the fix/sdx-541-respect-restore-action-configuration branch from cea76ea to 071d9f6 Compare May 14, 2024 08:49
@juice49 juice49 force-pushed the fix/sdx-541-respect-restore-action-configuration branch from 3e3c5c6 to a4119a6 Compare May 14, 2024 10:58
@juice49 juice49 force-pushed the fix/sdx-541-respect-restore-action-configuration branch from 19b3232 to a0c5f79 Compare May 17, 2024 13:52
@juice49 juice49 force-pushed the fix/sdx-541-respect-restore-action-configuration branch from 44083f4 to fe7213d Compare May 17, 2024 16:16
rexxars
rexxars previously approved these changes May 21, 2024
Copy link
Member

@rexxars rexxars left a 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!

@juice49 juice49 added this pull request to the merge queue May 23, 2024
Merged via the queue into next with commit 6ba71f2 May 23, 2024
41 of 42 checks passed
@juice49 juice49 deleted the fix/sdx-541-respect-restore-action-configuration branch May 23, 2024 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants