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

Improve consistency of Navigation block hook #38705

Merged
merged 3 commits into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
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