From dbd10fc31b0f619adbe3ce1431ed906908eee3e8 Mon Sep 17 00:00:00 2001 From: Tu Nguyen Date: Thu, 3 Oct 2024 08:14:38 -0700 Subject: [PATCH] Add alias for docs sidebar filtering (#2581) * add alias for docs sidebar filtering * remove extra log --- .../sidebar/helpers/get-filtered-nav-items.ts | 15 +++++++++++++++ src/components/sidebar/types.ts | 1 + 2 files changed, 16 insertions(+) diff --git a/src/components/sidebar/helpers/get-filtered-nav-items.ts b/src/components/sidebar/helpers/get-filtered-nav-items.ts index ee614ffe4d..8eac67923b 100644 --- a/src/components/sidebar/helpers/get-filtered-nav-items.ts +++ b/src/components/sidebar/helpers/get-filtered-nav-items.ts @@ -40,6 +40,21 @@ export const getFilteredNavItems = ( ?.toLowerCase() .includes(filterValue.toLowerCase()) + // Check and filter alias + const hasAlias = item.hasOwnProperty('alias') + if (hasAlias) { + const doesAliasMatchFilter = ( + item as SubmenuNavItemWithMetaData | LinkNavItemWithMetaData + ).alias + ?.toLowerCase() + .includes(filterValue.toLowerCase()) + + // Add to filtered items if filter value is in alias + if (doesAliasMatchFilter) { + filteredItems.push({ ...item, matchesFilter: true }) + } + } + /** * If an item's title matches the filter, we want to include it and its * children in the filter results. `matchesFilter` is added to all items diff --git a/src/components/sidebar/types.ts b/src/components/sidebar/types.ts index f91a11563b..aa6cc17741 100644 --- a/src/components/sidebar/types.ts +++ b/src/components/sidebar/types.ts @@ -28,6 +28,7 @@ interface HeadingNavItem { interface BaseNavItem { badge?: SidebarNavMenuItemBadgeProps hidden?: boolean + alias?: string title: string }