-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
TelegrafConfigOverlay.tsx
118 lines (104 loc) · 2.84 KB
/
TelegrafConfigOverlay.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Libraries
import React, {PureComponent} from 'react'
import {connect} from 'react-redux'
import {withRouter, WithRouterProps} from 'react-router'
import _ from 'lodash'
// Components
import {ErrorHandling} from 'src/shared/decorators/errors'
import TelegrafConfig from 'src/telegrafs/components/TelegrafConfig'
import {
ComponentColor,
Button,
RemoteDataState,
SpinnerContainer,
TechnoSpinner,
Overlay,
ComponentStatus,
} from '@influxdata/clockface'
// Utils
import {downloadTextFile} from 'src/shared/utils/download'
// Types
import {AppState} from 'src/types'
import {ITelegraf as Telegraf} from '@influxdata/influx'
interface StateProps {
telegraf: Telegraf
status: RemoteDataState
telegrafConfig: string
configStatus: RemoteDataState
}
type Props = StateProps & WithRouterProps
@ErrorHandling
class TelegrafConfigOverlay extends PureComponent<Props> {
public render() {
return <>{this.overlay}</>
}
private get overlay(): JSX.Element {
const {telegraf, status} = this.props
return (
<Overlay visible={true}>
<Overlay.Container maxWidth={1200}>
<Overlay.Header
title={`Telegraf Configuration - ${_.get(telegraf, 'name', '')}`}
onDismiss={this.handleDismiss}
/>
<Overlay.Body>
<SpinnerContainer
loading={status}
spinnerComponent={<TechnoSpinner />}
>
<div className="config-overlay">
<TelegrafConfig />
</div>
</SpinnerContainer>
</Overlay.Body>
<Overlay.Footer>
<Button
color={ComponentColor.Secondary}
text="Download Config"
onClick={this.handleDownloadConfig}
status={this.buttonStatus}
/>
</Overlay.Footer>
</Overlay.Container>
</Overlay>
)
}
private get buttonStatus(): ComponentStatus {
const {configStatus} = this.props
if (configStatus === RemoteDataState.Done) {
return ComponentStatus.Default
}
return ComponentStatus.Disabled
}
private handleDismiss = () => {
const {
router,
params: {orgID},
} = this.props
router.push(`/orgs/${orgID}/telegrafs`)
}
private handleDownloadConfig = async () => {
const {
telegrafConfig,
telegraf: {name},
} = this.props
downloadTextFile(telegrafConfig, name || 'config', '.toml')
}
}
const mstp = ({telegrafs}: AppState, props: Props): StateProps => {
const {
params: {id},
} = props
return {
telegraf: telegrafs.list.find(t => {
return t.id === id
}),
status: telegrafs.status,
telegrafConfig: telegrafs.currentConfig.item,
configStatus: telegrafs.currentConfig.status,
}
}
export default connect<StateProps, {}, {}>(
mstp,
null
)(withRouter<Props>(TelegrafConfigOverlay))