Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow to have top level alias for platforms #13069

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion docs/platforms/javascript/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
title: JavaScript
title: Browser JavaScript
platformTitle: JavaScript
caseStyle: camelCase
supportLevel: production
sdk: 'sentry.javascript.browser'
Expand Down
18 changes: 12 additions & 6 deletions src/components/breadcrumbs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,26 @@ type BreadcrumbsProps = {
};

export function Breadcrumbs({leafNode}: BreadcrumbsProps) {
const nodes: DocNode[] = [];
const breadcrumbs: {title: string; to: string}[] = [];

for (let node: DocNode | undefined = leafNode; node; node = node.parent) {
if (node && !node.missing) {
nodes.unshift(node);
const to = node.path === '/' ? node.path : `/${node.path}/`;
const title = node.frontmatter.platformTitle ?? node.frontmatter.title;

breadcrumbs.unshift({
to,
title,
});
}
}

return (
<ul className="list-none flex p-0 flex-wrap" style={{margin: 0}}>
{nodes.map(n => {
const to = n.path === '/' ? n.path : `/${n.path}/`;
{breadcrumbs.map(b => {
return (
<li className={styles['breadcrumb-item']} key={n.path}>
<SmartLink to={to}>{n.frontmatter.title}</SmartLink>
<li className={styles['breadcrumb-item']} key={b.to}>
<SmartLink to={b.to}>{b.title}</SmartLink>
</li>
);
})}
Expand Down
11 changes: 9 additions & 2 deletions src/components/platformFilter/client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export function PlatformFilterClient({platforms}: {platforms: Platform[]}) {
return platformsAndGuides;
}
// any of these fields can be used to match the search value
const keys = ['title', 'aliases', 'name', 'sdk', 'keywords'];
const keys = ['title', 'aliases', 'name', 'sdk', 'keywords', 'platformTitle'];
const matches_ = matchSorter(platformsAndGuides, filter, {
keys,
threshold: rankings.CONTAINS,
Expand Down Expand Up @@ -195,7 +195,14 @@ function PlatformWithGuides({

const guides = useMemo(() => {
const showPlatformInContent = matchKeys.includes(platform.key);
return showPlatformInContent ? [platform, ...platform.guides] : platform.guides;

// This is the case if `platformTitle` is configured for a platform
// In this case, we do not need to add the platform to the list of guides
const hasGuideWithPlatformKey = platform.guides.some(g => g.key === platform.key);

return showPlatformInContent && !hasGuideWithPlatformKey
? [platform, ...platform.guides]
: platform.guides;
}, [matchKeys, platform]);

return (
Expand Down
11 changes: 9 additions & 2 deletions src/components/platformSelector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ export function PlatformSelector({

const router = useRouter();
const onPlatformChange = (platformKey: string) => {
const platform_ = platformsAndGuides.find(platform => platform.key === platformKey);
const platform_ = platformsAndGuides.find(
platform => platform.key === platformKey.replace('-redirect', '')
);
if (platform_) {
localStorage.setItem('active-platform', platform_.key);
router.push(platform_.url);
Expand Down Expand Up @@ -277,6 +279,11 @@ function PlatformItem({
isLastGuide: i === guides.length - 1,
}));

// This is the case if `platformTitle` is configured for a platform
// In this case, the top-level select item should get the `-redirect` suffix,
// as we can't have two items with the same key
const hasGuideWithPlatformKey = platform.guides.some(g => g.key === platform.key);

const guides = platform.isExpanded
? markLastGuide(platform.guides.length > 0 ? platform.guides : platform.integrations)
: [];
Expand All @@ -288,7 +295,7 @@ function PlatformItem({
<RadixSelect.Label className="flex">
<Fragment>
<RadixSelect.Item
value={platform.key}
value={hasGuideWithPlatformKey ? `${platform.key}-redirect` : platform.key}
asChild
className={styles.item}
data-platform-with-guides
Expand Down
15 changes: 13 additions & 2 deletions src/docTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ function nodeToPlatform(n: DocNode): Platform {
name: n.slug,
type: 'platform',
url: '/' + n.path + '/',
title: n.frontmatter.title,
title: n.frontmatter.platformTitle ?? n.frontmatter.title,
caseStyle,
sdk: n.frontmatter.sdk,
fallbackPlatform: n.frontmatter.fallbackPlatform,
Expand Down Expand Up @@ -369,9 +369,20 @@ function extractGuides(platformNode: DocNode): PlatformGuide[] {
if (!guidesNode) {
return [];
}
return guidesNode.children

// If a `platformTitle` is defined, we add a virtual guide
const defaultGuide = platformNode.frontmatter.platformTitle
? {
...nodeToGuide(platformNode.slug, platformNode),
key: platformNode.slug,
}
: undefined;

const childGuides = guidesNode.children
.filter(({path}) => !isVersioned(path))
.map(n => nodeToGuide(platformNode.slug, n));

return defaultGuide ? [defaultGuide, ...childGuides] : childGuides;
}

const extractIntegrations = (p: DocNode): PlatformIntegration[] => {
Expand Down
7 changes: 6 additions & 1 deletion src/types/platform.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ export interface PlatformConfig {
* Keywords used for search etc.
*/
keywords?: string[];
/**
* The title of the platform as it should be displayed in the sidebar.
* In most cases, you do not need to define this, as the title is used.
* However, in some cases - e.g. JavaScript - the Platform title (JavaScript) is different from the default guide (Browser JavaScript).
*/
platformTitle?: string;
/**
* Used to map a platform to a specific SDK as defined by the SDK registry.
*/
Expand All @@ -130,7 +136,6 @@ export interface PlatformConfig {
* Is this a first-party or third-party SDK?
*/
supportLevel?: PlatformSupportLevel;

/**
* The human readable name of the platform.
*/
Expand Down
Loading