-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Try creating nav menu on pattern insertion or when the block has unco…
…ntrolled inner blocks (#36024) * Add automatic wp_navigation creation Fix issues with multiple menu creation Lift limit on loading of menus Remove attempt to use template part area to generate a name Remove unused client id prop Try creating as auto-draft and publishing on save Only save when selecting menu Show a draft save button on the block toolbar Show loading state when navigation block first loads Remove flicker when selecting block with unsaved inner blocks Polish switch to controlled inner blocks Take drafts into account when naming menus Fix repeated line * Remove unused file * Remove unusued useState * Update animations
- Loading branch information
Showing
9 changed files
with
303 additions
and
70 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
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
57 changes: 57 additions & 0 deletions
57
packages/block-library/src/navigation/edit/navigation-menu-publish-button.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,57 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { ToolbarButton } from '@wordpress/components'; | ||
import { | ||
useEntityId, | ||
useEntityProp, | ||
store as coreStore, | ||
} from '@wordpress/core-data'; | ||
import { useDispatch } from '@wordpress/data'; | ||
import { useState } from '@wordpress/element'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import NavigationMenuNameModal from './navigation-menu-name-modal'; | ||
|
||
export default function NavigationMenuPublishButton() { | ||
const [ isNameModalVisible, setIsNameModalVisible ] = useState( false ); | ||
const id = useEntityId( 'postType', 'wp_navigation' ); | ||
const [ navigationMenuTitle ] = useEntityProp( | ||
'postType', | ||
'wp_navigation', | ||
'title' | ||
); | ||
const { editEntityRecord, saveEditedEntityRecord } = useDispatch( | ||
coreStore | ||
); | ||
|
||
return ( | ||
<> | ||
<ToolbarButton onClick={ () => setIsNameModalVisible( true ) }> | ||
{ __( 'Save as' ) } | ||
</ToolbarButton> | ||
{ isNameModalVisible && ( | ||
<NavigationMenuNameModal | ||
title={ __( 'Save your new navigation menu' ) } | ||
value={ navigationMenuTitle } | ||
onRequestClose={ () => setIsNameModalVisible( false ) } | ||
finishButtonText={ __( 'Save' ) } | ||
onFinish={ ( updatedTitle ) => { | ||
editEntityRecord( 'postType', 'wp_navigation', id, { | ||
title: updatedTitle, | ||
status: 'publish', | ||
} ); | ||
saveEditedEntityRecord( | ||
'postType', | ||
'wp_navigation', | ||
id | ||
); | ||
} } | ||
/> | ||
) } | ||
</> | ||
); | ||
} |
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
Oops, something went wrong.