Skip to content

Commit 1ad62fb

Browse files
authored
feat(telegrafPage): use OverlayController to open instructions overlay (#5640)
1 parent 385e75c commit 1ad62fb

File tree

7 files changed

+79
-58
lines changed

7 files changed

+79
-58
lines changed

src/overlays/components/OverlayController.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import NoteEditorOverlay from 'src/dashboards/components/NoteEditorOverlay'
1818
import AllAccessTokenOverlay from 'src/authorizations/components/AllAccessTokenOverlay'
1919
import TelegrafConfigOverlay from 'src/telegrafs/components/TelegrafConfigOverlay'
2020
import TelegrafOutputOverlay from 'src/telegrafs/components/TelegrafOutputOverlay'
21+
import TelegrafInstructionsOverlay from 'src/telegrafs/components/TelegrafInstructionsOverlay'
2122
import OrgSwitcherOverlay from 'src/pageLayout/components/OrgSwitcherOverlay'
2223
import CreateBucketOverlay from 'src/buckets/components/createBucketForm/CreateBucketOverlay'
2324
import AssetLimitOverlay from 'src/cloud/components/AssetLimitOverlay'
@@ -95,6 +96,11 @@ export const OverlayController: FunctionComponent = () => {
9596
case 'telegraf-output':
9697
activeOverlay.current = <TelegrafOutputOverlay onClose={onClose} />
9798
break
99+
case 'telegraf-instructions':
100+
activeOverlay.current = (
101+
<TelegrafInstructionsOverlay onClose={onClose} />
102+
)
103+
break
98104
case 'switch-organizations':
99105
activeOverlay.current = <OrgSwitcherOverlay onClose={onClose} />
100106
break

src/overlays/components/index.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ export const TelegrafOutputOverlay = RouteOverlay(
5252
}
5353
)
5454

55+
export const TelegrafInstructionsOverlay = RouteOverlay(
56+
OverlayHandler,
57+
'telegraf-instructions',
58+
(history, params) => {
59+
history.push(`/orgs/${params.orgID}/load-data/telegrafs`)
60+
}
61+
)
62+
5563
export const AddAnnotationDEOverlay = RouteOverlay(
5664
OverlayHandler,
5765
'add-annotation',

src/overlays/reducers/overlays.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export type OverlayID =
1515
| 'add-token'
1616
| 'telegraf-config'
1717
| 'telegraf-output'
18+
| 'telegraf-instructions'
1819
| 'switch-organizations'
1920
| 'create-bucket'
2021
| 'asset-limit'
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.setup-instructions {
2+
cursor: pointer;
3+
color: #00a3ff;
4+
}
5+
.setup-instructions:hover {
6+
color: #00c9ff;
7+
}

src/telegrafs/components/CollectorCard.tsx

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Libraries
22
import React, {PureComponent, MouseEvent, RefObject, createRef} from 'react'
33
import {connect, ConnectedProps} from 'react-redux'
4-
import {withRouter, RouteComponentProps, Link} from 'react-router-dom'
4+
import {withRouter, RouteComponentProps} from 'react-router-dom'
55

66
// Components
77
import {
@@ -24,6 +24,7 @@ import {
2424
addTelegrafLabelAsync,
2525
removeTelegrafLabelAsync,
2626
} from 'src/telegrafs/actions/thunks'
27+
import {showOverlay, dismissOverlay} from 'src/overlays/actions/overlays'
2728

2829
import {cloneTelegraf} from 'src/telegrafs/actions/thunks'
2930
// Selectors
@@ -38,6 +39,9 @@ import {AppState, Label, Telegraf} from 'src/types'
3839
// Utils
3940
import {setCloneName} from 'src/utils/naming'
4041

42+
// Styles
43+
import './CollectorCard.scss'
44+
4145
interface OwnProps {
4246
collector: Telegraf
4347
onDelete: (telegraf: Telegraf) => void
@@ -52,7 +56,7 @@ class CollectorRow extends PureComponent<
5256
Props & RouteComponentProps<{orgID: string}>
5357
> {
5458
public render() {
55-
const {collector, org} = this.props
59+
const {collector} = this.props
5660

5761
return (
5862
<ResourceCard
@@ -75,12 +79,13 @@ class CollectorRow extends PureComponent<
7579
placeholder={`Describe ${collector.name}`}
7680
/>
7781
<ResourceCard.Meta>
78-
<Link
79-
to={`/orgs/${org.id}/load-data/telegrafs/${collector.id}/instructions`}
82+
<span
83+
className="setup-instructions"
8084
data-testid="setup-instructions-link"
85+
onClick={this.openInstructionsOverlay}
8186
>
8287
Setup Instructions
83-
</Link>
88+
</span>
8489
</ResourceCard.Meta>
8590
{this.labels}
8691
</ResourceCard>
@@ -131,6 +136,16 @@ class CollectorRow extends PureComponent<
131136
)
132137
}
133138

139+
private openInstructionsOverlay = e => {
140+
e.preventDefault()
141+
const {showOverlay, dismissOverlay, collector} = this.props
142+
return showOverlay(
143+
'telegraf-instructions',
144+
{collectorId: collector.id},
145+
dismissOverlay
146+
)
147+
}
148+
134149
private handleUpdateName = (name: string) => {
135150
const {onUpdate, collector} = this.props
136151

@@ -199,6 +214,8 @@ const mdtp = {
199214
cloneTelegraf,
200215
onAddLabel: addTelegrafLabelAsync,
201216
onRemoveLabel: removeTelegrafLabelAsync,
217+
showOverlay,
218+
dismissOverlay,
202219
}
203220

204221
const connector = connect(mstp, mdtp)

src/telegrafs/components/TelegrafInstructionsOverlay.tsx

Lines changed: 35 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
// Libraries
2-
import React, {PureComponent} from 'react'
2+
import React, {FC, useContext} from 'react'
33
import {connect, ConnectedProps} from 'react-redux'
4-
import {get} from 'lodash'
54
import {withRouter, RouteComponentProps} from 'react-router-dom'
65

76
// Components
8-
import {ErrorHandling} from 'src/shared/decorators/errors'
97
import {Overlay} from '@influxdata/clockface'
108
import TelegrafInstructions from 'src/dataLoaders/components/verifyStep/TelegrafInstructions'
119
import GetResources from 'src/resources/components/GetResources'
@@ -17,64 +15,53 @@ import {Telegraf, AppState, ResourceType} from 'src/types'
1715
import {getAll, getToken} from 'src/resources/selectors'
1816
import {clearDataLoaders} from 'src/dataLoaders/actions/dataLoaders'
1917

18+
// Contexts
19+
import {OverlayContext} from 'src/overlays/components/OverlayController'
20+
21+
interface OwnProps {
22+
onClose: () => void
23+
}
24+
2025
type ReduxProps = ConnectedProps<typeof connector>
21-
type Props = ReduxProps & RouteComponentProps<{orgID: string; id: string}>
26+
type Props = OwnProps &
27+
ReduxProps &
28+
RouteComponentProps<{orgID: string; id: string}>
2229

23-
@ErrorHandling
24-
export class TelegrafInstructionsOverlay extends PureComponent<Props> {
25-
public render() {
26-
const {token} = this.props
27-
return (
28-
<Overlay visible={true}>
29-
<Overlay.Container maxWidth={700}>
30-
<Overlay.Header
31-
title="Telegraf Setup Instructions"
32-
onDismiss={this.handleDismiss}
33-
/>
34-
<Overlay.Body>
35-
<GetResources resources={[ResourceType.Authorizations]}>
36-
<TelegrafInstructions
37-
token={token}
38-
configID={get(this.collector, 'id', '')}
39-
/>
40-
</GetResources>
41-
</Overlay.Body>
42-
</Overlay.Container>
43-
</Overlay>
44-
)
45-
}
30+
const TelegrafInstructionsOverlay: FC<Props> = props => {
31+
const {token} = props
32+
const {params} = useContext(OverlayContext)
4633

47-
private get collector() {
48-
const {
49-
match: {
50-
params: {id},
51-
},
52-
collectors,
53-
} = this.props
54-
return collectors.find(c => c.id === id)
34+
const collector = () => {
35+
const {collectors} = props
36+
const collector = collectors.find(c => c.id === params.collectorId)
37+
return collector.id || ''
5538
}
5639

57-
private handleDismiss = (): void => {
58-
const {
59-
history,
60-
match: {
61-
params: {orgID},
62-
},
63-
onClearDataLoaders,
64-
} = this.props
65-
this.setState({
66-
collectorID: null,
67-
})
40+
const handleDismiss = (): void => {
41+
const {onClearDataLoaders, onClose} = props
6842
onClearDataLoaders()
69-
history.push(`/orgs/${orgID}/load-data/telegrafs/`)
43+
onClose()
7044
}
45+
46+
return (
47+
<Overlay.Container maxWidth={700}>
48+
<Overlay.Header
49+
title="Telegraf Setup Instructions"
50+
onDismiss={handleDismiss}
51+
/>
52+
<Overlay.Body>
53+
<GetResources resources={[ResourceType.Authorizations]}>
54+
<TelegrafInstructions token={token} configID={collector()} />
55+
</GetResources>
56+
</Overlay.Body>
57+
</Overlay.Container>
58+
)
7159
}
7260

7361
const mstp = (state: AppState) => {
7462
const {
7563
me: {name},
7664
} = state
77-
7865
const token = getToken(state)
7966
const telegrafs = getAll<Telegraf>(state, ResourceType.Telegrafs)
8067

src/telegrafs/containers/TelegrafsPage.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import LoadDataHeader from 'src/settings/components/LoadDataHeader'
99
import Collectors from 'src/telegrafs/components/Collectors'
1010
import GetResources from 'src/resources/components/GetResources'
1111
import LimitChecker from 'src/cloud/components/LimitChecker'
12-
import TelegrafInstructionsOverlay from 'src/telegrafs/components/TelegrafInstructionsOverlay'
1312
import TelegrafUIRefreshWizard from 'src/dataLoaders/components/collectorsWizard/TelegrafUIRefreshWizard'
1413
import {Page} from '@influxdata/clockface'
1514
import OverlayHandler, {
@@ -57,10 +56,6 @@ class TelegrafsPage extends PureComponent {
5756
path={`${telegrafsPath}/:id/view`}
5857
component={TelegrafConfigOverlay}
5958
/>
60-
<Route
61-
path={`${telegrafsPath}/:id/instructions`}
62-
component={TelegrafInstructionsOverlay}
63-
/>
6459
<Route
6560
path={`${telegrafsPath}/new`}
6661
component={TelegrafUIRefreshWizard}

0 commit comments

Comments
 (0)