-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add delete nav menu button to nav block (#35981)
* Add a delete button to the navigation block inspector * Style delete button * Force delete menus
- Loading branch information
Showing
3 changed files
with
98 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
packages/block-library/src/navigation/edit/navigation-menu-delete-control.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Button, Flex, FlexItem, Modal } from '@wordpress/components'; | ||
import { | ||
store as coreStore, | ||
useEntityId, | ||
useEntityProp, | ||
} from '@wordpress/core-data'; | ||
import { useDispatch } from '@wordpress/data'; | ||
import { useState } from '@wordpress/element'; | ||
import { __, sprintf } from '@wordpress/i18n'; | ||
|
||
export default function NavigationMenuDeleteControl( { onDelete } ) { | ||
const [ isConfirmModalVisible, setIsConfirmModalVisible ] = useState( | ||
false | ||
); | ||
const id = useEntityId( 'postType', 'wp_navigation' ); | ||
const [ title ] = useEntityProp( 'postType', 'wp_navigation', 'title' ); | ||
const { deleteEntityRecord } = useDispatch( coreStore ); | ||
|
||
return ( | ||
<> | ||
<Button | ||
className="wp-block-navigation-delete-menu-button" | ||
variant="secondary" | ||
isDestructive | ||
onClick={ () => { | ||
setIsConfirmModalVisible( true ); | ||
} } | ||
> | ||
{ __( 'Delete menu' ) } | ||
</Button> | ||
{ isConfirmModalVisible && ( | ||
<Modal | ||
title={ sprintf( | ||
/* translators: %s: the name of a menu to delete */ | ||
__( 'Delete %s' ), | ||
title | ||
) } | ||
closeLabel={ __( 'Cancel' ) } | ||
onRequestClose={ () => setIsConfirmModalVisible( false ) } | ||
> | ||
<p> | ||
{ __( | ||
'Are you sure you want to delete this navigation menu?' | ||
) } | ||
</p> | ||
<Flex justify="flex-end"> | ||
<FlexItem> | ||
<Button | ||
variant="secondary" | ||
onClick={ () => { | ||
setIsConfirmModalVisible( false ); | ||
} } | ||
> | ||
{ __( 'Cancel' ) } | ||
</Button> | ||
</FlexItem> | ||
<FlexItem> | ||
<Button | ||
variant="primary" | ||
onClick={ () => { | ||
deleteEntityRecord( | ||
'postType', | ||
'wp_navigation', | ||
id, | ||
{ force: true } | ||
); | ||
onDelete(); | ||
} } | ||
> | ||
{ __( 'Confirm' ) } | ||
</Button> | ||
</FlexItem> | ||
</Flex> | ||
</Modal> | ||
) } | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters