Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the delete navigation menu confirm dialogs consistent #59825

Merged
merged 3 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions packages/block-library/src/navigation/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
Spinner,
Notice,
} from '@wordpress/components';
import { __, sprintf } from '@wordpress/i18n';
import { __ } from '@wordpress/i18n';
import { speak } from '@wordpress/a11y';
import { close, Icon } from '@wordpress/icons';
import { useInstanceId } from '@wordpress/compose';
Expand Down Expand Up @@ -841,15 +841,11 @@ function Navigation( {
{ hasResolvedCanUserDeleteNavigationMenu &&
canUserDeleteNavigationMenu && (
<NavigationMenuDeleteControl
onDelete={ ( deletedMenuTitle = '' ) => {
onDelete={ () => {
replaceInnerBlocks( clientId, [] );
showNavigationMenuStatusNotice(
sprintf(
// translators: %s: the name of a menu (e.g. Header navigation).
__(
'Navigation menu %s successfully deleted.'
),
deletedMenuTitle
__(
'Navigation menu successfully deleted.'
)
);
} }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,17 @@
*/
import {
Button,
Modal,
__experimentalHStack as HStack,
__experimentalConfirmDialog as ConfirmDialog,
} from '@wordpress/components';
import {
store as coreStore,
useEntityId,
useEntityProp,
} from '@wordpress/core-data';
import { store as coreStore, useEntityId } from '@wordpress/core-data';
import { useDispatch } from '@wordpress/data';
import { useState } from '@wordpress/element';
import { __, sprintf } from '@wordpress/i18n';
import { __ } from '@wordpress/i18n';

export default function NavigationMenuDeleteControl( { onDelete } ) {
const [ isConfirmModalVisible, setIsConfirmModalVisible ] =
const [ isConfirmDialogVisible, setIsConfirmDialogVisible ] =
useState( false );
const id = useEntityId( 'postType', 'wp_navigation' );
const [ title ] = useEntityProp( 'postType', 'wp_navigation', 'title' );
const { deleteEntityRecord } = useDispatch( coreStore );

return (
Expand All @@ -29,50 +23,29 @@ export default function NavigationMenuDeleteControl( { onDelete } ) {
variant="secondary"
isDestructive
onClick={ () => {
setIsConfirmModalVisible( true );
setIsConfirmDialogVisible( true );
} }
>
{ __( 'Delete menu' ) }
</Button>
{ isConfirmModalVisible && (
<Modal
title={ sprintf(
/* translators: %s: the name of a menu to delete */
__( 'Delete %s' ),
title
) }
onRequestClose={ () => setIsConfirmModalVisible( false ) }
{ isConfirmDialogVisible && (
<ConfirmDialog
isOpen
onConfirm={ () => {
deleteEntityRecord( 'postType', 'wp_navigation', id, {
force: true,
} );
onDelete();
} }
onCancel={ () => {
setIsConfirmDialogVisible( false );
} }
confirmButtonText={ __( 'Delete' ) }
>
<p>
{ __(
'Are you sure you want to delete this navigation menu?'
) }
</p>
<HStack justify="right">
<Button
variant="tertiary"
onClick={ () => {
setIsConfirmModalVisible( false );
} }
>
{ __( 'Cancel' ) }
</Button>
<Button
variant="primary"
onClick={ () => {
deleteEntityRecord(
'postType',
'wp_navigation',
id,
{ force: true }
);
onDelete( title );
} }
>
{ __( 'Confirm' ) }
</Button>
</HStack>
</Modal>
{ __(
'Are you sure you want to delete this Navigation menu?'
) }
</ConfirmDialog>
) }
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
import { __experimentalConfirmDialog as ConfirmDialog } from '@wordpress/components';
import { __ } from '@wordpress/i18n';

export default function RenameModal( { onClose, onConfirm } ) {
export default function DeleteConfirmDialog( { onClose, onConfirm } ) {
return (
<ConfirmDialog
isOpen
onConfirm={ ( e ) => {
e.preventDefault();
onConfirm={ () => {
onConfirm();

// Immediate close avoids ability to hit delete multiple times.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useState } from '@wordpress/element';
* Internal dependencies
*/
import RenameModal from './rename-modal';
import DeleteModal from './delete-modal';
import DeleteConfirmDialog from './delete-confirm-dialog';

const POPOVER_PROPS = {
position: 'bottom right',
Expand All @@ -20,14 +20,15 @@ export default function ScreenNavigationMoreMenu( props ) {
const { onDelete, onSave, onDuplicate, menuTitle } = props;

const [ renameModalOpen, setRenameModalOpen ] = useState( false );
const [ deleteModalOpen, setDeleteModalOpen ] = useState( false );
const [ deleteConfirmDialogOpen, setDeleteConfirmDialogOpen ] =
useState( false );

const closeModals = () => {
setRenameModalOpen( false );
setDeleteModalOpen( false );
setDeleteConfirmDialogOpen( false );
};
const openRenameModal = () => setRenameModalOpen( true );
const openDeleteModal = () => setDeleteModalOpen( true );
const openDeleteConfirmDialog = () => setDeleteConfirmDialogOpen( true );

return (
<>
Expand Down Expand Up @@ -60,7 +61,7 @@ export default function ScreenNavigationMoreMenu( props ) {
<MenuItem
isDestructive
onClick={ () => {
openDeleteModal();
openDeleteConfirmDialog();

// Close the dropdown after opening the modal.
onClose();
Expand All @@ -72,11 +73,12 @@ export default function ScreenNavigationMoreMenu( props ) {
</div>
) }
</DropdownMenu>

{ deleteModalOpen && (
<DeleteModal onClose={ closeModals } onConfirm={ onDelete } />
{ deleteConfirmDialogOpen && (
<DeleteConfirmDialog
onClose={ closeModals }
onConfirm={ onDelete }
/>
) }

{ renameModalOpen && (
<RenameModal
onClose={ closeModals }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ function useDeleteNavigationMenu() {
throwOnError: true,
}
);
createSuccessNotice( __( 'Deleted Navigation menu' ), {
type: 'snackbar',
} );
createSuccessNotice(
__( 'Navigation menu successfully deleted.' ),
{
type: 'snackbar',
}
);
goTo( '/navigation' );
} catch ( error ) {
createErrorNotice(
Expand Down
Loading