-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Navigation: Implement redesign of Navigation Editor #25178
Merged
+882
−1,114
Merged
Changes from 33 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
53f11de
Navigation: Implement redesign of Navigation Editor
noisysocks 7ba8452
Navigation: Typo: @wordpress/i18n -> @wordpress/element
noisysocks 7efa781
Navigation: Inline call to setSelectedBlockId
noisysocks 7f59c24
Navigation: Add selectBlock as a useEffect dependency
noisysocks 96db71a
Navigation: Don't call setMenuLocationsByName when component is not m…
noisysocks 3f1eaf6
Navigation: Remove unnecessary useCallback()
noisysocks 22750a8
Navigation: Show Toolbar when there are no menus
noisysocks 18341e8
Return stable references from useMenuLocations()
noisysocks 5888c7a
Navigation: Fix createStubPost() setting blocks = [ undefined ]
noisysocks 79026cf
Navigation: Use NavigableToolbar
noisysocks 86440fa
Navigation: Split toolbar into two lines on mobile
noisysocks cd405b7
Changing the order of the list view and visual view so the list view …
shaunandrews a758ad2
Adding a title to the top of the List View.
shaunandrews 90c2b58
Moving the add-menu-form from the toolbar into the header.
shaunandrews 143df0b
Moving the props for the add form from the toolbar to the header.
shaunandrews f5cdbbb
A general refactor of the CSS, moving the add menu around, and genera…
shaunandrews c19c449
Navigation: Use <label> for dropdown instead of <p>
noisysocks 93f5efa
Navigation: Remove Cancel buton from AddMenuForm
noisysocks 62211f0
Navigation: 24px -> -unit-30
noisysocks 6e5df7d
Navigation: Remove isAddingMenu state
noisysocks 4a7da3f
Navigation: Simplify Add Menu Form
noisysocks 08980a2
Navigation: Remove menu location from label for now
noisysocks bdc1cdc
Navigation: Center spinner in Add Menu Form
noisysocks 1b668fb
Navigation: Improve mobile styling
noisysocks 74d6a8b
Navigation: Minor cleanup
noisysocks f4e9bb9
Navigation: Use className instead of h3
noisysocks a094256
Navigation: Use em for font-size
noisysocks 417ee55
Navigation: Remove Spinner from header
noisysocks bf6aefa
Navigation: Use $default-line-height
noisysocks 6125e6f
Navigation: Use className for h1
noisysocks 80215a7
Navigation: Remove unnecessary flexbox styling
noisysocks 5d06320
Navigation: VisualView -> BlockView
noisysocks d02bcb8
Navigation: Use deps in useSelect()
noisysocks 3ba5109
Navigation: Remove CSS re-ordering of block inspector, for now
noisysocks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
29 changes: 0 additions & 29 deletions
29
packages/edit-navigation/src/components/delete-menu-button/index.js
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
packages/edit-navigation/src/components/delete-menu-button/style.scss
This file was deleted.
Oops, something went wrong.
39 changes: 39 additions & 0 deletions
39
packages/edit-navigation/src/components/editor/block-view.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,39 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useSelect, useDispatch } from '@wordpress/data'; | ||
import { useEffect } from '@wordpress/element'; | ||
import { WritingFlow, ObserveTyping, BlockList } from '@wordpress/block-editor'; | ||
import { Spinner } from '@wordpress/components'; | ||
|
||
export default function BlockView( { isPending } ) { | ||
const rootClientId = useSelect( | ||
( select ) => select( 'core/block-editor' ).getBlocks()[ 0 ]?.clientId, | ||
[] | ||
); | ||
|
||
const { selectBlock } = useDispatch( 'core/block-editor' ); | ||
|
||
// Select the root Navigation block when it becomes available. | ||
useEffect( () => { | ||
if ( rootClientId ) { | ||
selectBlock( rootClientId ); | ||
} | ||
}, [ rootClientId, selectBlock ] ); | ||
|
||
return ( | ||
<div className="edit-navigation-editor__block-view"> | ||
{ isPending ? ( | ||
<Spinner /> | ||
) : ( | ||
<div className="editor-styles-wrapper"> | ||
<WritingFlow> | ||
<ObserveTyping> | ||
<BlockList /> | ||
</ObserveTyping> | ||
</WritingFlow> | ||
</div> | ||
) } | ||
</div> | ||
); | ||
} |
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,14 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import BlockView from './block-view'; | ||
import ListView from './list-view'; | ||
|
||
export default function Editor( { isPending, blocks } ) { | ||
return ( | ||
<div className="edit-navigation-editor"> | ||
<BlockView isPending={ isPending } /> | ||
<ListView isPending={ isPending } blocks={ blocks } /> | ||
</div> | ||
); | ||
} |
34 changes: 34 additions & 0 deletions
34
packages/edit-navigation/src/components/editor/list-view.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,34 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { useState } from '@wordpress/element'; | ||
import { Spinner } from '@wordpress/components'; | ||
import { __experimentalBlockNavigationTree } from '@wordpress/block-editor'; | ||
|
||
export default function ListView( { isPending, blocks } ) { | ||
const [ selectedBlockId, setSelectedBlockId ] = useState( | ||
blocks[ 0 ]?.clientId | ||
); | ||
|
||
return ( | ||
<div className="edit-navigation-editor__list-view"> | ||
<h3 className="edit-navigation-editor__list-view-title"> | ||
{ __( 'List view' ) } | ||
</h3> | ||
{ isPending ? ( | ||
<Spinner /> | ||
) : ( | ||
<__experimentalBlockNavigationTree | ||
blocks={ blocks } | ||
selectedBlockClientId={ selectedBlockId } | ||
selectBlock={ setSelectedBlockId } | ||
__experimentalFeatures | ||
showNestedBlocks | ||
showAppender | ||
showBlockMovers | ||
/> | ||
) } | ||
</div> | ||
); | ||
} |
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,45 @@ | ||
.edit-navigation-editor { | ||
margin: $grid-unit-20; | ||
|
||
@include break-medium() { | ||
align-items: flex-start; | ||
display: flex; | ||
} | ||
} | ||
|
||
.edit-navigation-editor__block-view { | ||
@include break-medium() { | ||
flex-grow: 1; | ||
} | ||
|
||
.components-spinner { | ||
display: block; | ||
margin: 10px auto; | ||
} | ||
} | ||
|
||
.edit-navigation-editor__list-view { | ||
border-top: 1px solid $gray-200; | ||
margin-top: $grid-unit-20; | ||
padding-top: $grid-unit-20; | ||
|
||
@include break-medium() { | ||
border-left: 1px solid $gray-200; | ||
border-top: none; | ||
margin-left: $grid-unit-20; | ||
margin-top: 0; | ||
padding-left: $grid-unit-20; | ||
padding-top: 0; | ||
width: 300px; | ||
} | ||
|
||
.edit-navigation-editor__list-view-title { | ||
font-size: 1.2em; | ||
margin: 0; | ||
} | ||
|
||
.components-spinner { | ||
display: block; | ||
margin: 100px auto; | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
packages/edit-navigation/src/components/header/add-menu-form.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,84 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { some } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useState } from '@wordpress/element'; | ||
import { useDispatch } from '@wordpress/data'; | ||
import { TextControl, Button } from '@wordpress/components'; | ||
import { __, sprintf } from '@wordpress/i18n'; | ||
|
||
const menuNameMatches = ( menuName ) => ( menu ) => | ||
menu.name.toLowerCase() === menuName.toLowerCase(); | ||
|
||
export default function AddMenuForm( { menus, onCreate } ) { | ||
const [ menuName, setMenuName ] = useState( '' ); | ||
|
||
const { createErrorNotice, createInfoNotice } = useDispatch( | ||
'core/notices' | ||
); | ||
|
||
const [ isCreatingMenu, setIsCreatingMenu ] = useState( false ); | ||
|
||
const { saveMenu } = useDispatch( 'core' ); | ||
|
||
const createMenu = async ( event ) => { | ||
event.preventDefault(); | ||
|
||
if ( ! menuName.length ) { | ||
return; | ||
} | ||
|
||
if ( some( menus, menuNameMatches( menuName ) ) ) { | ||
const message = sprintf( | ||
// translators: %s: the name of a menu. | ||
__( | ||
'The menu name %s conflicts with another menu name. Please try another.' | ||
), | ||
menuName | ||
); | ||
createErrorNotice( message, { id: 'edit-navigation-error' } ); | ||
return; | ||
} | ||
|
||
setIsCreatingMenu( true ); | ||
|
||
const menu = await saveMenu( { name: menuName } ); | ||
if ( menu ) { | ||
createInfoNotice( __( 'Menu created' ), { | ||
type: 'snackbar', | ||
isDismissible: true, | ||
} ); | ||
onCreate( menu.id ); | ||
} | ||
|
||
setIsCreatingMenu( false ); | ||
}; | ||
|
||
return ( | ||
<form onSubmit={ createMenu }> | ||
<TextControl | ||
// Disable reason: The name field should receive focus when | ||
// component mounts. | ||
// eslint-disable-next-line jsx-a11y/no-autofocus | ||
autoFocus | ||
label={ __( 'Menu name' ) } | ||
value={ menuName } | ||
onChange={ setMenuName } | ||
/> | ||
|
||
<Button | ||
className="edit-navigation-header__create-menu-button" | ||
type="submit" | ||
isPrimary | ||
disabled={ ! menuName.length } | ||
isBusy={ isCreatingMenu } | ||
> | ||
{ __( 'Create menu' ) } | ||
</Button> | ||
</form> | ||
); | ||
} |
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,83 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useViewportMatch } from '@wordpress/compose'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { Button, SelectControl, Dropdown } from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import ManageLocations from './manage-locations'; | ||
import AddMenuForm from './add-menu-form'; | ||
|
||
export default function Header( { menus, selectedMenuId, onSelectMenu } ) { | ||
const isMobileViewport = useViewportMatch( 'small', '<' ); | ||
|
||
return ( | ||
<div className="edit-navigation-header"> | ||
<h1 className="edit-navigation-header__title"> | ||
{ __( 'Navigation' ) } | ||
</h1> | ||
|
||
<div className="edit-navigation-header__actions"> | ||
<div className="edit-navigation-header__current-menu"> | ||
<SelectControl | ||
label={ __( 'Currently editing' ) } | ||
hideLabelFromVision={ isMobileViewport } | ||
disabled={ ! menus?.length } | ||
value={ selectedMenuId ?? 0 } | ||
options={ | ||
menus?.length | ||
? menus.map( ( menu ) => ( { | ||
value: menu.id, | ||
label: menu.name, | ||
} ) ) | ||
: [ | ||
{ | ||
value: 0, | ||
label: '-', | ||
}, | ||
] | ||
} | ||
onChange={ onSelectMenu } | ||
/> | ||
</div> | ||
|
||
<Dropdown | ||
position="bottom center" | ||
renderToggle={ ( { isOpen, onToggle } ) => ( | ||
<Button | ||
isTertiary | ||
aria-expanded={ isOpen } | ||
onClick={ onToggle } | ||
> | ||
{ __( 'Add new' ) } | ||
</Button> | ||
) } | ||
renderContent={ () => ( | ||
<AddMenuForm | ||
menus={ menus } | ||
onCreate={ onSelectMenu } | ||
/> | ||
) } | ||
/> | ||
|
||
<Dropdown | ||
contentClassName="edit-navigation-header__manage-locations" | ||
position="bottom center" | ||
renderToggle={ ( { isOpen, onToggle } ) => ( | ||
<Button | ||
isTertiary | ||
aria-expanded={ isOpen } | ||
onClick={ onToggle } | ||
> | ||
{ __( 'Manage locations' ) } | ||
</Button> | ||
) } | ||
renderContent={ () => <ManageLocations /> } | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens when
blocks
changes?For example, it changes from
[1, 2, 3]
to[4, 5, 6]
.selectedBlockId
is now out of sync, should we care about this at all?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest I'm not even sure why we're using local state instead of
select( 'core/block-editor' ).getSelectedBlockClientId()
. Maybe @talldan knows?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was already this way in
master
, so I've made a note to come back to this later.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this was @adamziel's change, #22705 should be the issue relating to the code.