Skip to content

Commit

Permalink
rebase with master, conflicts resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
grzegorz_marzencki committed Mar 23, 2021
1 parent 73b2d92 commit 272ce65
Show file tree
Hide file tree
Showing 9 changed files with 327 additions and 84 deletions.
45 changes: 0 additions & 45 deletions packages/edit-navigation/src/components/header/manage-locations.js
Original file line number Diff line number Diff line change
@@ -1,45 +0,0 @@
/**
* WordPress dependencies
*/
import { Spinner, SelectControl } from '@wordpress/components';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import useMenuLocations from '../../hooks/use-menu-locations';

export default function ManageLocations( { menus } ) {
const [ menuLocations, assignMenuToLocation ] = useMenuLocations();

if ( ! menus || ! menuLocations ) {
return <Spinner />;
}

if ( ! menus.length ) {
return <p>{ __( 'There are no available menus.' ) }</p>;
}

if ( ! menuLocations.length ) {
return <p>{ __( 'There are no available menu locations.' ) }</p>;
}

return menuLocations.map( ( menuLocation ) => (
<SelectControl
key={ menuLocation.name }
label={ menuLocation.description }
labelPosition="top"
value={ menuLocation.menu }
options={ [
{ value: 0, label: __( '— Select a Menu —' ) },
...menus.map( ( menu ) => ( {
value: menu.id,
label: menu.name,
} ) ),
] }
onChange={ ( menuId ) => {
assignMenuToLocation( menuLocation.name, Number( menuId ) );
} }
/>
) );
}
5 changes: 5 additions & 0 deletions packages/edit-navigation/src/components/header/save-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ import { __ } from '@wordpress/i18n';
* Internal dependencies
*/
import { store as editNavigationStore } from '../../store';
import { useMenuEntity, MenuIdContext } from '../../hooks';
import { useContext } from '@wordpress/element';

export default function SaveButton( { navigationPost } ) {
const menuId = useContext( MenuIdContext );
const { saveMenuName } = useMenuEntity( menuId );
const { saveNavigationPost } = useDispatch( editNavigationStore );

return (
Expand All @@ -19,6 +23,7 @@ export default function SaveButton( { navigationPost } ) {
isPrimary
onClick={ () => {
saveNavigationPost( navigationPost );
saveMenuName();
} }
disabled={ ! navigationPost }
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@ import { InspectorControls } from '@wordpress/block-editor';
*/
import AutoAddPagesPanel from './auto-add-pages-panel';
import DeleteMenuPanel from './delete-menu-panel';
import ManageLocations from './manage-locations';
import { NameEditor } from '../name-editor';
import { PanelBody } from '@wordpress/components';
import { __ } from '@wordpress/i18n';

export default function InspectorAdditions( { menuId, onDeleteMenu } ) {
export default function InspectorAdditions( {
menuId,
onDeleteMenu,
onSelectMenu,
isManageLocationsModalOpen,
closeManageLocationsModal,
openManageLocationsModal,
} ) {
const selectedBlock = useSelect(
( select ) => select( 'core/block-editor' ).getSelectedBlock(),
[]
Expand All @@ -25,7 +33,15 @@ export default function InspectorAdditions( { menuId, onDeleteMenu } ) {

return (
<InspectorControls>
<PanelBody title={ __( 'Menu Settings' ) }>
<PanelBody title={ __( 'Theme locations' ) }>
<ManageLocations
onSelectMenu={ onSelectMenu }
isModalOpen={ isManageLocationsModalOpen }
closeModal={ closeManageLocationsModal }
openModal={ openManageLocationsModal }
/>
</PanelBody>
<PanelBody title={ __( 'Menu settings' ) }>
<NameEditor />
<AutoAddPagesPanel menuId={ menuId } />
<DeleteMenuPanel onDeleteMenu={ onDeleteMenu } />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
/**
* WordPress dependencies
*/
import { useSelect } from '@wordpress/data';
import { useContext } from '@wordpress/element';
import {
Spinner,
SelectControl,
CheckboxControl,
Button,
Modal,
} from '@wordpress/components';
import { __, sprintf } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import { useMenuLocations, MenuIdContext } from '../../hooks';

export default function ManageLocations( {
onSelectMenu,
isModalOpen,
openModal,
closeModal,
} ) {
const menus = useSelect( ( select ) => select( 'core' ).getMenus(), [] );

const selectedMenuId = useContext( MenuIdContext );

const {
menuLocations,
assignMenuToLocation,
toggleMenuLocationAssignment,
} = useMenuLocations();

const themeLocationCountTextMain = sprintf(
// translators: Number of available theme locations.
__(
'Your current theme provides %d different locations to place menu.'
),
menuLocations.length
);

const themeLocationCountTextModal = sprintf(
// translators: Number of available theme locations.
__(
'Your current theme supports %d different locations. Select which menu appears in each location.'
),
menuLocations.length
);

const menusWithSelection = menuLocations.map( ( { name, menu } ) => {
const menuOnLocation = menus
.filter( ( { id } ) => ! [ 0, selectedMenuId ].includes( id ) )
.find( ( { id } ) => id === menu );

return (
<li
key={ name }
className="edit-navigation-manage-locations__checklist-item"
>
<CheckboxControl
className="edit-navigation-manage-locations__menu-location-checkbox"
checked={ menu === selectedMenuId }
onChange={ () =>
toggleMenuLocationAssignment( name, selectedMenuId )
}
label={ name }
help={
menuOnLocation &&
sprintf(
// translators: menu name.
__( 'Currently using %s' ),
menuOnLocation.name
)
}
/>
</li>
);
} );

if ( ! menus || ! menuLocations ) {
return <Spinner />;
}

if ( ! menuLocations.length ) {
return <p>{ __( 'There are no available menu locations.' ) }</p>;
}

const menuLocationCard = menuLocations.map( ( menuLocation ) => (
<div
key={ menuLocation.name }
className="edit-navigation-manage-locations__menu-entry"
>
<SelectControl
key={ menuLocation.name }
className="edit-navigation-manage-locations__select-menu"
label={ menuLocation.description }
labelPosition="top"
value={ menuLocation.menu }
options={ [
{ value: 0, label: __( '-' ), key: 0 },
...menus.map( ( { id, name } ) => ( {
key: id,
value: id,
label: name,
} ) ),
] }
onChange={ ( menuId ) => {
assignMenuToLocation( menuLocation.name, Number( menuId ) );
} }
/>
<Button
isSecondary
style={ {
visibility: !! menuLocation.menu ? 'visible' : 'hidden',
} }
className="edit-navigation-manage-locations__edit-button"
onClick={ () => (
closeModal(), onSelectMenu( menuLocation.menu )
) }
>
{ __( 'Edit' ) }
</Button>
</div>
) );

return (
<>
<div className="edit-navigation-manage-locations__theme-location-text-main">
{ themeLocationCountTextMain }
</div>
<ul className="edit-navigation-manage-locations__checklist">
{ menusWithSelection }
</ul>
<Button
isSecondary
className="edit-navigation-manage-locations__open-menu-locations-modal-button"
aria-expanded={ isModalOpen }
onClick={ openModal }
>
{ __( 'Manage locations' ) }
</Button>
{ isModalOpen && (
<Modal
className="edit-navigation-manage-locations__modal"
title={ __( 'Manage locations' ) }
onRequestClose={ closeModal }
>
<div className="edit-navigation-manage-locations__theme-location-text-modal">
{ themeLocationCountTextModal }
</div>
{ menuLocationCard }
</Modal>
) }
</>
);
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,59 @@
.edit-navigation-inspector-additions__delete-menu-panel {
text-align: center;
}

.block-editor-block-inspector__no-blocks,
.block-editor-block-inspector {
width: $sidebar-width;
background: $white;
border-left: 1px solid $gray-300;
position: fixed;
top: $grid-unit-40;
right: 0;
bottom: 0;
z-index: 1;
overflow: auto;
}

.edit-navigation-manage-locations__modal {
max-width: 360px;
}

.edit-navigation-manage-locations__delete-menu-panel {
text-align: center;
}

.edit-navigation-manage-locations__menu-entry .components-base-control {
width: 100%;
}

.edit-navigation-manage-locations__edit-button {
flex: 1;
}

.edit-navigation-manage-locations__menu-entry {
display: flex;
margin-bottom: $grid-unit-15;
margin-top: $grid-unit-15;
.components-custom-select-control,
.components-custom-select-control__button {
width: 100%;
}
button {
height: 100%;
}
}

.edit-navigation-manage-locations__select-menu {
padding-right: $grid-unit-10;
}

.edit-navigation-manage-locations__open-menu-locations-modal-button {
width: 100%;
justify-content: center;
}

.edit-navigation-manage-locations__theme-location-text-main,
.edit-navigation-manage-locations__theme-location-text-modal {
margin-bottom: $grid-unit-30;
}
15 changes: 15 additions & 0 deletions packages/edit-navigation/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ export default function Layout( { blockEditorSettings } ) {
navigationPost,
selectMenu,
deleteMenu,
openManageLocationsModal,
closeManageLocationsModal,
isManageLocationsModalOpen,
} = useNavigationEditor();

const [ blocks, onInput, onChange ] = useNavigationBlockEditor(
Expand Down Expand Up @@ -167,6 +170,18 @@ export default function Layout( { blockEditorSettings } ) {
blocks={ blocks }
/>
<InspectorAdditions
isManageLocationsModalOpen={
isManageLocationsModalOpen
}
openManageLocationsModal={
openManageLocationsModal
}
closeManageLocationsModal={
closeManageLocationsModal
}
onSelectMenu={
selectMenu
}
menuId={
selectedMenuId
}
Expand Down
Loading

0 comments on commit 272ce65

Please sign in to comment.