Skip to content

Commit

Permalink
Improve consistency of Navigation block hook (#38705)
Browse files Browse the repository at this point in the history
* Rename to include "Menu" terminology

Remove "entity" in favour of "menu"

Attempt to fix failing e2e test

* Rename all instances

* Remove unneeded aliasing
  • Loading branch information
getdave authored Feb 14, 2022
1 parent 0bad51e commit ea32685
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 32 deletions.
42 changes: 22 additions & 20 deletions packages/block-library/src/navigation/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,12 @@ function Navigation( {
hasResolvedNavigationMenus,
navigationMenus,
navigationMenu,
canUserUpdateNavigationEntity,
hasResolvedCanUserUpdateNavigationEntity,
canUserDeleteNavigationEntity,
hasResolvedCanUserDeleteNavigationEntity,
canUserCreateNavigation,
hasResolvedCanUserCreateNavigation,
canUserUpdateNavigationMenu,
hasResolvedCanUserUpdateNavigationMenu,
canUserDeleteNavigationMenu,
hasResolvedCanUserDeleteNavigationMenu,
canUserCreateNavigationMenu,
hasResolvedCanUserCreateNavigationMenu,
} = useNavigationMenu( ref );

const navRef = useRef();
Expand Down Expand Up @@ -361,27 +361,27 @@ function Navigation( {

if ( isSelected || isInnerBlockSelected ) {
if (
hasResolvedCanUserUpdateNavigationEntity &&
! canUserUpdateNavigationEntity
hasResolvedCanUserUpdateNavigationMenu &&
! canUserUpdateNavigationMenu
) {
showCantEditNotice();
}

if (
! ref &&
hasResolvedCanUserCreateNavigation &&
! canUserCreateNavigation
hasResolvedCanUserCreateNavigationMenu &&
! canUserCreateNavigationMenu
) {
showCantCreateNotice();
}
}
}, [
isSelected,
isInnerBlockSelected,
canUserUpdateNavigationEntity,
hasResolvedCanUserUpdateNavigationEntity,
canUserCreateNavigation,
hasResolvedCanUserCreateNavigation,
canUserUpdateNavigationMenu,
hasResolvedCanUserUpdateNavigationMenu,
canUserCreateNavigationMenu,
hasResolvedCanUserCreateNavigationMenu,
ref,
] );

Expand Down Expand Up @@ -645,12 +645,12 @@ function Navigation( {
</InspectorControls>
{ isEntityAvailable && (
<InspectorControls __experimentalGroup="advanced">
{ hasResolvedCanUserUpdateNavigationEntity &&
canUserUpdateNavigationEntity && (
{ hasResolvedCanUserUpdateNavigationMenu &&
canUserUpdateNavigationMenu && (
<NavigationMenuNameControl />
) }
{ hasResolvedCanUserDeleteNavigationEntity &&
canUserDeleteNavigationEntity && (
{ hasResolvedCanUserDeleteNavigationMenu &&
canUserDeleteNavigationMenu && (
<NavigationMenuDeleteControl
onDelete={ startWithEmptyMenu }
/>
Expand All @@ -672,10 +672,12 @@ function Navigation( {
hasResolvedNavigationMenus
}
clientId={ clientId }
canUserCreateNavigation={ canUserCreateNavigation }
canUserCreateNavigationMenu={
canUserCreateNavigationMenu
}
/>
) }
{ ! hasResolvedCanUserCreateNavigation ||
{ ! hasResolvedCanUserCreateNavigationMenu ||
( ! isEntityAvailable && ! isPlaceholderShown && (
<PlaceholderPreview isLoading />
) ) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export default function NavigationMenuSelector( {

const {
navigationMenus,
canUserCreateNavigation: canUserCreateNavigationMenu,
canUserUpdateNavigationEntity: canUserUpdateNavigationMenu,
canUserCreateNavigationMenu,
canUserUpdateNavigationMenu,
canSwitchNavigationMenu,
} = useNavigationMenu();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ export default function NavigationPlaceholder( {
onFinish,
canSwitchNavigationMenu,
hasResolvedNavigationMenus,
canUserCreateNavigation = false,
canUserCreateNavigationMenu = false,
} ) {
const createNavigationMenu = useCreateNavigationMenu( clientId );

const onFinishMenuCreation = async (
blocks,
navigationMenuTitle = null
) => {
if ( ! canUserCreateNavigation ) {
if ( ! canUserCreateNavigationMenu ) {
return;
}

Expand Down Expand Up @@ -56,7 +56,7 @@ export default function NavigationPlaceholder( {
const hasNavigationMenus = !! navigationMenus?.length;

const showSelectMenus =
( canSwitchNavigationMenu || canUserCreateNavigation ) &&
( canSwitchNavigationMenu || canUserCreateNavigationMenu ) &&
( hasNavigationMenus || hasMenus );

return (
Expand Down Expand Up @@ -100,7 +100,7 @@ export default function NavigationPlaceholder( {
</>
) : undefined }

{ canUserCreateNavigation && (
{ canUserCreateNavigationMenu && (
<Button
variant="tertiary"
onClick={ onCreateEmptyMenu }
Expand Down
12 changes: 6 additions & 6 deletions packages/block-library/src/navigation/use-navigation-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,22 @@ export default function useNavigationMenu( ref ) {
),
navigationMenu,
navigationMenus,
canUserUpdateNavigationEntity: ref
canUserUpdateNavigationMenu: ref
? canUser( 'update', 'navigation', ref )
: undefined,
hasResolvedCanUserUpdateNavigationEntity: hasFinishedResolution(
hasResolvedCanUserUpdateNavigationMenu: hasFinishedResolution(
'canUser',
[ 'update', 'navigation', ref ]
),
canUserDeleteNavigationEntity: ref
canUserDeleteNavigationMenu: ref
? canUser( 'delete', 'navigation', ref )
: undefined,
hasResolvedCanUserDeleteNavigationEntity: hasFinishedResolution(
hasResolvedCanUserDeleteNavigationMenu: hasFinishedResolution(
'canUser',
[ 'delete', 'navigation', ref ]
),
canUserCreateNavigation: canUser( 'create', 'navigation' ),
hasResolvedCanUserCreateNavigation: hasFinishedResolution(
canUserCreateNavigationMenu: canUser( 'create', 'navigation' ),
hasResolvedCanUserCreateNavigationMenu: hasFinishedResolution(
'canUser',
[ 'create', 'navigation' ]
),
Expand Down

0 comments on commit ea32685

Please sign in to comment.