Skip to content

Commit ecbb897

Browse files
committed
WIP: Allow to have top level alias for platforms
1 parent 28d68bf commit ecbb897

File tree

6 files changed

+32
-11
lines changed

6 files changed

+32
-11
lines changed

docs/platforms/javascript/config.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
title: JavaScript
1+
title: Browser JavaScript
2+
topLevelAlias: JavaScript
23
caseStyle: camelCase
34
supportLevel: production
45
sdk: 'sentry.javascript.browser'

src/components/breadcrumbs/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function Breadcrumbs({leafNode}: BreadcrumbsProps) {
2222
const to = n.path === '/' ? n.path : `/${n.path}/`;
2323
return (
2424
<li className={styles['breadcrumb-item']} key={n.path}>
25-
<SmartLink to={to}>{n.frontmatter.title}</SmartLink>
25+
<SmartLink to={to}>{n.frontmatter.topLevelAlias ?? n.frontmatter.title}</SmartLink>
2626
</li>
2727
);
2828
})}

src/components/platformFilter/client.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export function PlatformFilterClient({platforms}: {platforms: Platform[]}) {
6262
return platformsAndGuides;
6363
}
6464
// any of these fields can be used to match the search value
65-
const keys = ['title', 'aliases', 'name', 'sdk', 'keywords'];
65+
const keys = ['title', 'aliases', 'name', 'sdk', 'keywords', 'topLevelAlias'];
6666
const matches_ = matchSorter(platformsAndGuides, filter, {
6767
keys,
6868
threshold: rankings.CONTAINS,
@@ -213,7 +213,7 @@ function PlatformWithGuides({
213213
format="lg"
214214
className={`${styles.PlatformIcon} !border-none !shadow-none`}
215215
/>
216-
{platform.title}
216+
{platform.topLevelAlias ?? platform.title}
217217
</div>
218218
<button className={styles.ChevronButton}>
219219
<TriangleRightIcon

src/components/platformSelector/index.tsx

+21-6
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ export function PlatformSelector({
9292

9393
const router = useRouter();
9494
const onPlatformChange = (platformKey: string) => {
95-
const platform_ = platformsAndGuides.find(platform => platform.key === platformKey);
95+
const platform_ = platformsAndGuides.find(
96+
platform => platform.key === platformKey.replace('-redirect', '')
97+
);
9698
if (platform_) {
9799
localStorage.setItem('active-platform', platform_.key);
98100
router.push(platform_.url);
@@ -277,8 +279,17 @@ function PlatformItem({
277279
isLastGuide: i === guides.length - 1,
278280
}));
279281

282+
const isPlatformWithGuidesAndTopLevelAlias =
283+
platform.guides.length > 0 && !!platform.topLevelAlias;
284+
280285
const guides = platform.isExpanded
281-
? markLastGuide(platform.guides.length > 0 ? platform.guides : platform.integrations)
286+
? markLastGuide(
287+
platform.guides.length > 0
288+
? isPlatformWithGuidesAndTopLevelAlias
289+
? [platform as unknown as PlatformGuide, ...platform.guides]
290+
: platform.guides
291+
: platform.integrations
292+
)
282293
: [];
283294

284295
return (
@@ -288,7 +299,11 @@ function PlatformItem({
288299
<RadixSelect.Label className="flex">
289300
<Fragment>
290301
<RadixSelect.Item
291-
value={platform.key}
302+
value={
303+
isPlatformWithGuidesAndTopLevelAlias
304+
? `${platform.key}-redirect`
305+
: platform.key
306+
}
292307
asChild
293308
className={styles.item}
294309
data-platform-with-guides
@@ -303,7 +318,7 @@ function PlatformItem({
303318
format="sm"
304319
className={styles['platform-icon']}
305320
/>
306-
{platform.title}
321+
{platform.topLevelAlias ?? platform.title}
307322
</span>
308323
</RadixSelect.ItemText>
309324
</ComboboxItem>
@@ -327,7 +342,7 @@ function PlatformItem({
327342
</RadixSelect.Label>
328343
</RadixSelect.Group>
329344
{guides.map(guide => {
330-
return <GuideItem key={guide.key} guide={guide} />;
345+
return <GuideItem key={guide.key + '-guide'} guide={guide} />;
331346
})}
332347
</Fragment>
333348
);
@@ -339,7 +354,7 @@ type GuideItemProps = {
339354
function GuideItem({guide}: GuideItemProps) {
340355
return (
341356
<RadixSelect.Item
342-
key={guide.key}
357+
key={guide.key + '-guide'}
343358
value={guide.key}
344359
asChild
345360
className={styles.item}

src/docTree.ts

+2
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ function nodeToPlatform(n: DocNode): Platform {
253253
const caseStyle = platformData?.case_style || n.frontmatter.caseStyle;
254254
const guides = extractGuides(n);
255255
const integrations = extractIntegrations(n);
256+
const topLevelAlias = n.frontmatter.topLevelAlias;
256257

257258
return {
258259
key: n.slug,
@@ -267,6 +268,7 @@ function nodeToPlatform(n: DocNode): Platform {
267268
keywords: n.frontmatter.keywords,
268269
guides,
269270
integrations,
271+
topLevelAlias,
270272
};
271273
}
272274

src/types/platform.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,14 @@ export interface PlatformConfig {
130130
* Is this a first-party or third-party SDK?
131131
*/
132132
supportLevel?: PlatformSupportLevel;
133-
134133
/**
135134
* The human readable name of the platform.
136135
*/
137136
title?: string;
137+
/**
138+
* Alias for the top level platform name.
139+
*/
140+
topLevelAlias?: string;
138141
}
139142

140143
/**

0 commit comments

Comments
 (0)