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 13, 2024
1 parent c43ccf4 commit cea76ea
Showing 1 changed file with 14 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,16 @@ 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], [])

const historyActions = useMemo(() => (actions ?? []).filter(isRestoreAction), [actions])

return (
<RenderActionCollectionState
Expand All @@ -136,3 +141,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 cea76ea

Please sign in to comment.