Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/components/Navigation.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, TextContentEntry[]> = {};
const uniqueSections = new Set(navDataRaw.map((entry) => entry.data.section as string));

const [orderedSections, unorderedSections] = Array.from(uniqueSections).reduce(
(acc, section) => {
Expand All @@ -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))
Expand Down Expand Up @@ -68,7 +67,7 @@ sortedSections.map((section) => {
return a.data.id.localeCompare(b.data.id)
})

navData[section] = sortedUniqueEntries;
return sortedUniqueEntries
})

---
Expand Down
22 changes: 12 additions & 10 deletions src/components/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, TextContentEntry[]>
navData: TextContentEntry[][]
}

export const Navigation: React.FunctionComponent<NavigationProps> = ({
Expand All @@ -29,14 +28,17 @@ export const Navigation: React.FunctionComponent<NavigationProps> = ({
<PageSidebarBody id="page-sidebar-body">
<Nav onSelect={onNavSelect}>
<NavList>
{Object.entries(navData).map(([key, value], index) => (
<NavSection
key={index}
entries={value}
sectionId={key}
activeItem={activeItem}
/>
))}
{navData.map((navEntries) => {
const { section } = navEntries[0].data
return (
<NavSection
key={section}
entries={navEntries}
sectionId={section}
activeItem={activeItem}
/>
)
})}
</NavList>
</Nav>
</PageSidebarBody>
Expand Down
10 changes: 5 additions & 5 deletions src/components/__tests__/Navigation.test.tsx
Original file line number Diff line number Diff line change
@@ -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<string, TextContentEntry[]> = {
'section one': [
const mockEntries: TextContentEntry[][] = [
[
{
id: 'entry1',
data: { id: 'Entry1', section: 'section-one' },
Expand All @@ -26,7 +26,7 @@ const mockEntries: Record<string, TextContentEntry[]> = {
data: { id: 'Entry5', section: 'section-one' },
},
],
'section two': [
[
{
id: 'entry6',
data: { id: 'Entry6', section: 'section-two' },
Expand All @@ -40,7 +40,7 @@ const mockEntries: Record<string, TextContentEntry[]> = {
data: { id: 'Entry8', section: 'section-two' },
},
],
}
]

it('renders without crashing', () => {
render(<Navigation navData={mockEntries} />)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ exports[`matches snapshot 1`] = `
<button
aria-expanded="true"
class="pf-v6-c-nav__link"
id="nav-section-section one"
id="nav-section-section-one"
>
Section one
<span
Expand All @@ -52,7 +52,7 @@ exports[`matches snapshot 1`] = `
</span>
</button>
<section
aria-labelledby="nav-section-section one"
aria-labelledby="nav-section-section-one"
class="pf-v6-c-nav__subnav"
>
<ul
Expand Down Expand Up @@ -162,7 +162,7 @@ exports[`matches snapshot 1`] = `
<button
aria-expanded="false"
class="pf-v6-c-nav__link"
id="nav-section-section two"
id="nav-section-section-two"
>
Section two
<span
Expand All @@ -188,7 +188,7 @@ exports[`matches snapshot 1`] = `
</span>
</button>
<section
aria-labelledby="nav-section-section two"
aria-labelledby="nav-section-section-two"
class="pf-v6-c-nav__subnav"
hidden=""
>
Expand Down