Skip to content

Commit

Permalink
feat(sanity): add "Compare versions" document action to releases plugin
Browse files Browse the repository at this point in the history
The action doesn't do anything yet.
  • Loading branch information
juice49 committed Dec 9, 2024
1 parent 4f2194b commit 5ae6f8b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {TransferIcon} from '@sanity/icons'
import {useMemo} from 'react'

import {type ActionComponent, type DocumentActionProps} from '../../../config'
import {useTranslation} from '../../../i18n'
import {releasesLocaleNamespace} from '../../i18n'

export const CompareVersionsAction: ActionComponent<DocumentActionProps> = () => {
const {t} = useTranslation(releasesLocaleNamespace)

return useMemo(
() => ({
icon: TransferIcon,
label: t('action.compare-versions'),
title: t('actions.create.text'),
group: ['paneActions'],
}),
[t],
)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {type DocumentActionComponent, type DocumentActionsContext} from 'sanity'

import {CompareVersionsAction} from './CompareVersionsAction'
import {DiscardVersionAction} from './DiscardVersionAction'
import {UnpublishVersionAction} from './UnpublishVersionAction'

Expand All @@ -10,8 +11,10 @@ export default function resolveDocumentActions(
context: DocumentActionsContext,
): Action[] {
const duplicateAction = existingActions.filter(({name}) => name === 'DuplicateAction')

return context.versionType === 'version'
? duplicateAction.concat(DiscardVersionAction).concat(UnpublishVersionAction)
: existingActions
return [
...(context.perspective === 'version'
? duplicateAction.concat(DiscardVersionAction).concat(UnpublishVersionAction)
: existingActions),
CompareVersionsAction,
]
}

0 comments on commit 5ae6f8b

Please sign in to comment.