Skip to content

Commit 4da6d58

Browse files
authored
reuse the sidebar sorter on pageGrid (#11531)
1 parent 7672f89 commit 4da6d58

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

src/components/pageGrid.tsx

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import Link from 'next/link';
22

3-
import {nodeForPath, sidebarOrderSorter} from 'sentry-docs/docTree';
3+
import {nodeForPath} from 'sentry-docs/docTree';
44
import {serverContext} from 'sentry-docs/serverContext';
5+
import {sortPages} from 'sentry-docs/utils';
56

67
type Props = {
78
nextPages: boolean;
@@ -25,18 +26,23 @@ export function PageGrid({header, exclude}: Props) {
2526
<nav>
2627
{header && <h2>{header}</h2>}
2728
<ul>
28-
{parentNode.children
29-
/* NOTE: temp fix while we figure out the reason why some nodes have empty front matter */
30-
.filter(c => c.frontmatter.title && !exclude?.includes(c.slug))
31-
.sort((a, b) => sidebarOrderSorter(a.frontmatter, b.frontmatter))
32-
.map(n => (
33-
<li key={n.path} style={{marginBottom: '1rem'}}>
34-
<h4 style={{marginBottom: '0px'}}>
35-
<Link href={'/' + n.path}>{n.frontmatter.title}</Link>
36-
</h4>
37-
{n.frontmatter.description && <p>{n.frontmatter.description}</p>}
38-
</li>
39-
))}
29+
{sortPages(
30+
parentNode.children.filter(
31+
c =>
32+
!c.frontmatter.sidebar_hidden &&
33+
c.frontmatter.title &&
34+
!exclude?.includes(c.slug)
35+
),
36+
// a hacky adapter to reuse the same sidebar sorter
37+
node => ({...node, context: node.frontmatter})
38+
).map(n => (
39+
<li key={n.path} style={{marginBottom: '1rem'}}>
40+
<h4 style={{marginBottom: '0px'}}>
41+
<Link href={'/' + n.path}>{n.frontmatter.title}</Link>
42+
</h4>
43+
{n.frontmatter.description && <p>{n.frontmatter.description}</p>}
44+
</li>
45+
))}
4046
</ul>
4147
</nav>
4248
);

src/docTree.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ async function getDocsRootNodeUncached(): Promise<DocNode> {
4444
);
4545
}
4646

47-
export const sidebarOrderSorter = (a: FrontMatter, b: FrontMatter) => {
47+
const sidebarOrderSorter = (a: FrontMatter, b: FrontMatter) => {
4848
const partDiff = slugWithoutIndex(a.slug).length - slugWithoutIndex(b.slug).length;
4949
if (partDiff !== 0) {
5050
return partDiff;

0 commit comments

Comments
 (0)