Skip to content

Commit

Permalink
fix(sanity): respect Studio configuration when rendering "restore" do…
Browse files Browse the repository at this point in the history
…cument action
  • Loading branch information
juice49 committed May 14, 2024
1 parent c43ccf4 commit a4119a6
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
/* eslint-disable camelcase */
import {Flex, Hotkeys, LayerProvider, Stack, Text} from '@sanity/ui'
import {memo, useMemo, useState} from 'react'
import {type DocumentActionDescription, useTimelineSelector} from 'sanity'
import {
type DocumentActionComponent,
type DocumentActionDescription,
useTimelineSelector,
} from 'sanity'

import {Button, Tooltip} from '../../../../ui-components'
import {RenderActionCollectionState} from '../../../components'
Expand Down Expand Up @@ -110,15 +114,17 @@ export const DocumentStatusBarActions = memo(function DocumentStatusBarActions()
})

export const HistoryStatusBarActions = memo(function HistoryStatusBarActions() {
const {connectionState, editState, timelineStore} = useDocumentPane()
const {actions, connectionState, editState, timelineStore} = useDocumentPane()

// Subscribe to external timeline state changes
const revTime = useTimelineSelector(timelineStore, (state) => state.revTime)

const revision = revTime?.id || ''
const disabled = (editState?.draft || editState?.published || {})._rev === revision
const actionProps = useMemo(() => ({...(editState || {}), revision}), [editState, revision])
const historyActions = useMemo(() => [HistoryRestoreAction], [])

// If multiple `restore` actions are defined, ensure only the final one is used.
const historyActions = useMemo(() => (actions ?? []).filter(isRestoreAction).slice(-1), [actions])

return (
<RenderActionCollectionState
Expand All @@ -136,3 +142,9 @@ export const HistoryStatusBarActions = memo(function HistoryStatusBarActions() {
</RenderActionCollectionState>
)
})

function isRestoreAction(
action: DocumentActionComponent,
): action is DocumentActionComponent & {action: 'restore'} {
return action.action === HistoryRestoreAction.action
}

0 comments on commit a4119a6

Please sign in to comment.