-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Make saveEditedEntityRecord use the entity key when available #36212
Conversation
Size Change: +10 B (0%) Total Size: 1.09 MB
ℹ️ View Unchanged
|
@@ -644,12 +644,19 @@ export const saveEditedEntityRecord = ( | |||
if ( ! select.hasEditsForEntityRecord( kind, name, recordId ) ) { | |||
return; | |||
} | |||
const entities = await dispatch( getKindEntities( kind ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
something feels weird here. should this be select
or dispatch
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@youknowriad I just copied this over from saveEntityRecord
. getKindEntities
is an action, probably because it calls entities = await kindConfig.loadEntities();
later on. I wonder if it could be a selector with a resolver instead? But that's something for another PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gutenberg/packages/core-data/src/actions.js
Lines 383 to 395 in 88d2956
export const saveEntityRecord = ( | |
kind, | |
name, | |
record, | |
{ isAutosave = false, __unstableFetch = apiFetch } = {} | |
) => async ( { select, resolveSelect, dispatch } ) => { | |
const entities = await dispatch( getKindEntities( kind ) ); | |
const entity = find( entities, { kind, name } ); | |
if ( ! entity || entity?.__experimentalNoFetch ) { | |
return; | |
} | |
const entityIdKey = entity.key || DEFAULT_ENTITY_KEY; | |
const recordId = record[ entityIdKey ]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed I guess my old self is to blame for this confusion :P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code should actually be like:
const entities = await resolveSelect.getEntitiesByKind( kind );
The getEntitiesByKind
selector already exists, but it doesn't have a resolver attached. That needs to be fixed to make resolveSelect
work. Now, we need to manually dispatch the getKindEntities
action that fetches and populates the state read by getEntitiesByKind
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Description
Fixes a bug in
saveEditedEntityRecord
which right now assumes that entity key is calledid
. After the fix, it uses theentity.key
just likesaveEntityRecord
.How has this been tested?
Confirm all the tests pass.