Skip to content

Commit

Permalink
feat(i18n): use i18n strings in delete document action
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoerge committed Sep 29, 2023
1 parent ff0d7c0 commit 8f1ea87
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
15 changes: 15 additions & 0 deletions dev/test-studio/plugins/locale-no-nb/bundles/desk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ const deskResources: Record<DeskLocaleResourceKeys, string> = {

/** Tooltip when publish button is waiting for validation and async tasks to complete.*/
'action.publish.waiting': 'Venter på at andre oppgaver skal fullføre',

/** --- DELETE ACTION --- **/
/**
* Tooltip when delete button is disabled because the document does not exist
*/
'action.delete.disabled.nothingToDelete':
'Dette dokumentet eksisterer ikke eller har allerede blitt slettet',
/**
* Tooltip when delete button is disabled because the document does not exist
*/
/** Label for the "Delete" document action */
'action.delete.label': 'Slett',

/** Label for the "Delete" document action while the document is being deleted */
'action.delete.running.label': 'Sletter…',
}

export default deskResources
16 changes: 11 additions & 5 deletions packages/sanity/src/desk/documentActions/DeleteAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
import {TrashIcon} from '@sanity/icons'
import React, {useCallback, useState} from 'react'
import {ConfirmDeleteDialog} from '../components'
import {useDocumentPane} from '../panes/document/useDocumentPane'
import {deskLocaleNamespace} from '../i18n'
import {
DocumentActionComponent,
InsufficientPermissionsMessage,
useCurrentUser,
useDocumentOperation,
useDocumentPairPermissions,
useTranslation,
} from 'sanity'
import {useDocumentPane} from '../panes/document/useDocumentPane'

const DISABLED_REASON_TITLE = {
NOTHING_TO_DELETE: 'This document doesn’t yet exist or is already deleted',
const DISABLED_REASON_TITLE_KEY = {
NOTHING_TO_DELETE: 'action.delete.disabled.nothingToDelete',
}

/** @internal */
Expand All @@ -23,6 +25,8 @@ export const DeleteAction: DocumentActionComponent = ({id, type, draft, onComple
const [isDeleting, setIsDeleting] = useState(false)
const [isConfirmDialogOpen, setConfirmDialogOpen] = useState(false)

const {t} = useTranslation(deskLocaleNamespace)

const handleCancel = useCallback(() => {
setConfirmDialogOpen(false)
onComplete()
Expand Down Expand Up @@ -69,9 +73,11 @@ export const DeleteAction: DocumentActionComponent = ({id, type, draft, onComple
disabled: isDeleting || Boolean(deleteOp.disabled) || isPermissionsLoading,
title:
(deleteOp.disabled &&
DISABLED_REASON_TITLE[deleteOp.disabled as keyof typeof DISABLED_REASON_TITLE]) ||
t(
DISABLED_REASON_TITLE_KEY[deleteOp.disabled as keyof typeof DISABLED_REASON_TITLE_KEY],
)) ||
'',
label: isDeleting ? 'Deleting…' : 'Delete',
label: isDeleting ? t('action.deleting.label') : t('action.delete.label'),
shortcut: 'Ctrl+Alt+D',
onHandle: handle,
dialog: isConfirmDialogOpen && {
Expand Down
14 changes: 14 additions & 0 deletions packages/sanity/src/desk/i18n/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ const deskLocaleStrings = {

/** Tooltip when publish button is waiting for validation and async tasks to complete.*/
'action.publish.waiting': 'Waiting for tasks to finish before publishing',

/** --- DELETE ACTION --- **/
/**
* Tooltip when delete button is disabled because the document does not exist
*/
'action.delete.disabled.nothingToDelete': 'This document doesn’t yet exist or is already deleted',
/**
* Tooltip when delete button is disabled because the document does not exist
*/
/** Label for the "Delete" document action */
'action.delete.label': 'Delete',

/** Label for the "Delete" document action while the document is being deleted */
'action.delete.running.label': 'Deleting…',
}

/**
Expand Down

0 comments on commit 8f1ea87

Please sign in to comment.