From 68db735cc32e9bab956f0a214478224989a3792a Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Tue, 23 May 2023 12:42:13 +0100 Subject: [PATCH] Add selectors for retrieving a single menu --- docs/reference-guides/data/data-core.md | 4 ++++ packages/core-data/README.md | 4 ++++ packages/core-data/src/resolvers.js | 8 +++++++- packages/core-data/src/selectors.ts | 13 +++++++++++++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/docs/reference-guides/data/data-core.md b/docs/reference-guides/data/data-core.md index 2c92e1b0e641ec..e3b0a9ea5c00bd 100644 --- a/docs/reference-guides/data/data-core.md +++ b/docs/reference-guides/data/data-core.md @@ -341,6 +341,10 @@ _Returns_ - `EntityRecordKey | undefined`: The ID for the fallback Navigation post. +### getNavigationMenu + +Undocumented declaration. + ### getNavigationMenuBySlug Returns a Navigation Menu object by slug. diff --git a/packages/core-data/README.md b/packages/core-data/README.md index a1506396aa1c51..5b36c892671f88 100644 --- a/packages/core-data/README.md +++ b/packages/core-data/README.md @@ -518,6 +518,10 @@ _Returns_ - `EntityRecordKey | undefined`: The ID for the fallback Navigation post. +### getNavigationMenu + +Undocumented declaration. + ### getNavigationMenuBySlug Returns a Navigation Menu object by slug. diff --git a/packages/core-data/src/resolvers.js b/packages/core-data/src/resolvers.js index bcaa01e28c7c03..11b81509c9458f 100644 --- a/packages/core-data/src/resolvers.js +++ b/packages/core-data/src/resolvers.js @@ -600,10 +600,16 @@ export const getNavigationFallbackId = } }; +export const getNavigationMenu = + ( id ) => + async ( { resolveSelect } ) => { + resolveSelect.getEntityRecord( 'postType', 'wp_navigation', id ); + }; + export const getNavigationMenuBySlug = ( slug ) => async ( { resolveSelect } ) => { - await resolveSelect.getEntityRecords( 'postType', 'wp_navigation', { + resolveSelect.getEntityRecords( 'postType', 'wp_navigation', { slug, per_page: 1, } ); diff --git a/packages/core-data/src/selectors.ts b/packages/core-data/src/selectors.ts index dd1948c97ff3ef..93ed90ebe4495c 100644 --- a/packages/core-data/src/selectors.ts +++ b/packages/core-data/src/selectors.ts @@ -1269,6 +1269,19 @@ export function getCurrentThemeGlobalStylesRevisions( return state.themeGlobalStyleRevisions[ currentGlobalStylesId ]; } +export function getNavigationMenu( + state: State, + id: EntityRecordKey +): Object | null { + const record = getEntityRecord( state, 'postType', 'wp_navigation', id ); + + if ( ! record ) { + return null; + } + + return record; +} + /** * Returns a Navigation Menu object by slug. *