Skip to content

Commit

Permalink
Core Data: Fix errors when the entities list doesn't contain config k…
Browse files Browse the repository at this point in the history
…ey (#62346)


Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: tyxla <[email protected]>
Co-authored-by: Mr2P <[email protected]>
  • Loading branch information
4 people authored and ellatrix committed Jun 11, 2024
1 parent ddfc3a6 commit d9a29c8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions packages/core-data/src/queried-data/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ export function items( state = {}, action ) {
[ context ]: {
...state[ context ],
...action.items.reduce( ( accumulator, value ) => {
const itemId = value[ key ];
const itemId = value?.[ key ];

accumulator[ itemId ] = conservativeMapItem(
state?.[ context ]?.[ itemId ],
value
Expand Down Expand Up @@ -164,7 +165,7 @@ export function itemIsComplete( state = {}, action ) {
[ context ]: {
...state[ context ],
...action.items.reduce( ( result, item ) => {
const itemId = item[ key ];
const itemId = item?.[ key ];

// Defer to completeness if already assigned. Technically the
// data may be outdated if receiving items for a field subset.
Expand Down Expand Up @@ -232,7 +233,7 @@ const receiveQueries = compose( [
return {
itemIds: getMergedItemIds(
state?.itemIds || [],
action.items.map( ( item ) => item[ key ] ),
action.items.map( ( item ) => item?.[ key ] ).filter( Boolean ),
page,
perPage
),
Expand Down
2 changes: 1 addition & 1 deletion packages/core-data/src/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ function entity( entityConfig ) {
const nextState = { ...state };

for ( const record of action.items ) {
const recordId = record[ action.key ];
const recordId = record?.[ action.key ];
const edits = nextState[ recordId ];
if ( ! edits ) {
continue;
Expand Down
2 changes: 1 addition & 1 deletion packages/core-data/src/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ export const getEntityRecords =
if ( ! query?._fields && ! query.context ) {
const key = entityConfig.key || DEFAULT_ENTITY_KEY;
const resolutionsArgs = records
.filter( ( record ) => record[ key ] )
.filter( ( record ) => record?.[ key ] )
.map( ( record ) => [ kind, name, record[ key ] ] );

dispatch( {
Expand Down

0 comments on commit d9a29c8

Please sign in to comment.