fix: delete document actions labels (#21182)

* fix: delete document actions labels

* chore: remove log

* fix: e2e tests
This commit is contained in:
Rémi de Juvigny 2024-09-09 06:08:59 -04:00 committed by GitHub
parent 953f201d8f
commit 29afb2b983
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 29 additions and 14 deletions

View File

@ -491,13 +491,17 @@ const DeleteAction: DocumentActionComponent = ({ documentId, model, collectionTy
const { delete: deleteAction } = useDocumentActions(); const { delete: deleteAction } = useDocumentActions();
const { toggleNotification } = useNotification(); const { toggleNotification } = useNotification();
const setSubmitting = useForm('DeleteAction', (state) => state.setSubmitting); const setSubmitting = useForm('DeleteAction', (state) => state.setSubmitting);
const isLocalized = document?.locale != null;
return { return {
disabled: !canDelete || !document, disabled: !canDelete || !document,
label: formatMessage({ label: formatMessage(
{
id: 'content-manager.actions.delete.label', id: 'content-manager.actions.delete.label',
defaultMessage: 'Delete document', defaultMessage: 'Delete entry{isLocalized, select, true { (all locales)} other {}}',
}), },
{ isLocalized }
),
icon: <Trash />, icon: <Trash />,
dialog: { dialog: {
type: 'dialog', type: 'dialog',

View File

@ -4,7 +4,7 @@
"actions.clone.label": "Duplicate", "actions.clone.label": "Duplicate",
"actions.delete.dialog.body": "Are you sure you want to delete this document? This action is irreversible.", "actions.delete.dialog.body": "Are you sure you want to delete this document? This action is irreversible.",
"actions.delete.error": "An error occurred while trying to delete the document.", "actions.delete.error": "An error occurred while trying to delete the document.",
"actions.delete.label": "Delete document", "actions.delete.label": "Delete entry{isLocalized, select, true { (all locales)} other {}}",
"actions.discard.label": "Discard changes", "actions.discard.label": "Discard changes",
"actions.discard.dialog.body": "Are you sure you want to discard the changes? This action is irreversible.", "actions.discard.dialog.body": "Are you sure you want to discard the changes? This action is irreversible.",
"actions.edit.error": "An error occurred while trying to edit the document.", "actions.edit.error": "An error occurred while trying to edit the document.",

View File

@ -318,6 +318,12 @@ const DeleteLocaleAction: DocumentActionComponent = ({
const { delete: deleteAction } = useDocumentActions(); const { delete: deleteAction } = useDocumentActions();
const { hasI18n, canDelete } = useI18n(); const { hasI18n, canDelete } = useI18n();
// Get the current locale object, using the URL instead of document so it works while creating
const [{ query }] = useQueryParams<I18nBaseQuery>();
const { data: locales = [] } = useGetLocalesQuery();
const currentDesiredLocale = query.plugins?.i18n?.locale;
const locale = !('error' in locales) && locales.find((loc) => loc.code === currentDesiredLocale);
if (!hasI18n) { if (!hasI18n) {
return null; return null;
} }
@ -326,10 +332,13 @@ const DeleteLocaleAction: DocumentActionComponent = ({
disabled: disabled:
(document?.locale && !canDelete.includes(document.locale)) || !document || !document.id, (document?.locale && !canDelete.includes(document.locale)) || !document || !document.id,
position: ['header', 'table-row'], position: ['header', 'table-row'],
label: formatMessage({ label: formatMessage(
{
id: getTranslation('actions.delete.label'), id: getTranslation('actions.delete.label'),
defaultMessage: 'Delete locale', defaultMessage: 'Delete entry ({locale})',
}), },
{ locale: locale && locale.name }
),
icon: <StyledTrash />, icon: <StyledTrash />,
variant: 'danger', variant: 'danger',
dialog: { dialog: {

View File

@ -1,5 +1,5 @@
{ {
"actions.delete.label": "Delete locale", "actions.delete.label": "Delete entry ({locale})",
"actions.delete.dialog.title": "Confirmation", "actions.delete.dialog.title": "Confirmation",
"actions.delete.dialog.body": "Are you sure you want to delete this locale?", "actions.delete.dialog.body": "Are you sure you want to delete this locale?",
"actions.delete.error": "An error occurred while trying to delete the document locale.", "actions.delete.error": "An error occurred while trying to delete the document locale.",

View File

@ -358,7 +358,7 @@ test.describe('Edit View', () => {
await page.getByRole('gridcell', { name: 'West Ham post match analysis' }).click(); await page.getByRole('gridcell', { name: 'West Ham post match analysis' }).click();
await page.getByRole('button', { name: 'More actions' }).click(); await page.getByRole('button', { name: 'More actions' }).click();
await page.getByRole('menuitem', { name: 'Delete document' }).click(); await page.getByRole('menuitem', { name: 'Delete entry (all locales)' }).click();
await page.getByRole('button', { name: 'Confirm' }).click(); await page.getByRole('button', { name: 'Confirm' }).click();
await findAndClose(page, 'Deleted Document'); await findAndClose(page, 'Deleted Document');

View File

@ -227,7 +227,7 @@ describeOnCondition(edition === 'EE')('History', () => {
await page.getByRole('link', { name: 'Will Kitman' }).click(); await page.getByRole('link', { name: 'Will Kitman' }).click();
await page.waitForURL(AUTHOR_EDIT_URL); await page.waitForURL(AUTHOR_EDIT_URL);
await page.getByRole('button', { name: /more actions/i }).click(); await page.getByRole('button', { name: /more actions/i }).click();
await page.getByRole('menuitem', { name: /delete document/i }).click(); await page.getByRole('menuitem', { name: /delete entry/i }).click();
await page.getByRole('button', { name: /confirm/i }).click(); await page.getByRole('button', { name: /confirm/i }).click();
// Go to the the article's history page // Go to the the article's history page
@ -461,7 +461,7 @@ describeOnCondition(edition === 'EE')('History', () => {
await page.getByRole('link', { name: 'Will Kitman' }).click(); await page.getByRole('link', { name: 'Will Kitman' }).click();
await page.waitForURL(AUTHOR_EDIT_URL); await page.waitForURL(AUTHOR_EDIT_URL);
await page.getByRole('button', { name: /more actions/i }).click(); await page.getByRole('button', { name: /more actions/i }).click();
await page.getByRole('menuitem', { name: /delete document/i }).click(); await page.getByRole('menuitem', { name: /delete entry/i }).click();
await page.getByRole('button', { name: /confirm/i }).click(); await page.getByRole('button', { name: /confirm/i }).click();
// Go to the the article's history page // Go to the the article's history page

View File

@ -71,7 +71,9 @@ test.describe('Settings', () => {
await expect(page.getByRole('menuitem', { name: 'Edit the model' })).toBeEnabled(); await expect(page.getByRole('menuitem', { name: 'Edit the model' })).toBeEnabled();
await expect(page.getByRole('menuitem', { name: 'Configure the view' })).toBeEnabled(); await expect(page.getByRole('menuitem', { name: 'Configure the view' })).toBeEnabled();
await expect(page.getByRole('menuitem', { name: 'Delete locale' })).toBeDisabled(); await expect(page.getByRole('menuitem', { name: 'Delete locale' })).toBeDisabled();
await expect(page.getByRole('menuitem', { name: 'Delete document' })).toBeEnabled(); await expect(
page.getByRole('menuitem', { name: 'Delete entry (all locales)' })
).toBeEnabled();
await page.keyboard.press('Escape'); await page.keyboard.press('Escape');
/** /**