Skip to content

Commit 6e9813b

Browse files
authored
feat: Add PlatformOrGuideName and PlatformSdkPackageName components (#9200)
1 parent 89fc020 commit 6e9813b

File tree

4 files changed

+72
-3
lines changed

4 files changed

+72
-3
lines changed

docs/platforms/javascript/common/profiling/index.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ Note that since the profiling API is currently only exposed in Chromium, profile
2626

2727
To get started with JavaScript browser profiling, you'll need to:
2828

29-
- Install the @sentry/browser SDK, minimum version 7.60.0
29+
- Install the <PlatformSdkPackageName fallback="@sentry/browser"/> SDK, minimum version 7.60.0
3030
- Configure the document response header to include `Document-Policy: js-profiling`
3131
- Configure the SDK to use the `BrowserProfilingIntegration` and set `profilesSampleRate`
3232

33-
## Step 1: Install the JavaScript Browser SDK
33+
## Step 1: Install the <PlatformOrGuideName/> SDK
3434

3535
<PlatformSection notSupported={["javascript.electron"]}>
3636

37-
Install our JavaScript browser SDK using either `yarn` or `npm`, the minimum version that supports profiling is **7.60.0**.
37+
Install our <PlatformOrGuideName/> SDK using either `yarn` or `npm`, the minimum version that supports profiling is **7.60.0**.
3838

3939
</PlatformSection>
4040

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import {getCurrentPlatformOrGuide} from 'sentry-docs/docTree';
2+
import {serverContext} from 'sentry-docs/serverContext';
3+
4+
type PlatformOrGuideNameProps = {
5+
/**
6+
* The fallback value to display if the platform or guide name is not found.
7+
* @default 'Sentry'
8+
*/
9+
fallback?: string;
10+
};
11+
12+
/**
13+
* Displays a readable name of the currently selected platform or guide.
14+
* Example: `Next.js`.
15+
*/
16+
export function PlatformOrGuideName({fallback}: PlatformOrGuideNameProps) {
17+
const fallbackName = fallback || 'Sentry';
18+
const {rootNode, path} = serverContext();
19+
const platformOrGuide = rootNode && getCurrentPlatformOrGuide(rootNode, path);
20+
if (!platformOrGuide) {
21+
return fallbackName;
22+
}
23+
24+
return `${platformOrGuide.title || fallbackName} `;
25+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import getPackageRegistry from 'sentry-docs/build/packageRegistry';
2+
import {getCurrentPlatformOrGuide} from 'sentry-docs/docTree';
3+
import {serverContext} from 'sentry-docs/serverContext';
4+
5+
type PlatformSdkPackageNameProps = {
6+
/**
7+
* The fallback value to display if the SDK package name is not found.
8+
* @default 'Sentry'
9+
*/
10+
fallback?: string;
11+
};
12+
13+
/**
14+
* Displays the SDK package name for the current platform or guide.
15+
* Example: `@sentry/react`
16+
*/
17+
export async function PlatformSdkPackageName({fallback}: PlatformSdkPackageNameProps) {
18+
const fallbackName = fallback || 'Sentry';
19+
const {rootNode, path} = serverContext();
20+
const platformOrGuide = rootNode && getCurrentPlatformOrGuide(rootNode, path);
21+
if (!platformOrGuide) {
22+
return <code>{fallbackName} </code>;
23+
}
24+
25+
const packageRegistry = await getPackageRegistry();
26+
const allSdks = packageRegistry.data;
27+
const entries = Object.entries(allSdks || {});
28+
const pair: any = entries.find(([sdkName]) => sdkName === platformOrGuide.sdk);
29+
if (!pair) {
30+
return <code>{fallbackName} </code>;
31+
}
32+
const [, sdkData] = pair;
33+
if (!sdkData) {
34+
return <code>{fallbackName} </code>;
35+
}
36+
37+
const prettifiedName = sdkData.canonical.replace(/^npm:/, '');
38+
39+
return <code>{prettifiedName || fallbackName} </code>;
40+
}

src/mdxComponents.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import {PlatformGrid} from './components/platformGrid';
2020
import {PlatformIdentifier} from './components/platformIdentifier';
2121
import {PlatformLink} from './components/platformLink';
2222
import {PlatformLinkWithLogo} from './components/platformLinkWithLogo';
23+
import {PlatformOrGuideName} from './components/platformOrGuideName';
24+
import {PlatformSdkPackageName} from './components/platformSdkPackageName';
2325
import {PlatformSection} from './components/platformSection';
2426
import {RelayMetrics} from './components/relayMetrics';
2527
import {SandboxLink} from './components/sandboxLink';
@@ -55,6 +57,8 @@ export function mdxComponents(
5557
PlatformLink,
5658
PlatformLinkWithLogo,
5759
PlatformSection,
60+
PlatformOrGuideName,
61+
PlatformSdkPackageName,
5862
RelayMetrics,
5963
SandboxLink,
6064
SignInNote,

0 commit comments

Comments
 (0)