Skip to content

Commit 49774e5

Browse files
feat: Create Token and Initialize Client pages for first mile experience (#4033)
* feat: Create Token page for first mile experience * feat: Initialize Client page for first mile experience * chore: imports * chore: prettier * fix: address PR comments * chore: prettier
1 parent b16d304 commit 49774e5

File tree

3 files changed

+116
-0
lines changed

3 files changed

+116
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Libraries
2+
import React, {FC} from 'react'
3+
import CodeSnippet from 'src/shared/components/CodeSnippet'
4+
import {Button, ComponentColor, ComponentSize} from '@influxdata/clockface'
5+
import {connect, ConnectedProps, useDispatch, useSelector} from 'react-redux'
6+
import {RouteComponentProps, withRouter} from 'react-router-dom'
7+
8+
// Selectors
9+
import {notify} from 'src/shared/actions/notifications'
10+
import {getResourcesTokensFailure} from 'src/shared/copy/notifications'
11+
import {getAllResources} from 'src/authorizations/actions/thunks'
12+
import {dismissOverlay, showOverlay} from 'src/overlays/actions/overlays'
13+
import {getOrg} from 'src/organizations/selectors'
14+
15+
// Helper Components
16+
import {SafeBlankLink} from 'src/utils/SafeBlankLink'
17+
18+
type ReduxProps = ConnectedProps<typeof connector>
19+
20+
const CreateTokenComponent: FC<ReduxProps & RouteComponentProps> = ({
21+
showOverlay,
22+
dismissOverlay,
23+
getAllResources,
24+
}) => {
25+
const org = useSelector(getOrg)
26+
const dispatch = useDispatch()
27+
const handleAllAccess = async () => {
28+
try {
29+
await getAllResources()
30+
showOverlay('add-master-token', null, dismissOverlay)
31+
} catch {
32+
dispatch(notify(getResourcesTokensFailure('all access token')))
33+
}
34+
}
35+
36+
return (
37+
<>
38+
<h1>Create a Token</h1>
39+
<p>
40+
InfluxDB Cloud uses Tokens to authenticate API access. Click below to
41+
create an all-access token.
42+
</p>
43+
<Button
44+
text="Generate Token"
45+
onClick={handleAllAccess}
46+
color={ComponentColor.Primary}
47+
size={ComponentSize.Medium}
48+
/>
49+
<p style={{marginTop: '51px'}}>
50+
Save your token as an environment variable; you’ll use it soon. Run this
51+
command in your terminal:
52+
</p>
53+
<CodeSnippet text="export INFLUXDB_TOKEN=<your token here>" />
54+
<p style={{marginTop: '46px'}}>
55+
You can create tokens in the future in the{' '}
56+
<SafeBlankLink href={`orgs/${org.id}/load-data/tokens`}>
57+
Token page
58+
</SafeBlankLink>
59+
.
60+
</p>
61+
</>
62+
)
63+
}
64+
65+
const mdtp = {
66+
showOverlay,
67+
dismissOverlay,
68+
getAllResources,
69+
}
70+
71+
const connector = connect(null, mdtp)
72+
export const CreateToken = connector(withRouter(CreateTokenComponent))
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import React from 'react'
2+
import CodeSnippet from 'src/shared/components/CodeSnippet'
3+
4+
export const InitalizeClient = () => {
5+
const pythonCode = `import os
6+
from datetime import datetime
7+
8+
from influxdb_client import InfluxDBClient, Point, WritePrecision
9+
from influxdb_client.client import SYNCHRONOUS
10+
11+
token = os.environ.get("INFLUXDB_TOKEN")
12+
org = "<user>@influxdata.com"
13+
url = "https://us-west-2-1.aws.cloud2.influxdata.com/"
14+
15+
client = influxdb_client.InfluxDBClient(url=url, token=token, org=org)
16+
write_api = client.write_api(write_options=SYNCHRONOUS)`
17+
18+
return (
19+
<>
20+
<h1>Initalize Client</h1>
21+
<p>
22+
Run this command in your terminal to open the interactive Python shell:
23+
</p>
24+
<CodeSnippet text="python3" />
25+
<p style={{marginTop: '40px'}}>
26+
Paste the following code after the prompt (>>>) and press Enter.
27+
</p>
28+
<CodeSnippet text={pythonCode} />
29+
<p style={{marginTop: '42px'}}>
30+
Here, we initialize the token, organization info, and server url that is
31+
needed to set up the initial connection to InfluxDB. The client
32+
connection is then established with InfluxDBClient initialization.
33+
</p>
34+
</>
35+
)
36+
}

src/homepageExperience/containers/HomepagePythonWizard.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import {Button, ComponentColor, ComponentSize} from '@influxdata/clockface'
66
import {InstallDependencies} from 'src/homepageExperience/components/steps/InstallDependencies'
77
import {Overview} from 'src/homepageExperience/components/steps/Overview'
88
import {Navigation} from 'src/homepageExperience/components/Navigation'
9+
import {CreateToken} from 'src/homepageExperience/components/steps/CreateToken'
10+
import {InitalizeClient} from 'src/homepageExperience/components/steps/InitalizeClient'
911

1012
import {HOMEPAGE_NAVIGATION_STEPS} from 'src/homepageExperience/utils'
1113

@@ -39,6 +41,12 @@ export class HomepagePythonWizard extends PureComponent<null, State> {
3941
case 2: {
4042
return <InstallDependencies />
4143
}
44+
case 3: {
45+
return <CreateToken />
46+
}
47+
case 4: {
48+
return <InitalizeClient />
49+
}
4250
default: {
4351
return <Overview />
4452
}

0 commit comments

Comments
 (0)