From ce75b386db704f221dd4599f37861672451e6bb8 Mon Sep 17 00:00:00 2001 From: Austin Sullivan Date: Tue, 20 May 2025 11:15:14 -0400 Subject: [PATCH 1/3] Fix(Navigation): Convert nav data from object to array of objects --- src/components/Navigation.astro | 7 +- src/components/Navigation.tsx | 14 ++-- src/components/__tests__/Navigation.test.tsx | 86 +++++++++++--------- 3 files changed, 58 insertions(+), 49 deletions(-) diff --git a/src/components/Navigation.astro b/src/components/Navigation.astro index e302cbf..d3dbc02 100644 --- a/src/components/Navigation.astro +++ b/src/components/Navigation.astro @@ -15,8 +15,7 @@ const collections = await Promise.all( ) const navDataRaw = collections.flat(); -const uniqueSections = new Set(navDataRaw.map((entry) => entry.data.section)); -const navData: Record = {}; +const uniqueSections = new Set(navDataRaw.map((entry) => entry.data.section as string)); const [orderedSections, unorderedSections] = Array.from(uniqueSections).reduce( (acc, section) => { @@ -37,7 +36,7 @@ const [orderedSections, unorderedSections] = Array.from(uniqueSections).reduce( ) const sortedSections = [...orderedSections, ...unorderedSections.sort()] -sortedSections.map((section) => { +const navData = sortedSections.map((section) => { const entries = navDataRaw .filter((entry) => entry.data.section === section) .map(entry => ({ id: entry.id, data: { id: entry.data.id, section }} as TextContentEntry)) @@ -61,7 +60,7 @@ sortedSections.map((section) => { ] } - navData[section] = navEntries; + return { section, navEntries} }) --- diff --git a/src/components/Navigation.tsx b/src/components/Navigation.tsx index 4218eec..ccb2d9a 100644 --- a/src/components/Navigation.tsx +++ b/src/components/Navigation.tsx @@ -3,8 +3,12 @@ import { Nav, NavList, PageSidebarBody } from '@patternfly/react-core' import { NavSection } from './NavSection' import { type TextContentEntry } from './NavEntry' +export interface NavData { + section: string + navEntries: TextContentEntry[] +} interface NavigationProps { - navData: Record + navData: NavData[] } export const Navigation: React.FunctionComponent = ({ @@ -29,11 +33,11 @@ export const Navigation: React.FunctionComponent = ({