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

[Navigation editor] Save menu items using the REST API #34541

Merged
merged 57 commits into from
Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
4863f57
Remove tests
spacedmonkey Sep 9, 2021
4310b3e
Validate if menu_order is set and >= 1
adamziel Sep 10, 2021
58598b1
First stab at saving menu items using the REST API
adamziel Sep 3, 2021
4ab63b8
Migrate batch save to async thunks using REST API calls
adamziel Sep 7, 2021
1e94429
simplify the logic
adamziel Sep 8, 2021
ba54594
Simplify computeDeletedMenuItemIds
adamziel Sep 8, 2021
082bf8d
Use more generic variable names
adamziel Sep 8, 2021
d805067
Use more consistent variable names
adamziel Sep 8, 2021
8a7cb65
Update the data flow to ensure API receives appropriate parameters names
adamziel Sep 8, 2021
5683433
Alter the order of arguments in blockToMenuItem
adamziel Sep 8, 2021
7eaf186
Move transformations to transform.js
adamziel Sep 8, 2021
9357af3
Remove dev comment
adamziel Sep 8, 2021
1c5e66b
Operate on lists and sets, not on trees
adamziel Sep 8, 2021
8c90ae8
Extract batchSaveMenuItems
adamziel Sep 8, 2021
0dbc490
Inline blockIdToOldEntityRecord
adamziel Sep 8, 2021
9532bd4
Ensure consistency between stored menu items and the ones recovered f…
adamziel Sep 9, 2021
a0eab6e
Add error checking
adamziel Sep 9, 2021
11f3d4b
Add generic batchSaveDiff function
adamziel Sep 9, 2021
6667fcc
Preprocess menu data before sending it over to the API
adamziel Sep 9, 2021
44fc290
Adjust unit tests
adamziel Sep 9, 2021
2be5615
Remove dev artifacts
adamziel Sep 9, 2021
2fcc115
Replace map/filter with a for loop for readability
adamziel Sep 10, 2021
2ecdeb3
Rename "new" to Desired" to avoid abiguity
adamziel Sep 10, 2021
68e0ea3
Rename tasks and diffs to changesets
adamziel Sep 10, 2021
5dcdb56
Remove prePersistMenuItem
adamziel Sep 14, 2021
61d44b7
Don't await releaseStoreLock
adamziel Sep 14, 2021
520dde4
Inline resolveSelectMenuItems
adamziel Sep 14, 2021
d9f5e9a
Resolve a list of all menu items prior to creating placeholder menu i…
adamziel Sep 14, 2021
91baba8
Remove async code from the synchronous getDesiredMenuItems selector
adamziel Sep 14, 2021
259a09a
Don't await createErrorNotice and createSuccessNotice
adamziel Sep 14, 2021
4146878
Rename computeChangeset to prepareChangeset and remove awaits from it…
adamziel Sep 14, 2021
cfa7bbf
Use store object to refer to core-data store, not a string identifier
adamziel Sep 14, 2021
315b9cc
Set placeholder menu order to 1
adamziel Sep 14, 2021
a54f430
Don't create placeholder menu items for non-link blocks
adamziel Sep 14, 2021
2d5c1f2
Remove menu order validation
adamziel Sep 14, 2021
fb989c6
Remove menu id validation
adamziel Sep 14, 2021
ee5e703
Restore rest_invalid_param validation error code
adamziel Sep 14, 2021
5a6f86b
Fix unit tests
adamziel Sep 14, 2021
7b46df1
Add comments blocks
adamziel Sep 14, 2021
7f78627
Remove "@TODO: extract locks to a separate package?"
adamziel Sep 15, 2021
09d7e18
Remove unused block argument from createPlaceholderMenuItem
adamziel Sep 15, 2021
fc9dca3
Remove obsolete "block" argument
adamziel Sep 15, 2021
6248810
Replace diff() with _.difference()
adamziel Sep 15, 2021
cf69c6e
Replace clientId mapping with internal attribute denoting entity reco…
adamziel Sep 15, 2021
b3a6b08
Radically simplify batch saving
adamziel Sep 17, 2021
fa3768c
Fix unit tests
adamziel Sep 17, 2021
33d45b0
Translate Menu item title
adamziel Sep 17, 2021
77f3316
Remove obsolete imports
adamziel Sep 17, 2021
89182df
Switch to using immutable data structures
adamziel Sep 20, 2021
fb90bd6
Add doc blocks
adamziel Sep 20, 2021
fa30c0f
Add a test for default 'menu-item-type'
adamziel Sep 20, 2021
9efdb57
Restore newline
adamziel Sep 20, 2021
de2a3d4
Lint
adamziel Sep 20, 2021
56b5579
Use isBlockSupportedInNav in blockToMenuItem
adamziel Sep 21, 2021
d62f3bf
Lint
adamziel Sep 21, 2021
005fbfd
Code style: Collapse two filters into one
adamziel Sep 21, 2021
4ff8b16
Inline applyEdits
adamziel Sep 21, 2021
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
1 change: 1 addition & 0 deletions lib/class-wp-rest-menu-items-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ protected function prepare_item_for_database( $request ) {
'menu-item-object' => $menu_item_obj->object,
'menu-item-parent-id' => $menu_item_obj->menu_item_parent,
'menu-item-position' => $position,
'menu-item-type' => $menu_item_obj->type,
noisysocks marked this conversation as resolved.
Show resolved Hide resolved
'menu-item-title' => $menu_item_obj->title,
'menu-item-url' => $menu_item_obj->url,
'menu-item-description' => $menu_item_obj->description,
Expand Down
1 change: 1 addition & 0 deletions packages/core-data/src/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export const defaultEntities = [
baseURLParams: { context: 'edit' },
plural: 'menuItems',
label: __( 'Menu Item' ),
rawAttributes: [ 'title', 'content' ],
},
{
name: 'menuLocation',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { chevronDown } from '@wordpress/icons';
*/
import { useMenuEntityProp, useSelectedMenuId } from '../../hooks';
import useNavigationEntities from './use-navigation-entities';
import menuItemsToBlocks from './menu-items-to-blocks';
import { menuItemsToBlocks } from '../../store/transform';

/**
* Convert pages to blocks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { createBlock } from '@wordpress/blocks';
/**
* Internal dependencies
*/
import { menuItemToBlockAttributes } from '../../store/utils';
import { menuItemToBlockAttributes } from '../../store/transform';

/**
* Convert a flat menu item structure to a nested blocks structure.
Expand Down
10 changes: 7 additions & 3 deletions packages/edit-navigation/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
BlockTools,
__unstableUseBlockSelectionClearer as useBlockSelectionClearer,
} from '@wordpress/block-editor';
import { useEntityBlockEditor } from '@wordpress/core-data';
import { Popover, SlotFillProvider, Spinner } from '@wordpress/components';
import { useDispatch, useSelect } from '@wordpress/data';
import { useEffect, useMemo, useState } from '@wordpress/element';
Expand All @@ -25,7 +26,6 @@ import UnselectedMenuState from './unselected-menu-state';
import {
IsMenuNameControlFocusedContext,
useNavigationEditor,
useNavigationBlockEditor,
useMenuNotifications,
} from '../../hooks';
import ErrorBoundary from '../error-boundary';
Expand Down Expand Up @@ -68,8 +68,12 @@ export default function Layout( { blockEditorSettings } ) {
isMenuSelected,
} = useNavigationEditor();

const [ blocks, onInput, onChange ] = useNavigationBlockEditor(
navigationPost
const [ blocks, onInput, onChange ] = useEntityBlockEditor(
'root',
'postType',
{
id: navigationPost?.id,
}
);

const { hasSidebarEnabled, isInserterOpened } = useSelect(
Expand Down
1 change: 0 additions & 1 deletion packages/edit-navigation/src/hooks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export const IsMenuNameControlFocusedContext = createContext();
export { default as useMenuEntity } from './use-menu-entity';
export { default as useMenuEntityProp } from './use-menu-entity-prop';
export { default as useNavigationEditor } from './use-navigation-editor';
export { default as useNavigationBlockEditor } from './use-navigation-block-editor';
export { default as useMenuNotifications } from './use-menu-notifications';
export { default as useSelectedMenuId } from './use-selected-menu-id';
export { default as useMenuLocations } from './use-menu-locations';
Expand Down
34 changes: 0 additions & 34 deletions packages/edit-navigation/src/hooks/use-navigation-block-editor.js

This file was deleted.

Loading