Skip to content

Commit

Permalink
Block Bindings: Improve getRegisteredPostMeta resolver (WordPress#65450)
Browse files Browse the repository at this point in the history
* Do nothing when request fails

* Update `State.registeredPostMeta`

Co-authored-by: SantosGuillamot <santosguillamot@git.wordpress.org>
Co-authored-by: gziolo <gziolo@git.wordpress.org>
  • Loading branch information
3 people committed Sep 18, 2024
1 parent b6ba559 commit e40612b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions packages/core-data/src/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -993,20 +993,25 @@ export const getRevision =
export const getRegisteredPostMeta =
( postType ) =>
async ( { dispatch, resolveSelect } ) => {
let options;
try {
const {
rest_namespace: restNamespace = 'wp/v2',
rest_base: restBase,
} = ( await resolveSelect.getPostType( postType ) ) || {};
const options = await apiFetch( {
options = await apiFetch( {
path: `${ restNamespace }/${ restBase }/?context=edit`,
method: 'OPTIONS',
} );
} catch ( error ) {
// Do nothing if the request comes back with an API error.
return;
}

if ( options ) {
dispatch.receiveRegisteredPostMeta(
postType,
options?.schema?.properties?.meta?.properties
);
} catch {
dispatch.receiveRegisteredPostMeta( postType, false );
}
};
2 changes: 1 addition & 1 deletion packages/core-data/src/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export interface State {
navigationFallbackId: EntityRecordKey;
userPatternCategories: Array< UserPatternCategory >;
defaultTemplates: Record< string, string >;
registeredPostMeta: Record< string, { postType: string } >;
registeredPostMeta: Record< string, Object >;
}

type EntityRecordKey = string | number;
Expand Down

0 comments on commit e40612b

Please sign in to comment.