From 5ae6f8b0358d3f13497b9d7e60baa42ac3bd33c5 Mon Sep 17 00:00:00 2001 From: Ash Date: Thu, 28 Nov 2024 16:05:48 +0000 Subject: [PATCH] feat(sanity): add "Compare versions" document action to releases plugin The action doesn't do anything yet. --- .../documentActions/CompareVersionsAction.tsx | 20 +++++++++++++++++++ .../releases/plugin/documentActions/index.ts | 11 ++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 packages/sanity/src/core/releases/plugin/documentActions/CompareVersionsAction.tsx diff --git a/packages/sanity/src/core/releases/plugin/documentActions/CompareVersionsAction.tsx b/packages/sanity/src/core/releases/plugin/documentActions/CompareVersionsAction.tsx new file mode 100644 index 00000000000..49116285013 --- /dev/null +++ b/packages/sanity/src/core/releases/plugin/documentActions/CompareVersionsAction.tsx @@ -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 = () => { + const {t} = useTranslation(releasesLocaleNamespace) + + return useMemo( + () => ({ + icon: TransferIcon, + label: t('action.compare-versions'), + title: t('actions.create.text'), + group: ['paneActions'], + }), + [t], + ) +} diff --git a/packages/sanity/src/core/releases/plugin/documentActions/index.ts b/packages/sanity/src/core/releases/plugin/documentActions/index.ts index 08e82b67fe1..0b189f432c2 100644 --- a/packages/sanity/src/core/releases/plugin/documentActions/index.ts +++ b/packages/sanity/src/core/releases/plugin/documentActions/index.ts @@ -1,5 +1,6 @@ import {type DocumentActionComponent, type DocumentActionsContext} from 'sanity' +import {CompareVersionsAction} from './CompareVersionsAction' import {DiscardVersionAction} from './DiscardVersionAction' import {UnpublishVersionAction} from './UnpublishVersionAction' @@ -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, + ] }