Skip to content

Commit 1ecd8c4

Browse files
committed
ref(platform): Update sidebar components
This was a bit tricky to follow/understand, and should hopefully be clearer now.
1 parent 949763e commit 1ecd8c4

File tree

7 files changed

+42
-82
lines changed

7 files changed

+42
-82
lines changed

src/components/sidebar/developDocsSidebar.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import {DocNode, nodeForPath} from 'sentry-docs/docTree';
22

33
import styles from './style.module.scss';
44

5-
import {DynamicNav, toTree} from '../dynamicNav';
65
import {SidebarLink} from '../sidebarLink';
76

7+
import {DynamicNav, toTree} from './dynamicNav';
88
import {NavNode} from './types';
99
import {docNodeToNavNode, getNavNodes} from './utils';
1010

11-
const devDocsMenuItems: {root: string; title: string; hideChevron?: boolean}[] = [
12-
{root: 'getting-started', title: 'Getting Started', hideChevron: true},
11+
const devDocsMenuItems: {root: string; title: string}[] = [
12+
{root: 'getting-started', title: 'Getting Started'},
1313
{root: 'engineering-practices', title: 'Engineering Practices'},
1414
{root: 'application-architecture', title: 'Application Architecture'},
1515
{root: 'development-infrastructure', title: 'Development Infrastructure'},
@@ -26,9 +26,7 @@ export function DevelopDocsSidebar({
2626
path,
2727
rootNode,
2828
sidebarToggleId,
29-
headerClassName,
3029
}: {
31-
headerClassName: string;
3230
path: string;
3331
rootNode: DocNode;
3432
sidebarToggleId: string;
@@ -47,15 +45,13 @@ export function DevelopDocsSidebar({
4745
<div className="md:flex flex-col items-stretch">
4846
<div className={styles.toc}>
4947
<ul data-sidebar-tree>
50-
{devDocsMenuItems.map(({root, title, hideChevron}) => (
48+
{devDocsMenuItems.map(({root, title}) => (
5149
<DynamicNav
5250
key={root}
5351
root={root}
5452
title={title}
5553
tree={getNavTree(root)}
56-
headerClassName={headerClassName}
57-
collapse
58-
withChevron={!hideChevron}
54+
collapsible
5955
/>
6056
))}
6157
</ul>

src/components/dynamicNav.tsx renamed to src/components/sidebar/dynamicNav.tsx

Lines changed: 30 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ import {serverContext} from 'sentry-docs/serverContext';
44
import {sortPages} from 'sentry-docs/utils';
55
import {getUnversionedPath, VERSION_INDICATOR} from 'sentry-docs/versioning';
66

7-
import {NavChevron} from './sidebar/navChevron';
8-
import {SidebarLink} from './sidebarLink';
9-
import {SmartLink} from './smartLink';
7+
import styles from './style.module.scss';
8+
9+
import {SidebarLink} from '../sidebarLink';
10+
import {SmartLink} from '../smartLink';
11+
12+
import {NavChevron} from './navChevron';
1013

1114
type Node = {
1215
[key: string]: any;
@@ -105,31 +108,19 @@ export function Children({tree, path, exclude = [], showDepth = 0}: ChildrenProp
105108
}
106109

107110
type Props = {
108-
headerClassName: string;
109111
root: string;
110112
tree: EntityTree[];
111-
collapse?: boolean;
113+
collapsible?: boolean;
112114
exclude?: string[];
113-
noHeadingLink?: boolean;
114-
prependLinks?: [string, string][];
115-
showDepth?: number;
116-
suppressMissing?: boolean;
117115
title?: string;
118-
withChevron?: boolean;
119116
};
120117

121118
export function DynamicNav({
122119
root,
123120
title,
124121
tree,
125-
collapse = false,
122+
collapsible = false,
126123
exclude = [],
127-
showDepth = 0,
128-
prependLinks = [],
129-
suppressMissing = false,
130-
noHeadingLink = false,
131-
headerClassName,
132-
withChevron = false,
133124
}: Props) {
134125
if (root.startsWith('/')) {
135126
root = root.substring(1);
@@ -141,10 +132,8 @@ export function DynamicNav({
141132
rootBits.forEach(bit => {
142133
entity = currentTree.find(n => n.name === bit);
143134
if (!entity) {
144-
if (!suppressMissing) {
145-
// eslint-disable-next-line no-console
146-
console.warn(`Could not find entity at ${root} (specifically at ${bit})`);
147-
}
135+
// eslint-disable-next-line no-console
136+
console.warn(`Could not find entity at ${root} (specifically at ${bit})`);
148137
return;
149138
}
150139
currentTree = entity.children;
@@ -155,44 +144,39 @@ export function DynamicNav({
155144
if (!title && entity.node) {
156145
title = entity.node.context.sidebar_title || entity.node.context.title || '';
157146
}
158-
const parentNode = entity.children
159-
? entity.children.find((n: EntityTree) => n.name === '')
160-
: null;
147+
const parentNode = entity.children?.find((n: EntityTree) => n.name === '');
148+
149+
if (!parentNode) {
150+
// eslint-disable-next-line no-console
151+
console.warn(`Could not find parentNode at ${root}`);
152+
return null;
153+
}
161154

162155
const {path} = serverContext();
163156
const isActive = path.join('/').indexOf(root) === 0;
164157
const linkPath = `/${path.join('/')}/`;
165158

166-
const header =
167-
parentNode && !noHeadingLink ? (
168-
<SmartLink
169-
to={`/${root}/`}
170-
className={`${headerClassName} ${getUnversionedPath(path, false) === root ? 'active' : ''} justify-between`}
171-
activeClassName="active"
172-
data-sidebar-link
173-
>
174-
<strong>{title}</strong>
175-
{withChevron && <NavChevron direction={isActive ? 'down' : 'right'} />}
176-
</SmartLink>
177-
) : (
178-
<div className={headerClassName} data-sidebar-link>
179-
<strong>{title}</strong>
180-
</div>
181-
);
159+
const header = (
160+
<SmartLink
161+
to={`/${root}/`}
162+
className={`${styles['sidebar-title']} flex items-center ${getUnversionedPath(path, false) === root ? 'active' : ''} justify-between`}
163+
activeClassName="active"
164+
data-sidebar-link
165+
>
166+
<strong>{title}</strong>
167+
{collapsible && <NavChevron direction={isActive ? 'down' : 'right'} />}
168+
</SmartLink>
169+
);
182170

183171
return (
184172
<li className="mb-3" data-sidebar-branch>
185173
{header}
186-
{(!collapse || isActive) && entity.children && (
174+
{(!collapsible || isActive) && entity.children && (
187175
<ul data-sidebar-tree className="pl-3">
188-
{prependLinks &&
189-
prependLinks.map(link => (
190-
<SidebarLink to={link[0]} key={link[0]} title={link[1]} path={linkPath} />
191-
))}
192176
<Children
193177
tree={entity.children}
194178
exclude={exclude}
195-
showDepth={showDepth}
179+
showDepth={0}
196180
path={linkPath}
197181
/>
198182
</ul>

src/components/sidebar/index.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {SidebarLinks} from './sidebarLinks';
1919
import {SidebarProps} from './types';
2020

2121
const activeLinkSelector = `.${styles.sidebar} .toc-item .active`;
22-
const headerClassName = `${styles['sidebar-title']} flex items-center`;
2322

2423
export const sidebarToggleId = styles['navbar-menu-toggle'];
2524

@@ -29,7 +28,6 @@ export async function Sidebar({path, versions}: SidebarProps) {
2928
if (isDeveloperDocs) {
3029
return (
3130
<DevelopDocsSidebar
32-
headerClassName={headerClassName}
3331
sidebarToggleId={sidebarToggleId}
3432
path={'/' + path.join('/') + '/'}
3533
rootNode={rootNode}
@@ -102,7 +100,7 @@ export async function Sidebar({path, versions}: SidebarProps) {
102100
</div>
103101
<div className={styles.toc}>
104102
<ScrollActiveLink activeLinkSelector={activeLinkSelector} />
105-
<SidebarLinks path={path} headerClassName={headerClassName} />
103+
<SidebarLinks path={path} />
106104
</div>
107105
</div>
108106
</aside>

src/components/sidebar/platformSidebar.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import {DocNode, getGuide, getPlatform, nodeForPath} from 'sentry-docs/docTree';
22

3-
import {DynamicNav, toTree} from '../dynamicNav';
4-
3+
import {DynamicNav, toTree} from './dynamicNav';
54
import {PlatformSidebarProps} from './types';
65
import {getNavNodes} from './utils';
76

87
export function PlatformSidebar({
98
rootNode,
109
platformName,
1110
guideName,
12-
headerClassName,
1311
}: PlatformSidebarProps) {
1412
const docNodeToPlatformSidebarNode = (n: DocNode) => {
1513
if (n.frontmatter.draft) {
@@ -52,7 +50,6 @@ export function PlatformSidebar({
5250
tree={tree}
5351
title={`Sentry for ${(guide || platform).title}`}
5452
exclude={[`/${pathRoot}/guides/`]}
55-
headerClassName={headerClassName}
5653
/>
5754
</ul>
5855
);

src/components/sidebar/productSidebar.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import {nodeForPath} from 'sentry-docs/docTree';
22

3-
import {DynamicNav, toTree} from '../dynamicNav';
43
import {SidebarLink} from '../sidebarLink';
54

5+
import {DynamicNav, toTree} from './dynamicNav';
66
import {NavNode, ProductSidebarProps} from './types';
77
import {docNodeToNavNode, getNavNodes} from './utils';
88

9-
export function ProductSidebar({rootNode, items, headerClassName}: ProductSidebarProps) {
9+
export function ProductSidebar({rootNode, items}: ProductSidebarProps) {
1010
const itemTree = (item: string) => {
1111
const node = nodeForPath(rootNode, item);
1212
if (!node) {
@@ -28,9 +28,7 @@ export function ProductSidebar({rootNode, items, headerClassName}: ProductSideba
2828
root={item.root}
2929
title={item.title}
3030
tree={tree}
31-
headerClassName={headerClassName}
32-
collapse
33-
withChevron
31+
collapsible
3432
/>
3533
)
3634
);

src/components/sidebar/sidebarLinks.tsx

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ import {Fragment} from 'react';
22

33
import {getDocsRootNode, nodeForPath} from 'sentry-docs/docTree';
44

5-
import {DynamicNav, toTree} from '../dynamicNav';
6-
75
import {DefaultSidebar} from './defaultSidebar';
6+
import {DynamicNav, toTree} from './dynamicNav';
87
import {PlatformSidebar} from './platformSidebar';
98
import {ProductSidebar} from './productSidebar';
109
import {NavNode} from './types';
@@ -47,13 +46,7 @@ const productSidebarItems = [
4746
},
4847
];
4948

50-
export async function SidebarLinks({
51-
path,
52-
headerClassName,
53-
}: {
54-
headerClassName: string;
55-
path: string[];
56-
}) {
49+
export async function SidebarLinks({path}: {path: string[]}) {
5750
const rootNode = await getDocsRootNode();
5851
if (
5952
productSidebarItems.some(el => el.root === path[0]) ||
@@ -63,7 +56,6 @@ export async function SidebarLinks({
6356
<ProductSidebar
6457
rootNode={rootNode}
6558
items={productSidebarItems}
66-
headerClassName={headerClassName}
6759
/>
6860
);
6961
}
@@ -79,15 +71,13 @@ export async function SidebarLinks({
7971
platformName={platformName}
8072
guideName={guideName}
8173
rootNode={rootNode}
82-
headerClassName={headerClassName}
8374
/>
8475
<hr />
8576
</Fragment>
8677
)}
8778
<ProductSidebar
8879
rootNode={rootNode}
8980
items={productSidebarItems}
90-
headerClassName={headerClassName}
9181
/>
9282
</Fragment>
9383
);
@@ -102,7 +92,6 @@ export async function SidebarLinks({
10292
root="contributing"
10393
title="Contributing to Docs"
10494
tree={toTree(contribNodes)}
105-
headerClassName={headerClassName}
10695
/>
10796
</ul>
10897
);

src/components/sidebar/types.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@ export type DefaultSidebarProps = SidebarProps & {
1818
};
1919

2020
export type ProductSidebarProps = {
21-
headerClassName: string;
2221
items: {root: string; title: string}[];
2322
rootNode: DocNode;
2423
};
2524

2625
export type PlatformSidebarProps = {
27-
headerClassName: string;
2826
platformName: string;
2927
rootNode: DocNode;
3028
guideName?: string;

0 commit comments

Comments
 (0)