-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add
PlatformOrGuideName
and PlatformSdkPackageName
components
- Loading branch information
Showing
4 changed files
with
72 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import {getCurrentPlatformOrGuide} from 'sentry-docs/docTree'; | ||
import {serverContext} from 'sentry-docs/serverContext'; | ||
|
||
type PlatformOrGuideNameProps = { | ||
/** | ||
* The fallback value to display if the platform or guide name is not found. | ||
* @default 'Sentry' | ||
*/ | ||
fallback?: string; | ||
}; | ||
|
||
/** | ||
* Displays a readable name of the currently selected platform or guide. | ||
* Example: `Next.js`. | ||
*/ | ||
export function PlatformOrGuideName({fallback}: PlatformOrGuideNameProps) { | ||
const fallbackName = fallback || 'Sentry'; | ||
const {rootNode, path} = serverContext(); | ||
const platformOrGuide = rootNode && getCurrentPlatformOrGuide(rootNode, path); | ||
if (!platformOrGuide) { | ||
return 'fallbackName '; | ||
} | ||
|
||
return `${platformOrGuide.title || fallbackName} `; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import getPackageRegistry from 'sentry-docs/build/packageRegistry'; | ||
import {getCurrentPlatformOrGuide} from 'sentry-docs/docTree'; | ||
import {serverContext} from 'sentry-docs/serverContext'; | ||
|
||
type PlatformSdkPackageNameProps = { | ||
/** | ||
* The fallback value to display if the SDK package name is not found. | ||
* @default 'Sentry' | ||
*/ | ||
fallback?: string; | ||
}; | ||
|
||
/** | ||
* Displays the SDK package name for the current platform or guide. | ||
* Example: `@sentry/react` | ||
*/ | ||
export async function PlatformSdkPackageName({fallback}: PlatformSdkPackageNameProps) { | ||
const fallbackName = fallback || 'Sentry'; | ||
const {rootNode, path} = serverContext(); | ||
const platformOrGuide = rootNode && getCurrentPlatformOrGuide(rootNode, path); | ||
if (!platformOrGuide) { | ||
return <code>{fallbackName} </code>; | ||
} | ||
|
||
const packageRegistry = await getPackageRegistry(); | ||
const allSdks = packageRegistry.data; | ||
const entries = Object.entries(allSdks || {}); | ||
const pair: any = entries.find(([sdkName]) => sdkName === platformOrGuide.sdk); | ||
if (!pair) { | ||
return <code>{fallbackName} </code>; | ||
} | ||
const [, sdkData] = pair; | ||
if (!sdkData) { | ||
return <code>{fallbackName} </code>; | ||
} | ||
|
||
const prettifiedName = sdkData.canonical.replace(/^npm:/, ''); | ||
|
||
return <code>{prettifiedName || fallbackName} </code>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters