From bd1ce1271a536a83faa0911a47a15a406d8e05ee Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Thu, 3 Sep 2020 17:39:16 +1000 Subject: [PATCH 1/2] Set up advanced attributes on nav screen. --- packages/edit-navigation/src/store/resolvers.js | 4 ++++ packages/edit-navigation/src/store/utils.js | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/edit-navigation/src/store/resolvers.js b/packages/edit-navigation/src/store/resolvers.js index ab346ac089365..99a0f76ae4b05 100644 --- a/packages/edit-navigation/src/store/resolvers.js +++ b/packages/edit-navigation/src/store/resolvers.js @@ -128,6 +128,10 @@ function convertMenuItemToBlock( menuItem, innerBlocks = [] ) { const attributes = { label: menuItem.title.rendered, url: menuItem.url, + title: menuItem.attr_title, + className: menuItem.classes.join( ' ' ), + description: menuItem.description, + rel: menuItem.xfn.join( ' ' ), }; return createBlock( 'core/navigation-link', attributes, innerBlocks ); diff --git a/packages/edit-navigation/src/store/utils.js b/packages/edit-navigation/src/store/utils.js index cc0f8ed2bdef6..42f8b5d56135e 100644 --- a/packages/edit-navigation/src/store/utils.js +++ b/packages/edit-navigation/src/store/utils.js @@ -154,6 +154,10 @@ export function computeCustomizedAttribute( title: block.attributes?.label, original_title: '', url: block.attributes.url, + description: block.attributes.description, + xfn: block.attributes.rel, + classes: block.attributes.className, + attr_title: block.attributes.title, }; } else { attributes = { @@ -166,8 +170,6 @@ export function computeCustomizedAttribute( ...menuItem, ...attributes, position, - classes: ( menuItem.classes || [] ).join( ' ' ), - xfn: ( menuItem.xfn || [] ).join( ' ' ), nav_menu_term_id: menuId, menu_item_parent: parentId, status: 'publish', From f74580d0286749712b6b700b181fea256c1c671f Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Fri, 4 Sep 2020 10:48:37 +1000 Subject: [PATCH 2/2] Add new attribs to tests. --- .../edit-navigation/src/store/test/actions.js | 32 +++++++++++++++++++ .../src/store/test/resolvers.js | 16 ++++++++++ .../edit-navigation/src/store/test/utils.js | 12 ++++--- packages/edit-navigation/src/store/utils.js | 4 +-- 4 files changed, 58 insertions(+), 6 deletions(-) diff --git a/packages/edit-navigation/src/store/test/actions.js b/packages/edit-navigation/src/store/test/actions.js index a4f7cab5b06b1..a300950e5e14e 100644 --- a/packages/edit-navigation/src/store/test/actions.js +++ b/packages/edit-navigation/src/store/test/actions.js @@ -244,6 +244,10 @@ describe( 'saveNavigationPost', () => { label: 'wp.org', opensInNewTab: false, url: 'http://wp.org', + className: '', + rel: '', + description: '', + title: '', }, clientId: 'navigation-link-block-client-id-1', innerBlocks: [], @@ -255,6 +259,10 @@ describe( 'saveNavigationPost', () => { label: 'wp.com', opensInNewTab: false, url: 'http://wp.com', + className: '', + rel: '', + description: '', + title: '', }, clientId: 'navigation-link-block-client-id-2', innerBlocks: [], @@ -278,6 +286,10 @@ describe( 'saveNavigationPost', () => { url: 'http://wp.com', menu_order: 1, menus: [ 1 ], + classes: [], + xfn: [], + description: '', + attr_title: '', }, { id: 101, @@ -288,6 +300,10 @@ describe( 'saveNavigationPost', () => { url: 'http://wp.org', menu_order: 2, menus: [ 1 ], + classes: [], + xfn: [], + description: '', + attr_title: '', }, ]; @@ -358,6 +374,10 @@ describe( 'saveNavigationPost', () => { label: 'wp.org', opensInNewTab: false, url: 'http://wp.org', + className: '', + rel: '', + description: '', + title: '', }, clientId: 'navigation-link-block-client-id-1', innerBlocks: [], @@ -369,6 +389,10 @@ describe( 'saveNavigationPost', () => { label: 'wp.com', opensInNewTab: false, url: 'http://wp.com', + className: '', + rel: '', + description: '', + title: '', }, clientId: 'navigation-link-block-client-id-2', innerBlocks: [], @@ -392,6 +416,10 @@ describe( 'saveNavigationPost', () => { url: 'http://wp.com', menu_order: 1, menus: [ 1 ], + classes: [], + xfn: [], + description: '', + attr_title: '', }, { id: 101, @@ -402,6 +430,10 @@ describe( 'saveNavigationPost', () => { url: 'http://wp.org', menu_order: 2, menus: [ 1 ], + classes: [], + xfn: [], + description: '', + attr_title: '', }, ]; diff --git a/packages/edit-navigation/src/store/test/resolvers.js b/packages/edit-navigation/src/store/test/resolvers.js index ecb5a299e95cb..a46d624bba727 100644 --- a/packages/edit-navigation/src/store/test/resolvers.js +++ b/packages/edit-navigation/src/store/test/resolvers.js @@ -76,6 +76,10 @@ describe( 'getNavigationPostForMenu', () => { menu_order: 1, menus: [ 1 ], parent: 0, + classes: [ 'menu', 'classes' ], + xfn: [ 'nofollow' ], + description: 'description', + attr_title: 'link title', }, { id: 101, @@ -87,6 +91,10 @@ describe( 'getNavigationPostForMenu', () => { menu_order: 2, menus: [ 1 ], parent: 0, + classes: [], + xfn: [], + description: '', + attr_title: '', }, ]; @@ -113,6 +121,10 @@ describe( 'getNavigationPostForMenu', () => { attributes: { label: 'wp.com', url: 'http://wp.com', + className: 'menu classes', + rel: 'nofollow', + description: 'description', + title: 'link title', }, clientId: 'client-id-0', innerBlocks: [], @@ -122,6 +134,10 @@ describe( 'getNavigationPostForMenu', () => { attributes: { label: 'wp.org', url: 'http://wp.org', + className: '', + rel: '', + description: '', + title: '', }, clientId: 'client-id-1', innerBlocks: [], diff --git a/packages/edit-navigation/src/store/test/utils.js b/packages/edit-navigation/src/store/test/utils.js index 69431212ce349..fdbf837bcaa78 100644 --- a/packages/edit-navigation/src/store/test/utils.js +++ b/packages/edit-navigation/src/store/test/utils.js @@ -216,6 +216,8 @@ describe( 'computeCustomizedAttribute', () => { label: 'wp.org', opensInNewTab: false, url: 'http://wp.org', + className: 'block classnames', + rel: 'external', }, clientId: 'navigation-link-block-client-id-1', innerBlocks: [], @@ -227,6 +229,8 @@ describe( 'computeCustomizedAttribute', () => { label: 'wp.com', opensInNewTab: false, url: 'http://wp.com', + className: '', + rel: '', }, clientId: 'navigation-link-block-client-id-2', innerBlocks: [], @@ -271,7 +275,7 @@ describe( 'computeCustomizedAttribute', () => { ).toEqual( { 'nav_menu_item[100]': { _invalid: false, - classes: '', + classes: [ 'block', 'classnames' ], id: 100, menu_item_parent: 0, menu_order: 1, @@ -282,11 +286,11 @@ describe( 'computeCustomizedAttribute', () => { title: 'wp.org', type: 'custom', url: 'http://wp.org', - xfn: '', + xfn: [ 'external' ], }, 'nav_menu_item[101]': { _invalid: false, - classes: '', + classes: [ '' ], id: 101, menu_item_parent: 0, menu_order: 2, @@ -297,7 +301,7 @@ describe( 'computeCustomizedAttribute', () => { title: 'wp.com', type: 'custom', url: 'http://wp.com', - xfn: '', + xfn: [ '' ], }, } ); } ); diff --git a/packages/edit-navigation/src/store/utils.js b/packages/edit-navigation/src/store/utils.js index 42f8b5d56135e..2bd1f9b9706fb 100644 --- a/packages/edit-navigation/src/store/utils.js +++ b/packages/edit-navigation/src/store/utils.js @@ -155,8 +155,8 @@ export function computeCustomizedAttribute( original_title: '', url: block.attributes.url, description: block.attributes.description, - xfn: block.attributes.rel, - classes: block.attributes.className, + xfn: block.attributes.rel.split( ' ' ), + classes: block.attributes.className.split( ' ' ), attr_title: block.attributes.title, }; } else {