Skip to content

Commit

Permalink
Add selectors for retrieving a single menu
Browse files Browse the repository at this point in the history
  • Loading branch information
getdave committed May 23, 2023
1 parent c5e6d39 commit 68db735
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
4 changes: 4 additions & 0 deletions docs/reference-guides/data/data-core.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions packages/core-data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 7 additions & 1 deletion packages/core-data/src/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
} );
Expand Down
13 changes: 13 additions & 0 deletions packages/core-data/src/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down

0 comments on commit 68db735

Please sign in to comment.