From f7ed4a5cc2f94a2c605f744f36f05b1241cbe376 Mon Sep 17 00:00:00 2001 From: Botho <1258870+elbotho@users.noreply.github.com> Date: Mon, 15 Apr 2024 17:02:07 +0200 Subject: [PATCH] fix: breadcrumbs for all uppermost taxonomies --- apps/web/src/fetcher/create-breadcrumbs.tsx | 10 ++++++---- apps/web/src/fetcher/create-secondary-menu.tsx | 6 +++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/apps/web/src/fetcher/create-breadcrumbs.tsx b/apps/web/src/fetcher/create-breadcrumbs.tsx index ae6c06c170..7d077d2512 100644 --- a/apps/web/src/fetcher/create-breadcrumbs.tsx +++ b/apps/web/src/fetcher/create-breadcrumbs.tsx @@ -44,6 +44,8 @@ export function taxonomyParentsToRootToBreadcrumbsData( const { secondaryMenus } = getInstanceDataByLang(instance) + if (!term.path) return undefined + let breadcrumbs = term.path.map((entry) => { return { label: entry!.title, @@ -52,9 +54,7 @@ export function taxonomyParentsToRootToBreadcrumbsData( } }) - if (!breadcrumbs?.length) return undefined - - if (includeFirstParent) { + if (includeFirstParent || !term.path.length) { breadcrumbs.push({ label: term.title, url: term.alias, @@ -62,9 +62,11 @@ export function taxonomyParentsToRootToBreadcrumbsData( }) } + if (!breadcrumbs?.length) return undefined + // get the subject from the secondary menu data so we link to the correct landing pages const subject = secondaryMenus.find( - (menu) => menu.rootId === breadcrumbs[0].id + (menu) => menu.rootId === breadcrumbs[0]?.id ?? term.id ) if (subject) { diff --git a/apps/web/src/fetcher/create-secondary-menu.tsx b/apps/web/src/fetcher/create-secondary-menu.tsx index 782d70dc74..08edb9500d 100644 --- a/apps/web/src/fetcher/create-secondary-menu.tsx +++ b/apps/web/src/fetcher/create-secondary-menu.tsx @@ -29,7 +29,11 @@ export function createSecondaryMenu( if (uuid.__typename === UuidType.TaxonomyTerm) { if (uuid.type === TaxonomyTermType.ExerciseFolder) return undefined - const breadcrumbs = taxonomyParentsToRootToBreadcrumbsData(uuid, instance) + const breadcrumbs = taxonomyParentsToRootToBreadcrumbsData( + uuid, + instance, + true + ) if (!breadcrumbs) return undefined