-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a button to view the telegraf config toml
- Loading branch information
Showing
6 changed files
with
258 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Libraries | ||
import React, {PureComponent} from 'react' | ||
import _ from 'lodash' | ||
|
||
// Components | ||
import {SpinnerContainer, TechnoSpinner} from 'src/clockface' | ||
import {ErrorHandling} from 'src/shared/decorators/errors' | ||
|
||
// Apis | ||
import {client} from 'src/utils/api' | ||
|
||
// Constants | ||
import {getTelegrafConfigFailed} from 'src/shared/copy/v2/notifications' | ||
|
||
// types | ||
import {RemoteDataState} from 'src/types' | ||
import {notify as notifyAction} from 'src/shared/actions/notifications' | ||
|
||
export interface Props { | ||
telegrafConfigID: string | ||
notify: typeof notifyAction | ||
children: (telegrafConfig: string) => JSX.Element | ||
} | ||
|
||
interface State { | ||
loading: RemoteDataState | ||
telegrafConfig?: string | ||
} | ||
|
||
@ErrorHandling | ||
class FetchTelegrafConfig extends PureComponent<Props, State> { | ||
constructor(props: Props) { | ||
super(props) | ||
|
||
this.state = {loading: RemoteDataState.NotStarted} | ||
} | ||
|
||
public async componentDidMount() { | ||
const {telegrafConfigID, notify} = this.props | ||
|
||
this.setState({loading: RemoteDataState.Loading}) | ||
try { | ||
const telegrafConfig = await client.telegrafConfigs.getTOML( | ||
telegrafConfigID | ||
) | ||
this.setState({telegrafConfig, loading: RemoteDataState.Done}) | ||
} catch (err) { | ||
this.setState({loading: RemoteDataState.Error}) | ||
notify(getTelegrafConfigFailed()) | ||
} | ||
} | ||
|
||
public render() { | ||
return ( | ||
<SpinnerContainer | ||
loading={this.state.loading} | ||
spinnerComponent={<TechnoSpinner />} | ||
> | ||
{this.props.children(this.state.telegrafConfig)} | ||
</SpinnerContainer> | ||
) | ||
} | ||
} | ||
|
||
export default FetchTelegrafConfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Libraries | ||
import React, {PureComponent} from 'react' | ||
import {connect} from 'react-redux' | ||
|
||
// Components | ||
import {ErrorHandling} from 'src/shared/decorators/errors' | ||
import FetchTelegrafConfig from 'src/organizations/components/FetchTelegrafConfig' | ||
import {Controlled as ReactCodeMirror} from 'react-codemirror2' | ||
|
||
// Actions | ||
import {notify as notifyAction} from 'src/shared/actions/notifications' | ||
|
||
// Types | ||
import {AppState} from 'src/types/v2' | ||
|
||
interface OwnProps {} | ||
|
||
interface DispatchProps { | ||
notify: typeof notifyAction | ||
} | ||
|
||
interface StateProps { | ||
telegrafConfigID: string | ||
} | ||
|
||
type Props = StateProps & DispatchProps & OwnProps | ||
|
||
@ErrorHandling | ||
export class TelegrafConfig extends PureComponent<Props> { | ||
public render() { | ||
const options = { | ||
tabIndex: 1, | ||
mode: 'toml', | ||
readonly: true, | ||
lineNumbers: true, | ||
autoRefresh: true, | ||
theme: 'time-machine', | ||
completeSingle: false, | ||
} | ||
|
||
return ( | ||
<FetchTelegrafConfig | ||
telegrafConfigID={this.props.telegrafConfigID} | ||
notify={this.props.notify} | ||
> | ||
{telegrafConfig => ( | ||
<ReactCodeMirror | ||
autoFocus={true} | ||
autoCursor={true} | ||
value={telegrafConfig} | ||
options={options} | ||
onBeforeChange={this.onBeforeChange} | ||
onTouchStart={this.onTouchStart} | ||
/> | ||
)} | ||
</FetchTelegrafConfig> | ||
) | ||
} | ||
|
||
private onBeforeChange = () => {} | ||
private onTouchStart = () => {} | ||
} | ||
|
||
const mstp = ({ | ||
dataLoading: { | ||
dataLoaders: {telegrafConfigID}, | ||
}, | ||
}: AppState): StateProps => ({ | ||
telegrafConfigID, | ||
}) | ||
|
||
const mdtp: DispatchProps = { | ||
notify: notifyAction, | ||
} | ||
|
||
export default connect<StateProps, DispatchProps, OwnProps>( | ||
mstp, | ||
mdtp | ||
)(TelegrafConfig) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Libraries | ||
import React, {PureComponent} from 'react' | ||
import {connect} from 'react-redux' | ||
|
||
// Components | ||
import {ErrorHandling} from 'src/shared/decorators/errors' | ||
import WizardOverlay from 'src/clockface/components/wizard/WizardOverlay' | ||
import TelegrafConfig from 'src/organizations/components/TelegrafConfig' | ||
|
||
// Types | ||
import {AppState} from 'src/types/v2' | ||
|
||
interface OwnProps { | ||
visible: boolean | ||
onDismiss: () => void | ||
} | ||
|
||
interface StateProps { | ||
telegrafConfigName: string | ||
} | ||
|
||
type Props = OwnProps & StateProps | ||
|
||
@ErrorHandling | ||
export class TelegrafConfigOverlay extends PureComponent<Props> { | ||
public render() { | ||
const {visible, onDismiss, telegrafConfigName} = this.props | ||
|
||
return ( | ||
<WizardOverlay | ||
visible={visible} | ||
title={`Telegraf Configuration - ${telegrafConfigName}`} | ||
onDismiss={onDismiss} | ||
> | ||
<TelegrafConfig /> | ||
</WizardOverlay> | ||
) | ||
} | ||
} | ||
|
||
const mstp = ({ | ||
dataLoading: { | ||
dataLoaders: {telegrafConfigName}, | ||
}, | ||
}: AppState): StateProps => { | ||
return {telegrafConfigName} | ||
} | ||
|
||
export default connect<StateProps, {}, OwnProps>( | ||
mstp, | ||
null | ||
)(TelegrafConfigOverlay) |