Skip to content

Commit

Permalink
Update Nav block permissions variable naming accuracy (WordPress#59882)
Browse files Browse the repository at this point in the history
* Rename vars for increased clarity

* Pluralise canCreate permission

* Update tests

* Improve comments

* Fix resolver naming

* Update tests

Co-authored-by: getdave <[email protected]>
Co-authored-by: scruffian <[email protected]>
  • Loading branch information
3 people authored and carstingaxion committed Mar 27, 2024
1 parent 99286d8 commit 9b06bf7
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 67 deletions.
24 changes: 13 additions & 11 deletions packages/block-library/src/navigation/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ function Navigation( {
hasResolvedCanUserUpdateNavigationMenu,
canUserDeleteNavigationMenu,
hasResolvedCanUserDeleteNavigationMenu,
canUserCreateNavigationMenu,
isResolvingCanUserCreateNavigationMenu,
hasResolvedCanUserCreateNavigationMenu,
canUserCreateNavigationMenus,
isResolvingCanUserCreateNavigationMenus,
hasResolvedCanUserCreateNavigationMenus,
} = useNavigationMenu( ref );

const navMenuResolvedButMissing =
Expand Down Expand Up @@ -467,8 +467,8 @@ function Navigation( {

if (
! ref &&
hasResolvedCanUserCreateNavigationMenu &&
! canUserCreateNavigationMenu
hasResolvedCanUserCreateNavigationMenus &&
! canUserCreateNavigationMenus
) {
showNavigationMenuPermissionsNotice(
__(
Expand All @@ -482,16 +482,16 @@ function Navigation( {
isInnerBlockSelected,
canUserUpdateNavigationMenu,
hasResolvedCanUserUpdateNavigationMenu,
canUserCreateNavigationMenu,
hasResolvedCanUserCreateNavigationMenu,
canUserCreateNavigationMenus,
hasResolvedCanUserCreateNavigationMenus,
ref,
hideNavigationMenuPermissionsNotice,
showNavigationMenuPermissionsNotice,
navMenuResolvedButMissing,
] );

const hasManagePermissions =
canUserCreateNavigationMenu || canUserUpdateNavigationMenu;
canUserCreateNavigationMenus || canUserUpdateNavigationMenu;

const overlayMenuPreviewClasses = classnames(
'wp-block-navigation__overlay-menu-preview',
Expand Down Expand Up @@ -801,9 +801,11 @@ function Navigation( {
isSelected={ isSelected }
currentMenuId={ ref }
clientId={ clientId }
canUserCreateNavigationMenu={ canUserCreateNavigationMenu }
isResolvingCanUserCreateNavigationMenu={
isResolvingCanUserCreateNavigationMenu
canUserCreateNavigationMenus={
canUserCreateNavigationMenus
}
isResolvingCanUserCreateNavigationMenus={
isResolvingCanUserCreateNavigationMenus
}
onSelectNavigationMenu={ onSelectNavigationMenu }
onSelectClassicMenu={ onSelectClassicMenu }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function NavigationMenuSelector( {
navigationMenus,
isResolvingNavigationMenus,
hasResolvedNavigationMenus,
canUserCreateNavigationMenu,
canUserCreateNavigationMenus,
canSwitchNavigationMenu,
} = useNavigationMenu();

Expand Down Expand Up @@ -100,7 +100,7 @@ function NavigationMenuSelector( {
const hasNavigationMenus = !! navigationMenus?.length;
const hasClassicMenus = !! classicMenus?.length;
const showNavigationMenus = !! canSwitchNavigationMenu;
const showClassicMenus = !! canUserCreateNavigationMenu;
const showClassicMenus = !! canUserCreateNavigationMenus;

const noMenuSelected = hasNavigationMenus && ! currentMenuId;
const noBlockMenus = ! hasNavigationMenus && hasResolvedNavigationMenus;
Expand Down Expand Up @@ -129,7 +129,7 @@ function NavigationMenuSelector( {
}, [
hasResolvedNavigationMenus,
createNavigationMenuIsSuccess,
canUserCreateNavigationMenu,
canUserCreateNavigationMenus,
createNavigationMenuIsError,
isUpdatingMenuRef,
menuUnavailable,
Expand Down Expand Up @@ -187,7 +187,7 @@ function NavigationMenuSelector( {
</MenuGroup>
) }

{ canUserCreateNavigationMenu && (
{ canUserCreateNavigationMenus && (
<MenuGroup label={ __( 'Tools' ) }>
<MenuItem
onClick={ async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export default function NavigationPlaceholder( {
isSelected,
currentMenuId,
clientId,
canUserCreateNavigationMenu = false,
isResolvingCanUserCreateNavigationMenu,
canUserCreateNavigationMenus = false,
isResolvingCanUserCreateNavigationMenus,
onSelectNavigationMenu,
onSelectClassicMenu,
onCreateEmpty,
Expand All @@ -41,7 +41,7 @@ export default function NavigationPlaceholder( {
}, [ hasResolvedMenus, isResolvingMenus, isSelected ] );

const isResolvingActions =
isResolvingMenus && isResolvingCanUserCreateNavigationMenu;
isResolvingMenus && isResolvingCanUserCreateNavigationMenus;

return (
<>
Expand Down Expand Up @@ -74,7 +74,7 @@ export default function NavigationPlaceholder( {

<hr />

{ canUserCreateNavigationMenu && (
{ canUserCreateNavigationMenus && (
<Button
variant="tertiary"
onClick={ onCreateEmpty }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe( 'NavigationMenuSelector', () => {
useNavigationMenu.mockReturnValue( {
navigationMenus: [],
hasResolvedNavigationMenus: true,
canUserCreateNavigationMenu: true,
canUserCreateNavigationMenus: true,
canSwitchNavigationMenu: true,
} );

Expand All @@ -115,7 +115,7 @@ describe( 'NavigationMenuSelector', () => {
navigationMenus: [],
isResolvingNavigationMenus: true,
hasResolvedNavigationMenus: false,
canUserCreateNavigationMenu: false,
canUserCreateNavigationMenus: false,
canSwitchNavigationMenu: true,
} );

Expand Down Expand Up @@ -152,7 +152,7 @@ describe( 'NavigationMenuSelector', () => {
useNavigationMenu.mockReturnValue( {
navigationMenus: [],
hasResolvedNavigationMenus: true,
canUserCreateNavigationMenu: true,
canUserCreateNavigationMenus: true,
canSwitchNavigationMenu: true,
} );

Expand Down Expand Up @@ -203,7 +203,7 @@ describe( 'NavigationMenuSelector', () => {
useNavigationMenu.mockReturnValue( {
navigationMenus: [],
hasResolvedNavigationMenus: true,
canUserCreateNavigationMenu: false,
canUserCreateNavigationMenus: false,
canSwitchNavigationMenu: true,
} );

Expand All @@ -226,7 +226,7 @@ describe( 'NavigationMenuSelector', () => {
useNavigationMenu.mockReturnValue( {
navigationMenus: [],
hasResolvedNavigationMenus: true,
canUserCreateNavigationMenu: true,
canUserCreateNavigationMenus: true,
canSwitchNavigationMenu: true,
} );

Expand Down Expand Up @@ -254,7 +254,7 @@ describe( 'NavigationMenuSelector', () => {
useNavigationMenu.mockReturnValue( {
navigationMenus: [],
hasResolvedNavigationMenus: true,
canUserCreateNavigationMenu: true,
canUserCreateNavigationMenus: true,
canSwitchNavigationMenu: true,
} );

Expand All @@ -278,7 +278,7 @@ describe( 'NavigationMenuSelector', () => {
navigationMenus: [],
hasResolvedNavigationMenus: false,
isResolvingNavigationMenus: true,
canUserCreateNavigationMenu: true,
canUserCreateNavigationMenus: true,
canSwitchNavigationMenu: true,
} );

Expand All @@ -303,7 +303,7 @@ describe( 'NavigationMenuSelector', () => {
navigationMenus: [],
hasResolvedNavigationMenus: true,
isResolvingNavigationMenus: false,
canUserCreateNavigationMenu: true,
canUserCreateNavigationMenus: true,
canSwitchNavigationMenu: true,
} );

Expand Down Expand Up @@ -331,7 +331,7 @@ describe( 'NavigationMenuSelector', () => {
useNavigationMenu.mockReturnValue( {
navigationMenus: navigationMenusFixture,
hasResolvedNavigationMenus: true,
canUserCreateNavigationMenu: true,
canUserCreateNavigationMenus: true,
canSwitchNavigationMenu: false,
} );

Expand All @@ -352,7 +352,7 @@ describe( 'NavigationMenuSelector', () => {
useNavigationMenu.mockReturnValue( {
navigationMenus: navigationMenusFixture,
hasResolvedNavigationMenus: true,
canUserCreateNavigationMenu: false,
canUserCreateNavigationMenus: false,
canSwitchNavigationMenu: true,
} );

Expand Down Expand Up @@ -391,7 +391,7 @@ describe( 'NavigationMenuSelector', () => {
useNavigationMenu.mockReturnValue( {
navigationMenus: menusWithNoTitle,
hasResolvedNavigationMenus: true,
canUserCreateNavigationMenu: true,
canUserCreateNavigationMenus: true,
canSwitchNavigationMenu: true,
} );

Expand Down Expand Up @@ -425,7 +425,7 @@ describe( 'NavigationMenuSelector', () => {
useNavigationMenu.mockReturnValue( {
navigationMenus: navigationMenusFixture,
hasResolvedNavigationMenus: true,
canUserCreateNavigationMenu: true,
canUserCreateNavigationMenus: true,
canSwitchNavigationMenu: true,
} );

Expand Down Expand Up @@ -453,7 +453,7 @@ describe( 'NavigationMenuSelector', () => {
useNavigationMenu.mockReturnValue( {
navigationMenus: navigationMenusFixture,
hasResolvedNavigationMenus: true,
canUserCreateNavigationMenu: true,
canUserCreateNavigationMenus: true,
canSwitchNavigationMenu: true,
} );

Expand Down Expand Up @@ -504,7 +504,7 @@ describe( 'NavigationMenuSelector', () => {
const user = userEvent.setup();

useNavigationMenu.mockReturnValue( {
canUserCreateNavigationMenu: false,
canUserCreateNavigationMenus: false,
} );

useNavigationEntities.mockReturnValue( {
Expand All @@ -526,7 +526,7 @@ describe( 'NavigationMenuSelector', () => {
const user = userEvent.setup();

useNavigationMenu.mockReturnValue( {
canUserCreateNavigationMenu: true,
canUserCreateNavigationMenus: true,
} );

useNavigationEntities.mockReturnValue( {
Expand Down Expand Up @@ -563,7 +563,7 @@ describe( 'NavigationMenuSelector', () => {
isResolvingNavigationMenus: false,
hasResolvedNavigationMenus: true,
canSwitchNavigationMenu: true,
canUserCreateNavigationMenu: true,
canUserCreateNavigationMenus: true,
} );

useNavigationEntities.mockReturnValue( {
Expand Down Expand Up @@ -595,7 +595,7 @@ describe( 'NavigationMenuSelector', () => {
navigationMenus: [],
isResolvingNavigationMenus: true,
hasResolvedNavigationMenus: false,
canUserCreateNavigationMenu: true,
canUserCreateNavigationMenus: true,
} );

useNavigationEntities.mockReturnValue( {
Expand Down Expand Up @@ -628,7 +628,7 @@ describe( 'NavigationMenuSelector', () => {
navigationMenus: [],
isResolvingNavigationMenus: false,
hasResolvedNavigationMenus: true,
canUserCreateNavigationMenu: true,
canUserCreateNavigationMenus: true,
} );

useNavigationEntities.mockReturnValue( {
Expand Down
Loading

0 comments on commit 9b06bf7

Please sign in to comment.