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

Page parent selector with ComboboxControl. #25267

Merged
merged 35 commits into from
Oct 16, 2020
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
a325579
Editor still loads if page or template type is not set
noahtallen Jul 7, 2020
a379413
Create homepage state reducer
noahtallen Jul 7, 2020
62b37d7
Remove initial state from PHP
noahtallen Jul 7, 2020
4af2c1c
Move home page resolution to client
noahtallen Jul 7, 2020
95124bf
Consolidate entityId logic
noahtallen Jul 9, 2020
9fe3fea
Consolidate activePage?.path
noahtallen Jul 9, 2020
e855102
Rework setupstate
noahtallen Jul 9, 2020
f9b2d52
Load home data over API
noahtallen Jul 9, 2020
6265ec3
Rename camelcase
noahtallen Jul 13, 2020
631e815
Remove templateId from setPage
noahtallen Jul 13, 2020
0d30cca
Naive cache results of findTemplate
noahtallen Jul 14, 2020
3a1da28
Rename cache variable
noahtallen Jul 14, 2020
7e6e1e3
Add text domain to setting translation
noahtallen Jul 14, 2020
f3d2b40
Fix existing JS unit tests
noahtallen Jul 14, 2020
821ced6
Fix e2e test
noahtallen Jul 15, 2020
24ef5c6
merge from origin/master
adamsilverstein Aug 14, 2020
8a80e6a
update after merge from origin/master
adamsilverstein Aug 14, 2020
e3d043c
Merge branch 'master' of github.com:WordPress/gutenberg
adamsilverstein Aug 14, 2020
ea2921f
Merge branch 'master' of github.com:WordPress/gutenberg
adamsilverstein Aug 26, 2020
40022d9
Merge branch 'master' of github.com:WordPress/gutenberg
adamsilverstein Sep 3, 2020
5f52dd9
Merge branch 'master' of github.com:WordPress/gutenberg
adamsilverstein Sep 9, 2020
f991486
Merge branch 'master' of github.com:WordPress/gutenberg
adamsilverstein Sep 11, 2020
f7c4c34
Merge branch 'master' of github.com:WordPress/gutenberg
adamsilverstein Sep 11, 2020
e0b000d
Merge branch 'master' of github.com:WordPress/gutenberg
adamsilverstein Sep 11, 2020
375bdc9
Page selector combobox, first pass.
adamsilverstein Sep 11, 2020
353c1d3
Additional work on page selector.
adamsilverstein Sep 14, 2020
eb71a7d
Merge branch 'master' into add/9441-page-selector-b
adamsilverstein Sep 14, 2020
90418ec
Clean up refresh on search, load.
adamsilverstein Sep 15, 2020
f334c9e
Merge remote-tracking branch 'origin/master' into add/9441-page-selec…
youknowriad Sep 28, 2020
d1b62c7
Merge remote-tracking branch 'origin/master' into add/9441-page-selec…
youknowriad Oct 12, 2020
5193869
Fix end2end test
youknowriad Oct 12, 2020
aa701ad
deoptimize fields filtering in the data module
youknowriad Oct 13, 2020
1398f6f
Avoid useless double useSelect
youknowriad Oct 13, 2020
ac897bd
Remove duplications
youknowriad Oct 13, 2020
edd314b
Fix unit test
youknowriad Oct 13, 2020
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
8 changes: 7 additions & 1 deletion packages/components/src/combobox-control/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* External dependencies
*/
import classnames from 'classnames';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -26,6 +31,7 @@ function ComboboxControl( {
hideLabelFromVision,
help,
allowReset = true,
className,
messages = {
selected: __( 'Item selected.' ),
},
Expand Down Expand Up @@ -155,7 +161,7 @@ function ComboboxControl( {
/* eslint-disable jsx-a11y/no-static-element-interactions */
return (
<BaseControl
className="components-combobox-control"
className={ classnames( className, 'components-combobox-control' ) }
tabIndex="-1"
label={ label }
id={ `components-form-token-input-${ instanceId }` }
Expand Down
13 changes: 9 additions & 4 deletions packages/core-data/src/queried-data/get-query-parts.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,16 @@ export function getQueryParts( query ) {
);
break;

case '_fields':
parts.fields = getNormalizedCommaSeparable( value );
break;

default:
// While in theory, we could exclude "_fields" from the stableKey
// because two request with different fields have the same results
// We're not able to ensure that because the server can decide to omit
// fields from the response even if we explicitely asked for it.
// Example: Asking for titles in posts without title support.
if ( key === '_fields' ) {
parts.fields = getNormalizedCommaSeparable( value );
}

// While it could be any deterministic string, for simplicity's
// sake mimic querystring encoding for stable key.
//
Expand Down
10 changes: 1 addition & 9 deletions packages/core-data/src/queried-data/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import createSelector from 'rememo';
import EquivalentKeyMap from 'equivalent-key-map';
import { get, has, set } from 'lodash';
import { get, set } from 'lodash';

/**
* Internal dependencies
Expand Down Expand Up @@ -31,7 +31,6 @@ function getQueriedItemsUncached( state, query ) {
const { stableKey, page, perPage, include, fields } = getQueryParts(
query
);

let itemIds;
if ( Array.isArray( include ) && ! stableKey ) {
// If the parsed query yields a set of IDs, but otherwise no filtering,
Expand Down Expand Up @@ -73,14 +72,7 @@ function getQueriedItemsUncached( state, query ) {
filteredItem = {};

for ( let f = 0; f < fields.length; f++ ) {
// Abort the entire request if a field is missing from the item.
// This accounts for the fact that queried items are stored by
// stable key without an associated fields query. Other requests
// may have included fewer fields properties.
const field = fields[ f ].split( '.' );
if ( ! has( item, field ) ) {
return null;
}
const value = get( item, field );
set( filteredItem, field, value );
}
Expand Down
12 changes: 0 additions & 12 deletions packages/core-data/src/queried-data/test/get-query-parts.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,6 @@ describe( 'getQueryParts', () => {
} );
} );

it( 'parses out `_fields` property filtering', () => {
const parts = getQueryParts( { _fields: 'content', a: 1 } );

expect( parts ).toEqual( {
page: 1,
perPage: 10,
stableKey: 'a=1',
fields: [ 'content' ],
include: null,
} );
} );

it( 'encodes stable string key', () => {
const first = getQueryParts( { '?': '&', b: 2 } );
const second = getQueryParts( { b: 2, '?': '&' } );
Expand Down
4 changes: 2 additions & 2 deletions packages/core-data/src/queried-data/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe( 'getQueriedItems', () => {
2: true,
},
queries: {
'': [ 1, 2 ],
'_fields%5B0%5D=content': [ 1, 2 ],
},
};

Expand Down Expand Up @@ -133,7 +133,7 @@ describe( 'getQueriedItems', () => {
2: true,
},
queries: {
'': [ 1, 2 ],
'_fields%5B0%5D=content&_fields%5B0%5D=meta.template': [ 1, 2 ],
},
};

Expand Down
18 changes: 15 additions & 3 deletions packages/core-data/src/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* External dependencies
*/
import createSelector from 'rememo';
import { first, map, find, get, filter, compact, defaultTo } from 'lodash';
import { set, map, find, get, filter, compact, defaultTo } from 'lodash';

/**
* WordPress dependencies
Expand All @@ -16,6 +16,7 @@ import deprecated from '@wordpress/deprecated';
import { REDUCER_KEY } from './name';
import { getQueriedItems } from './queried-data';
import { DEFAULT_ENTITY_KEY } from './entities';
import { getNormalizedCommaSeparable } from './utils';

/**
* Returns true if a request is in progress for embed preview data, or false
Expand Down Expand Up @@ -135,8 +136,19 @@ export function getEntityRecord( state, kind, name, key, query ) {
return queriedState.items[ key ];
}

query = { ...query, include: [ key ] };
return first( getQueriedItems( queriedState, query ) );
const item = queriedState.items[ key ];
if ( item && query._fields ) {
const filteredItem = {};
const fields = getNormalizedCommaSeparable( query._fields );
for ( let f = 0; f < fields.length; f++ ) {
const field = fields[ f ].split( '.' );
const value = get( item, field );
set( filteredItem, field, value );
}
return filteredItem;
}

return item;
}

/**
Expand Down
37 changes: 22 additions & 15 deletions packages/e2e-tests/specs/editor/plugins/custom-post-types.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ const openPageAttributesPanel = async () => {
await openButton.click();
}
};
const SELECT_OPTION_SELECTOR =
'.editor-page-attributes__parent option:nth-child(2)';

describe( 'Test Custom Post Types', () => {
beforeAll( async () => {
Expand All @@ -35,6 +33,11 @@ describe( 'Test Custom Post Types', () => {
} );

it( 'It should be able to create an hierarchical post without title support', async () => {
const PARENT_PAGE_INPUT =
'.editor-page-attributes__parent input:not([disabled])';
const SUGGESTION =
'.editor-page-attributes__parent .components-form-token-field__suggestion:first-child';

// Create a parent post.
await createNewPost( { postType: 'hierar-no-title' } );
await page.click( '.block-editor-writing-flow' );
Expand All @@ -43,25 +46,29 @@ describe( 'Test Custom Post Types', () => {
// Create a post that is a child of the previously created post.
await createNewPost( { postType: 'hierar-no-title' } );
await openPageAttributesPanel();
await page.waitForSelector( SELECT_OPTION_SELECTOR );
const optionToSelect = await page.$( SELECT_OPTION_SELECTOR );
const valueToSelect = await (
await optionToSelect.getProperty( 'value' )
).jsonValue();
await page.select(
'.editor-page-attributes__parent select',
valueToSelect
await page.waitForSelector( PARENT_PAGE_INPUT );
await page.click( PARENT_PAGE_INPUT );
await page.waitForSelector( SUGGESTION );
const optionToSelect = await page.$( SUGGESTION );
const valueToSelect = await page.$eval(
SUGGESTION,
( element ) => element.textContent
);
await optionToSelect.click();
await page.click( '.block-editor-writing-flow' );
await page.keyboard.type( 'Child Post' );
await publishPost();
// Reload the child post and verify it is still correctly selected as a child post.
await page.reload();
await page.waitForSelector( SELECT_OPTION_SELECTOR );
const selectedValue = await page.$eval(
'.editor-page-attributes__parent select',
( el ) => el.value
await page.waitForSelector( PARENT_PAGE_INPUT );
// Wait for the list of suggestions to fetch
// There should be a better way to do that.
// eslint-disable-next-line no-restricted-syntax
await page.waitFor(
( [ value, inputSelector ] ) =>
document.querySelector( inputSelector ).value === value,
{},
[ valueToSelect, PARENT_PAGE_INPUT ]
);
expect( selectedValue ).toEqual( valueToSelect );
} );
} );
Loading