-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat: Add APIs page for JavaScript #12605
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
Changes from 19 commits
446200f
95fff55
519e332
cbf2002
9bfdc9b
ce14272
fa967c0
d75275e
914e6d2
e3deb5e
a15c1ca
eac7de6
40cd5ef
6e52fd8
755cc35
809d651
071902d
586eb8d
b280a2e
640fcb6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. General question: will this page have a higher relevance for search? For example, when I look for "addIntegration", it would be great to have this page listed in the results somewhere near the top
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's a question for @chargome when he's back :D but it's a valid point! |
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -77,7 +77,7 @@ Sentry.withScope((scope) => { | |
| Sentry.captureException(new Error("my other error")); | ||
| ``` | ||
|
|
||
| You can access the current scope via `Sentry.getCurrentScope()`, but usually you should use `Sentry.withScope()` to interact with local scopes instead. | ||
| You can access the current scope via `Sentry.getCurrentScope()`, but in most cases you should not use this API, but instead use `withScope` to generate and access a local scope. There are no guarantees about the consistency of `getCurrentScope` across different parts of your application, as scope forking may happen under the hood at various points. | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @s1gr1d sneaked this change in here! |
||
|
|
||
| ## How Scope Data is Applied to Events | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,6 +55,7 @@ | |
|
|
||
| .callout-content { | ||
| min-width: 0; | ||
| flex-grow: 1; | ||
| } | ||
|
|
||
| .callout-info { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import {Fragment} from 'react'; | ||
| import {jsx, jsxs} from 'react/jsx-runtime'; | ||
| import {toJsxRuntime} from 'hast-util-to-jsx-runtime'; | ||
| import {Nodes} from 'hastscript/lib/create-h'; | ||
| import bash from 'refractor/lang/bash.js'; | ||
| import json from 'refractor/lang/json.js'; | ||
| import typescript from 'refractor/lang/typescript.js'; | ||
| import {refractor} from 'refractor/lib/core.js'; | ||
|
|
||
| refractor.register(bash); | ||
| refractor.register(json); | ||
| refractor.register(typescript); | ||
|
|
||
| // If a new language should be supported, add it here and register it in refractor above | ||
| export const SUPPORTED_LANGUAGES = ['bash', 'json', 'typescript']; | ||
|
|
||
| export function codeToJsx(code: string, lang = 'json') { | ||
| if (!SUPPORTED_LANGUAGES.includes(lang)) { | ||
| // eslint-disable-next-line no-console | ||
| console.error(`Unsupported language for syntax highlighting: ${lang}`); | ||
| } | ||
| return toJsxRuntime(refractor.highlight(code, lang) as Nodes, {Fragment, jsx, jsxs}); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| import {Fragment} from 'react'; | ||
|
|
||
| import {getCurrentPlatform} from 'sentry-docs/docTree'; | ||
| import {serverContext} from 'sentry-docs/serverContext'; | ||
| import {PlatformCategory} from 'sentry-docs/types'; | ||
|
|
||
| import {Expandable} from './expandable'; | ||
| import {codeToJsx} from './highlightCode'; | ||
| import {SdkDefinition} from './sdkDefinition'; | ||
| import {getPlatformHints} from './sdkOption'; | ||
|
|
||
| export interface ParameterDef { | ||
| name: string; | ||
| type: string | ObjectParameterDef; | ||
| defaultValue?: string; | ||
| description?: string; | ||
| required?: boolean; | ||
| } | ||
|
|
||
| type ObjectParameterDef = { | ||
| properties: ParameterDef[]; | ||
| name?: string; | ||
| }; | ||
|
|
||
| type Props = { | ||
| name: string; | ||
| parameters: ParameterDef[]; | ||
| signature: string; | ||
| categorySupported?: PlatformCategory[]; | ||
| children?: React.ReactNode; | ||
| language?: string; | ||
| }; | ||
|
|
||
| export function SdkApi({ | ||
mydea marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| name, | ||
| children, | ||
| signature, | ||
| parameters = [], | ||
| language, | ||
| categorySupported = [], | ||
| }: Props) { | ||
| const {rootNode, path} = serverContext(); | ||
| const platform = getCurrentPlatform(rootNode, path); | ||
| const lang = language || platform?.language || 'typescript'; | ||
|
|
||
| const {showBrowserOnly, showServerLikeOnly} = getPlatformHints(categorySupported); | ||
|
|
||
| return ( | ||
| <SdkDefinition name={name} categorySupported={categorySupported}> | ||
| {showBrowserOnly && <div className="italic text-sm">Only available on Client</div>} | ||
| {showServerLikeOnly && ( | ||
| <div className="italic text-sm">Only available on Server</div> | ||
| )} | ||
|
|
||
| <pre className="mt-2 mb-2 text-sm">{codeToJsx(signature, lang)}</pre> | ||
|
|
||
| {parameters.length ? ( | ||
| <Expandable title="Parameters"> | ||
| <div className="space-y-3"> | ||
| {parameters.map(param => ( | ||
| <ApiParameterDef key={param.name} language={lang} {...param} /> | ||
| ))} | ||
| </div> | ||
| </Expandable> | ||
| ) : null} | ||
|
|
||
| {children} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to play with the margins of the paragraphs of text that comes after the code/expandible. It needs to be closer I think. And after the text we need more whitespace.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is sadly pretty hard, because the text below "Parameters" is automatically converted to a About the space after the text: Do you really feel that is not enough? Feels pretty "spacy" to me below the text 🤔 |
||
| </SdkDefinition> | ||
| ); | ||
| } | ||
|
|
||
| function ApiParameterDef({ | ||
| name, | ||
| type, | ||
| description, | ||
| required, | ||
| language, | ||
| }: ParameterDef & {language: string}) { | ||
| return ( | ||
| <div className="space-y-1"> | ||
| <div className="font-bold m-0"> | ||
| {name} | ||
| {required ? <span className="text-red">*</span> : null} | ||
| </div> | ||
| <div className="space-y-1"> | ||
| <div className="flex"> | ||
| {typeof type === 'string' ? ( | ||
| <pre className="m-0 pt-1 pb-1 text-sm"> | ||
| <code>{codeToJsx(type, language)}</code> | ||
| </pre> | ||
| ) : ( | ||
| <pre className="m-0 pt-1 pb-1 text-sm"> | ||
| <NestedObject | ||
| name={type.name} | ||
| objProps={type.properties} | ||
| language={language} | ||
| /> | ||
| </pre> | ||
| )} | ||
| </div> | ||
|
|
||
| {description ? <p className="m-0">{description}</p> : null} | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| function NestedObject({ | ||
| name, | ||
| objProps, | ||
| language, | ||
| }: { | ||
| language: string; | ||
| objProps: ParameterDef[]; | ||
| name?: string; | ||
| }) { | ||
| // NOTE: For now, we always render the nested object in typescript | ||
|
|
||
| return ( | ||
| <div> | ||
| <div> | ||
| <code> | ||
| {name ? name : 'Object'} {'{'} | ||
| </code> | ||
| </div> | ||
|
|
||
| <div className="flex flex-col gap-2 pl-4"> | ||
| {objProps.map(prop => ( | ||
| <div key={prop.name}> | ||
| {prop.description && ( | ||
| <div> | ||
| <code>{codeToJsx(`// ${prop.description}`, 'typescript')}</code> | ||
| </div> | ||
| )} | ||
| <div> | ||
| {typeof prop.type === 'string' ? ( | ||
| <Fragment> | ||
| <code> | ||
| {prop.name} | ||
| {!prop.required ? '?' : ''}:{' '} | ||
| </code> | ||
| <code>{codeToJsx(prop.type, 'typescript')},</code> | ||
| </Fragment> | ||
| ) : ( | ||
| <NestedObject | ||
| name={`${prop.name}${!prop.required ? '?' : ''}: ${prop.type.name || 'Object'}`} | ||
| objProps={prop.type.properties} | ||
| language={language} | ||
| /> | ||
| )} | ||
| </div> | ||
| </div> | ||
| ))} | ||
| </div> | ||
| <div>{'}'}</div> | ||
| </div> | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import {PlatformCategory} from 'sentry-docs/types'; | ||
|
|
||
| import styles from './style.module.scss'; | ||
|
|
||
| import {PlatformCategorySection} from '../platformCategorySection'; | ||
|
|
||
| type Props = { | ||
| name: string; | ||
| categorySupported?: PlatformCategory[]; | ||
| children?: React.ReactNode; | ||
| }; | ||
|
|
||
| export function SdkDefinition({name, children, categorySupported = []}: Props) { | ||
| return ( | ||
| <PlatformCategorySection supported={categorySupported}> | ||
| <div className={styles['sdk-config-option']}> | ||
| <h3 id={name} aria-label={name} data-sdk-option> | ||
| <a href={`#${name}`}> | ||
| <svg | ||
| className="anchorlink before" | ||
| viewBox="0 0 24 24" | ||
| xmlns="http://www.w3.org/2000/svg" | ||
| width="16" | ||
| height="16" | ||
| > | ||
| <path | ||
| d="M9.199 13.599a5.99 5.99 0 0 0 3.949 2.345 5.987 5.987 0 0 0 5.105-1.702l2.995-2.994a5.992 5.992 0 0 0 1.695-4.285 5.976 5.976 0 0 0-1.831-4.211 5.99 5.99 0 0 0-6.431-1.242 6.003 6.003 0 0 0-1.905 1.24l-1.731 1.721a.999.999 0 1 0 1.41 1.418l1.709-1.699a3.985 3.985 0 0 1 2.761-1.123 3.975 3.975 0 0 1 2.799 1.122 3.997 3.997 0 0 1 .111 5.644l-3.005 3.006a3.982 3.982 0 0 1-3.395 1.126 3.987 3.987 0 0 1-2.632-1.563A1 1 0 0 0 9.201 13.6zm5.602-3.198a5.99 5.99 0 0 0-3.949-2.345 5.987 5.987 0 0 0-5.105 1.702l-2.995 2.994a5.992 5.992 0 0 0-1.695 4.285 5.976 5.976 0 0 0 1.831 4.211 5.99 5.99 0 0 0 6.431 1.242 6.003 6.003 0 0 0 1.905-1.24l1.723-1.723a.999.999 0 1 0-1.414-1.414L9.836 19.81a3.985 3.985 0 0 1-2.761 1.123 3.975 3.975 0 0 1-2.799-1.122 3.997 3.997 0 0 1-.111-5.644l3.005-3.006a3.982 3.982 0 0 1 3.395-1.126 3.987 3.987 0 0 1 2.632 1.563 1 1 0 0 0 1.602-1.198z" | ||
| fill="currentColor" | ||
| /> | ||
| </svg> | ||
| {name} | ||
| </a> | ||
| </h3> | ||
|
|
||
| <div className={styles['sdk-config-option-details']}>{children}</div> | ||
| </div> | ||
| </PlatformCategorySection> | ||
| ); | ||
| } | ||
|
|
||
| export function SdkDefinitionTable({ | ||
| children, | ||
| className, | ||
| }: { | ||
| children?: React.ReactNode; | ||
| className?: string; | ||
| }) { | ||
| return ( | ||
| <table className={styles['sdk-option-table'] + (className ? ` ${className}` : '')}> | ||
| <tbody>{children}</tbody> | ||
| </table> | ||
| ); | ||
| } |

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the styling could still be improved a bit. Something about this feels misaligned or empty (?):
Like the title of the expandable not having any separator to the content and the heading within the content being larger than the title of the expandable.
We can do that in a follow-up PR tho.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I agree this can be prettier/nicer for sure!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it's because all margins have a different width 🤔
Created a comment about this for the "examples" (but it's the same in "Parameters"): #12605 (comment)