Skip to content

Commit

Permalink
feat: Show org token selector (#7385)
Browse files Browse the repository at this point in the history
  • Loading branch information
mydea committed Jul 18, 2023
1 parent 503bec3 commit 59158be
Show file tree
Hide file tree
Showing 12 changed files with 596 additions and 57 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@sentry/browser": "7.55.2",
"@sentry/webpack-plugin": "2.2.2",
"@types/dompurify": "^3.0.2",
"@types/js-cookie": "^3.0.3",
"@types/jest": "^29.5.3",
"@types/js-yaml": "^3.0.0",
"@types/node": "^20.3.1",
Expand Down Expand Up @@ -54,6 +55,7 @@
"gatsby-transformer-json": "^4.0.0",
"gatsby-transformer-remark": "^5.0.0",
"gray-matter": "^4.0.2",
"js-cookie": "^3.0.5",
"js-yaml": "^3.0.0",
"jsdom": "^22.1.0",
"platformicons": "^5.6.0",
Expand Down
2 changes: 1 addition & 1 deletion src/api/auth.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ You can create authentication tokens within Sentry by [creating an internal inte

### User authentication tokens

Some API endpoints require an authentication token that's associated with your user account, rather than an authentication token from an internal integration. These auth tokens can be created within Sentry on the "User settings" page (**User settings > Auth Tokens**) and assigned specific scopes.
Some API endpoints require an authentication token that's associated with your user account, rather than an authentication token from an internal integration. These auth tokens can be created within Sentry on the "User settings" page (**User settings > User Auth Tokens**) and assigned specific scopes.

The endpoints that require a user authentication token are specific to your user, such as [List Your Organizations](/api/organizations/list-your-organizations/).

Expand Down
250 changes: 250 additions & 0 deletions src/components/__tests__/__snapshots__/codeBlock.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`CodeWrapper renders multiple placeholders 1`] = `
<code>
process.env.MY_ENV =
<span
className="css-1rhw0e5"
onClick={[Function]}
onKeyDown={[Function]}
role="button"
tabIndex={0}
title="example-org / example-project"
>
<svg
className="css-1i93cgw"
fill="none"
height="12px"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
viewBox="0 0 24 24"
width="12px"
xmlns="http://www.w3.org/2000/svg"
>
<line
x1="12"
x2="12"
y1="5"
y2="19"
/>
<polyline
points="19 12 12 19 5 12"
/>
</svg>
<span
style={
{
"display": undefined,
}
}
>
<span
className="css-1f5vc5"
style={
{
"opacity": 1,
"position": "relative",
"transform": "none",
}
}
>
example-org
</span>
</span>
</span>
+
<span
className="css-1rhw0e5"
onClick={[Function]}
onKeyDown={[Function]}
role="button"
tabIndex={0}
title="example-org / example-project"
>
<svg
className="css-1i93cgw"
fill="none"
height="12px"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
viewBox="0 0 24 24"
width="12px"
xmlns="http://www.w3.org/2000/svg"
>
<line
x1="12"
x2="12"
y1="5"
y2="19"
/>
<polyline
points="19 12 12 19 5 12"
/>
</svg>
<span
style={
{
"display": undefined,
}
}
>
<span
className="css-1f5vc5"
style={
{
"opacity": 1,
"position": "relative",
"transform": "none",
}
}
>
example-project
</span>
</span>
</span>
</code>
`;

exports[`CodeWrapper renders org auth token placeholder when not signed in 1`] = `
<code>
process.env.MY_ENV =
sntrys_YOUR_TOKEN_HERE
</code>
`;

exports[`CodeWrapper renders org auth token placeholder when signed in 1`] = `
<code>
process.env.MY_ENV =
<span
className="css-1rhw0e5"
onClick={[Function]}
>
Click to generate token
</span>
</code>
`;

exports[`CodeWrapper renders with placeholder 1`] = `
<code>
process.env.MY_ENV =
<span
className="css-1rhw0e5"
onClick={[Function]}
onKeyDown={[Function]}
role="button"
tabIndex={0}
title="example-org / example-project"
>
<svg
className="css-1i93cgw"
fill="none"
height="12px"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
viewBox="0 0 24 24"
width="12px"
xmlns="http://www.w3.org/2000/svg"
>
<line
x1="12"
x2="12"
y1="5"
y2="19"
/>
<polyline
points="19 12 12 19 5 12"
/>
</svg>
<span
style={
{
"display": undefined,
}
}
>
<span
className="css-1f5vc5"
style={
{
"opacity": 1,
"position": "relative",
"transform": "none",
}
}
>
example-org
</span>
</span>
</span>
</code>
`;

exports[`CodeWrapper renders with placeholder in middle of text 1`] = `
<code>
process.env.MY_ENV = https://
<span
className="css-1rhw0e5"
onClick={[Function]}
onKeyDown={[Function]}
role="button"
tabIndex={0}
title="example-org / example-project"
>
<svg
className="css-1i93cgw"
fill="none"
height="12px"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
viewBox="0 0 24 24"
width="12px"
xmlns="http://www.w3.org/2000/svg"
>
<line
x1="12"
x2="12"
y1="5"
y2="19"
/>
<polyline
points="19 12 12 19 5 12"
/>
</svg>
<span
style={
{
"display": undefined,
}
}
>
<span
className="css-1f5vc5"
style={
{
"opacity": 1,
"position": "relative",
"transform": "none",
}
}
>
example-org
</span>
</span>
</span>
.sentry.io
</code>
`;

exports[`CodeWrapper renders without placeholder 1`] = `
<code>
process.env.MY_ENV = 'foo'
</code>
`;
74 changes: 74 additions & 0 deletions src/components/__tests__/codeBlock.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import React from 'react';
import {create} from 'react-test-renderer';

import {CodeWrapper} from '../codeBlock';
import {_setCachedCodeKeywords, CodeContextProvider, DEFAULTS} from '../codeContext';

describe('CodeWrapper', () => {
beforeEach(() => {
_setCachedCodeKeywords(DEFAULTS);
});

it('renders without placeholder', () => {
const tree = create(
<CodeContextProvider>
<CodeWrapper>process.env.MY_ENV = 'foo'</CodeWrapper>
</CodeContextProvider>
);

expect(tree.toJSON()).toMatchSnapshot();
});

it('renders with placeholder', () => {
const tree = create(
<CodeContextProvider>
<CodeWrapper>process.env.MY_ENV = ___ORG_SLUG___</CodeWrapper>
</CodeContextProvider>
);

expect(tree.toJSON()).toMatchSnapshot();
});

it('renders with placeholder in middle of text', () => {
const tree = create(
<CodeContextProvider>
<CodeWrapper>process.env.MY_ENV = https://___ORG_SLUG___.sentry.io</CodeWrapper>
</CodeContextProvider>
);

expect(tree.toJSON()).toMatchSnapshot();
});

it('renders org auth token placeholder when not signed in', () => {
const tree = create(
<CodeContextProvider>
<CodeWrapper>process.env.MY_ENV = ___ORG_AUTH_TOKEN___</CodeWrapper>
</CodeContextProvider>
);

expect(tree.toJSON()).toMatchSnapshot();
});
it('renders org auth token placeholder when signed in', () => {
_setCachedCodeKeywords({...DEFAULTS, USER: {ID: 123, NAME: 'test@sentry.io'}});

const tree = create(
<CodeContextProvider>
<CodeWrapper>process.env.MY_ENV = ___ORG_AUTH_TOKEN___</CodeWrapper>
</CodeContextProvider>
);

expect(tree.toJSON()).toMatchSnapshot();
});

it('renders multiple placeholders', () => {
const tree = create(
<CodeContextProvider>
<CodeWrapper>
process.env.MY_ENV = ___ORG_SLUG___ + ___PROJECT_SLUG___
</CodeWrapper>
</CodeContextProvider>
);

expect(tree.toJSON()).toMatchSnapshot();
});
});
6 changes: 2 additions & 4 deletions src/components/basePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, {Fragment, useState} from 'react';
import {getCurrentTransaction} from '../utils';

import {Banner} from './banner';
import {CodeContext, useCodeContextState} from './codeContext';
import {CodeContextProvider} from './codeContext';
import {GitHubCTA} from './githubCta';
import {Layout} from './layout';
import {SEO} from './seo';
Expand Down Expand Up @@ -77,9 +77,7 @@ export function BasePage({
>
<h1 className="mb-3">{title}</h1>
<div id="main" ref={setContentElement}>
<CodeContext.Provider value={useCodeContextState()}>
{children}
</CodeContext.Provider>
<CodeContextProvider>{children}</CodeContextProvider>

{file && (
<GitHubCTA
Expand Down
Loading

1 comment on commit 59158be

@vercel
Copy link

@vercel vercel bot commented on 59158be Jul 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

sentry-docs – ./

docs.sentry.io
sentry-docs.sentry.dev
sentry-docs-git-master.sentry.dev

Please sign in to comment.