diff --git a/src/components/Navigation.astro b/src/components/Navigation.astro index 4b8e6a1..82ca35c 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, sortValue: entry.data.sortValue }} as TextContentEntry)) @@ -68,7 +67,7 @@ sortedSections.map((section) => { return a.data.id.localeCompare(b.data.id) }) - navData[section] = sortedUniqueEntries; + return sortedUniqueEntries }) --- diff --git a/src/components/Navigation.tsx b/src/components/Navigation.tsx index 4218eec..b2e6a9c 100644 --- a/src/components/Navigation.tsx +++ b/src/components/Navigation.tsx @@ -2,9 +2,8 @@ import { useEffect, useState } from 'react' import { Nav, NavList, PageSidebarBody } from '@patternfly/react-core' import { NavSection } from './NavSection' import { type TextContentEntry } from './NavEntry' - interface NavigationProps { - navData: Record + navData: TextContentEntry[][] } export const Navigation: React.FunctionComponent = ({ @@ -29,14 +28,17 @@ export const Navigation: React.FunctionComponent = ({ diff --git a/src/components/__tests__/Navigation.test.tsx b/src/components/__tests__/Navigation.test.tsx index 05ea5bb..24d597d 100644 --- a/src/components/__tests__/Navigation.test.tsx +++ b/src/components/__tests__/Navigation.test.tsx @@ -1,10 +1,10 @@ import { render, screen } from '@testing-library/react' import userEvent from '@testing-library/user-event' import { Navigation } from '../Navigation' -import { TextContentEntry } from '../NavEntry' +import { type TextContentEntry } from '../NavEntry' -const mockEntries: Record = { - 'section one': [ +const mockEntries: TextContentEntry[][] = [ + [ { id: 'entry1', data: { id: 'Entry1', section: 'section-one' }, @@ -26,7 +26,7 @@ const mockEntries: Record = { data: { id: 'Entry5', section: 'section-one' }, }, ], - 'section two': [ + [ { id: 'entry6', data: { id: 'Entry6', section: 'section-two' }, @@ -40,7 +40,7 @@ const mockEntries: Record = { data: { id: 'Entry8', section: 'section-two' }, }, ], -} +] it('renders without crashing', () => { render() diff --git a/src/components/__tests__/__snapshots__/Navigation.test.tsx.snap b/src/components/__tests__/__snapshots__/Navigation.test.tsx.snap index 12e78ed..6dae245 100644 --- a/src/components/__tests__/__snapshots__/Navigation.test.tsx.snap +++ b/src/components/__tests__/__snapshots__/Navigation.test.tsx.snap @@ -26,7 +26,7 @@ exports[`matches snapshot 1`] = `