Skip to content

Commit

Permalink
Handle edge case where menu is not defined. (#804)
Browse files Browse the repository at this point in the history
  • Loading branch information
timcosgrove authored Nov 5, 2024
1 parent 59729e8 commit e658209
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
11 changes: 7 additions & 4 deletions src/data/queries/pressReleaseListing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,13 @@ export const data: QueryData<
)

// Fetch the menu name dynamically off of the field_office reference
const menu = await getMenu(
entity.field_office.field_system_menu.resourceIdObjMeta
.drupal_internal__target_id
)
let menu = null
if (entity.field_office.field_system_menu) {
menu = await getMenu(
entity.field_office.field_system_menu.resourceIdObjMeta
?.drupal_internal__target_id
)
}

return {
entity,
Expand Down
12 changes: 7 additions & 5 deletions src/data/queries/storyListing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,14 @@ export const data: QueryData<ListingPageDataOpts, StoryListingData> = async (
listingParams(entity.id),
PAGE_SIZE
)

// Fetch the menu name dynamically off of the field_office reference
const menu = await getMenu(
entity.field_office.field_system_menu.resourceIdObjMeta
.drupal_internal__target_id
)
let menu = null
if (entity.field_office.field_system_menu) {
menu = await getMenu(
entity.field_office.field_system_menu.resourceIdObjMeta
?.drupal_internal__target_id
)
}

return {
entity,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/drupal/facilitySideNav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const normalizeMenuItem = (item: MenuItem): SideNavItem => {

const normalizeMenuData = (menu: Menu): SideNavData => {
// Bail early if no tree is provided
if (!menu.tree || menu.tree.length === 0) return null
if (!menu || !menu.tree || menu.tree.length === 0) return null

const links = []
menu.tree.forEach((item) => {
Expand Down

0 comments on commit e658209

Please sign in to comment.