Create dashboards for plugins in verify step

pull/11477/head
Deniz Kusefoglu 2019-01-17 19:53:16 -08:00
parent 74c21c8990
commit fe5539c9cf
9 changed files with 92 additions and 46 deletions

View File

@ -26,7 +26,6 @@ import {
removeConfigValue, removeConfigValue,
setActiveTelegrafPlugin, setActiveTelegrafPlugin,
setPluginConfiguration, setPluginConfiguration,
createOrUpdateTelegrafConfigAsync,
addPluginBundleWithPlugins, addPluginBundleWithPlugins,
removePluginBundleWithPlugins, removePluginBundleWithPlugins,
setConfigArrayValue, setConfigArrayValue,
@ -81,7 +80,6 @@ interface DispatchProps {
onSetActiveTelegrafPlugin: typeof setActiveTelegrafPlugin onSetActiveTelegrafPlugin: typeof setActiveTelegrafPlugin
onSetPluginConfiguration: typeof setPluginConfiguration onSetPluginConfiguration: typeof setPluginConfiguration
onSetConfigArrayValue: typeof setConfigArrayValue onSetConfigArrayValue: typeof setConfigArrayValue
onSaveTelegrafConfig: typeof createOrUpdateTelegrafConfigAsync
onIncrementCurrentStepIndex: typeof incrementCurrentStepIndex onIncrementCurrentStepIndex: typeof incrementCurrentStepIndex
onDecrementCurrentStepIndex: typeof decrementCurrentStepIndex onDecrementCurrentStepIndex: typeof decrementCurrentStepIndex
onSetCurrentStepIndex: typeof setCurrentStepIndex onSetCurrentStepIndex: typeof setCurrentStepIndex
@ -128,7 +126,6 @@ class DataLoadersWizard extends PureComponent<Props> {
onUpdateTelegrafPluginConfig, onUpdateTelegrafPluginConfig,
onAddConfigValue, onAddConfigValue,
onRemoveConfigValue, onRemoveConfigValue,
onSaveTelegrafConfig,
onAddPluginBundle, onAddPluginBundle,
onRemovePluginBundle, onRemovePluginBundle,
notify, notify,
@ -170,7 +167,6 @@ class DataLoadersWizard extends PureComponent<Props> {
onSetPluginConfiguration={onSetPluginConfiguration} onSetPluginConfiguration={onSetPluginConfiguration}
onAddConfigValue={onAddConfigValue} onAddConfigValue={onAddConfigValue}
onRemoveConfigValue={onRemoveConfigValue} onRemoveConfigValue={onRemoveConfigValue}
onSaveTelegrafConfig={onSaveTelegrafConfig}
onAddPluginBundle={onAddPluginBundle} onAddPluginBundle={onAddPluginBundle}
onRemovePluginBundle={onRemovePluginBundle} onRemovePluginBundle={onRemovePluginBundle}
onSetConfigArrayValue={onSetConfigArrayValue} onSetConfigArrayValue={onSetConfigArrayValue}
@ -304,7 +300,6 @@ const mdtp: DispatchProps = {
onAddConfigValue: addConfigValue, onAddConfigValue: addConfigValue,
onRemoveConfigValue: removeConfigValue, onRemoveConfigValue: removeConfigValue,
onSetActiveTelegrafPlugin: setActiveTelegrafPlugin, onSetActiveTelegrafPlugin: setActiveTelegrafPlugin,
onSaveTelegrafConfig: createOrUpdateTelegrafConfigAsync,
onAddPluginBundle: addPluginBundleWithPlugins, onAddPluginBundle: addPluginBundleWithPlugins,
onRemovePluginBundle: removePluginBundleWithPlugins, onRemovePluginBundle: removePluginBundleWithPlugins,
onSetPluginConfiguration: setPluginConfiguration, onSetPluginConfiguration: setPluginConfiguration,

View File

@ -15,7 +15,6 @@ import {
setActiveTelegrafPlugin, setActiveTelegrafPlugin,
addConfigValue, addConfigValue,
removeConfigValue, removeConfigValue,
createOrUpdateTelegrafConfigAsync,
addPluginBundleWithPlugins, addPluginBundleWithPlugins,
removePluginBundleWithPlugins, removePluginBundleWithPlugins,
setPluginConfiguration, setPluginConfiguration,
@ -40,7 +39,6 @@ interface Props {
buckets: Bucket[] buckets: Bucket[]
dataLoaders: DataLoadersState dataLoaders: DataLoadersState
currentStepIndex: number currentStepIndex: number
onSaveTelegrafConfig: typeof createOrUpdateTelegrafConfigAsync
onAddPluginBundle: typeof addPluginBundleWithPlugins onAddPluginBundle: typeof addPluginBundleWithPlugins
onRemovePluginBundle: typeof removePluginBundleWithPlugins onRemovePluginBundle: typeof removePluginBundleWithPlugins
onSetConfigArrayValue: typeof setConfigArrayValue onSetConfigArrayValue: typeof setConfigArrayValue
@ -58,7 +56,6 @@ class StepSwitcher extends PureComponent<Props> {
onboardingStepProps, onboardingStepProps,
dataLoaders, dataLoaders,
onSetDataLoadersType, onSetDataLoadersType,
onSaveTelegrafConfig,
onUpdateTelegrafPluginConfig, onUpdateTelegrafPluginConfig,
onSetActiveTelegrafPlugin, onSetActiveTelegrafPlugin,
onSetPluginConfiguration, onSetPluginConfiguration,
@ -117,7 +114,6 @@ class StepSwitcher extends PureComponent<Props> {
selectedBucket={selectedBucket} selectedBucket={selectedBucket}
username={username} username={username}
org={org} org={org}
onSaveTelegrafConfig={onSaveTelegrafConfig}
onSetActiveTelegrafPlugin={onSetActiveTelegrafPlugin} onSetActiveTelegrafPlugin={onSetActiveTelegrafPlugin}
onSetPluginConfiguration={onSetPluginConfiguration} onSetPluginConfiguration={onSetPluginConfiguration}
stepIndex={currentStepIndex} stepIndex={currentStepIndex}

View File

@ -3,7 +3,7 @@ import React from 'react'
import {shallow} from 'enzyme' import {shallow} from 'enzyme'
// Components // Components
import CreateOrUpdateConfig from 'src/onboarding/components/verifyStep/CreateOrUpdateConfig' import {CreateOrUpdateConfig} from 'src/onboarding/components/verifyStep/CreateOrUpdateConfig'
jest.mock('src/utils/api', () => require('src/onboarding/apis/mocks')) jest.mock('src/utils/api', () => require('src/onboarding/apis/mocks'))
@ -12,6 +12,7 @@ const setup = async (override = {}) => {
org: 'default', org: 'default',
children: jest.fn(), children: jest.fn(),
onSaveTelegrafConfig: jest.fn(), onSaveTelegrafConfig: jest.fn(),
createDashboardsForPlugins: jest.fn(),
notify: jest.fn(), notify: jest.fn(),
authToken: '', authToken: '',
...override, ...override,

View File

@ -1,5 +1,6 @@
// Libraries // Libraries
import React, {PureComponent} from 'react' import React, {PureComponent} from 'react'
import {connect} from 'react-redux'
import _ from 'lodash' import _ from 'lodash'
// Components // Components
@ -8,6 +9,8 @@ import {ErrorHandling} from 'src/shared/decorators/errors'
// Actions // Actions
import {createOrUpdateTelegrafConfigAsync} from 'src/onboarding/actions/dataLoaders' import {createOrUpdateTelegrafConfigAsync} from 'src/onboarding/actions/dataLoaders'
import {notify as notifyAction} from 'src/shared/actions/notifications'
import {createDashboardsForPlugins as createDashboardsForPluginsAction} from 'src/protos/actions/'
// Constants // Constants
import { import {
@ -18,20 +21,26 @@ import {
// Types // Types
import {RemoteDataState, NotificationAction} from 'src/types' import {RemoteDataState, NotificationAction} from 'src/types'
export interface Props { export interface OwnProps {
org: string org: string
authToken: string authToken: string
children: () => JSX.Element children: () => JSX.Element
onSaveTelegrafConfig: typeof createOrUpdateTelegrafConfigAsync
notify: NotificationAction
} }
export interface DispatchProps {
notify: NotificationAction
onSaveTelegrafConfig: typeof createOrUpdateTelegrafConfigAsync
createDashboardsForPlugins: typeof createDashboardsForPluginsAction
}
type Props = OwnProps & DispatchProps
interface State { interface State {
loading: RemoteDataState loading: RemoteDataState
} }
@ErrorHandling @ErrorHandling
class CreateOrUpdateConfig extends PureComponent<Props, State> { export class CreateOrUpdateConfig extends PureComponent<Props, State> {
constructor(props: Props) { constructor(props: Props) {
super(props) super(props)
@ -39,13 +48,19 @@ class CreateOrUpdateConfig extends PureComponent<Props, State> {
} }
public async componentDidMount() { public async componentDidMount() {
const {onSaveTelegrafConfig, authToken, notify} = this.props const {
onSaveTelegrafConfig,
authToken,
notify,
createDashboardsForPlugins,
} = this.props
this.setState({loading: RemoteDataState.Loading}) this.setState({loading: RemoteDataState.Loading})
try { try {
await onSaveTelegrafConfig(authToken) await onSaveTelegrafConfig(authToken)
notify(TelegrafConfigCreationSuccess) notify(TelegrafConfigCreationSuccess)
await createDashboardsForPlugins()
this.setState({loading: RemoteDataState.Done}) this.setState({loading: RemoteDataState.Done})
} catch (error) { } catch (error) {
@ -61,4 +76,13 @@ class CreateOrUpdateConfig extends PureComponent<Props, State> {
} }
} }
export default CreateOrUpdateConfig const mdtp: DispatchProps = {
notify: notifyAction,
onSaveTelegrafConfig: createOrUpdateTelegrafConfigAsync,
createDashboardsForPlugins: createDashboardsForPluginsAction,
}
export default connect<null, DispatchProps, OwnProps>(
null,
mdtp
)(CreateOrUpdateConfig)

View File

@ -7,9 +7,6 @@ import TelegrafInstructions from 'src/onboarding/components/verifyStep/TelegrafI
import CreateOrUpdateConfig from 'src/onboarding/components/verifyStep/CreateOrUpdateConfig' import CreateOrUpdateConfig from 'src/onboarding/components/verifyStep/CreateOrUpdateConfig'
import DataListening from 'src/onboarding/components/verifyStep/DataListening' import DataListening from 'src/onboarding/components/verifyStep/DataListening'
// Actions
import {createOrUpdateTelegrafConfigAsync} from 'src/onboarding/actions/dataLoaders'
// Decorator // Decorator
import {ErrorHandling} from 'src/shared/decorators/errors' import {ErrorHandling} from 'src/shared/decorators/errors'
@ -22,29 +19,16 @@ interface Props {
org: string org: string
configID: string configID: string
authToken: string authToken: string
onSaveTelegrafConfig: typeof createOrUpdateTelegrafConfigAsync
} }
@ErrorHandling @ErrorHandling
class DataStreaming extends PureComponent<Props> { class DataStreaming extends PureComponent<Props> {
public render() { public render() {
const { const {authToken, org, configID, bucket, notify} = this.props
authToken,
org,
configID,
onSaveTelegrafConfig,
bucket,
notify,
} = this.props
return ( return (
<> <>
<CreateOrUpdateConfig <CreateOrUpdateConfig org={org} authToken={authToken}>
org={org}
notify={notify}
authToken={authToken}
onSaveTelegrafConfig={onSaveTelegrafConfig}
>
{() => ( {() => (
<TelegrafInstructions <TelegrafInstructions
notify={notify} notify={notify}

View File

@ -12,7 +12,6 @@ import FancyScrollbar from 'src/shared/components/fancy_scrollbar/FancyScrollbar
// Actions // Actions
import { import {
setActiveTelegrafPlugin, setActiveTelegrafPlugin,
createOrUpdateTelegrafConfigAsync,
setPluginConfiguration, setPluginConfiguration,
} from 'src/onboarding/actions/dataLoaders' } from 'src/onboarding/actions/dataLoaders'
@ -30,7 +29,6 @@ export interface OwnProps extends DataLoaderStepProps {
telegrafPlugins: TelegrafPlugin[] telegrafPlugins: TelegrafPlugin[]
onSetActiveTelegrafPlugin: typeof setActiveTelegrafPlugin onSetActiveTelegrafPlugin: typeof setActiveTelegrafPlugin
onSetPluginConfiguration: typeof setPluginConfiguration onSetPluginConfiguration: typeof setPluginConfiguration
onSaveTelegrafConfig: typeof createOrUpdateTelegrafConfigAsync
stepIndex: number stepIndex: number
bucket: string bucket: string
username: string username: string
@ -61,7 +59,6 @@ export class VerifyDataStep extends PureComponent<Props> {
username, username,
telegrafConfigID, telegrafConfigID,
type, type,
onSaveTelegrafConfig,
onDecrementCurrentStepIndex, onDecrementCurrentStepIndex,
notify, notify,
lpStatus, lpStatus,
@ -78,7 +75,6 @@ export class VerifyDataStep extends PureComponent<Props> {
notify={notify} notify={notify}
type={type} type={type}
telegrafConfigID={telegrafConfigID} telegrafConfigID={telegrafConfigID}
onSaveTelegrafConfig={onSaveTelegrafConfig}
org={org} org={org}
bucket={this.bucket} bucket={this.bucket}
username={username} username={username}

View File

@ -6,9 +6,6 @@ import {ErrorHandling} from 'src/shared/decorators/errors'
import DataStreaming from 'src/onboarding/components/verifyStep/DataStreaming' import DataStreaming from 'src/onboarding/components/verifyStep/DataStreaming'
import FetchAuthToken from 'src/onboarding/components/verifyStep/FetchAuthToken' import FetchAuthToken from 'src/onboarding/components/verifyStep/FetchAuthToken'
// Actions
import {createOrUpdateTelegrafConfigAsync} from 'src/onboarding/actions/dataLoaders'
// Types // Types
import {DataLoaderType} from 'src/types/v2/dataLoaders' import {DataLoaderType} from 'src/types/v2/dataLoaders'
import {NotificationAction, RemoteDataState} from 'src/types' import {NotificationAction, RemoteDataState} from 'src/types'
@ -21,7 +18,6 @@ interface Props {
bucket: string bucket: string
username: string username: string
telegrafConfigID: string telegrafConfigID: string
onSaveTelegrafConfig: typeof createOrUpdateTelegrafConfigAsync
onDecrementCurrentStep: () => void onDecrementCurrentStep: () => void
lpStatus: RemoteDataState lpStatus: RemoteDataState
} }
@ -35,7 +31,6 @@ export class VerifyDataSwitcher extends PureComponent<Props> {
username, username,
type, type,
telegrafConfigID, telegrafConfigID,
onSaveTelegrafConfig,
notify, notify,
lpStatus, lpStatus,
} = this.props } = this.props
@ -51,7 +46,6 @@ export class VerifyDataSwitcher extends PureComponent<Props> {
configID={telegrafConfigID} configID={telegrafConfigID}
authToken={authToken} authToken={authToken}
bucket={bucket} bucket={bucket}
onSaveTelegrafConfig={onSaveTelegrafConfig}
/> />
)} )}
</FetchAuthToken> </FetchAuthToken>

View File

@ -13,10 +13,18 @@ import {addLabelDefaults} from 'src/shared/utils/labels'
// Actions // Actions
import {loadDashboard} from 'src/dashboards/actions/v2/' import {loadDashboard} from 'src/dashboards/actions/v2/'
import {notify} from 'src/shared/actions/notifications'
// Types // Types
import {Proto} from 'src/api' import {Proto, Dashboard} from 'src/api'
import {Dashboard} from 'src/types/v2' import {GetState} from 'src/types/v2'
import {ConfigurationState} from 'src/types/v2/dataLoaders'
// Const
import {
ProtoDashboardFailed,
ProtoDashboardCreated,
} from 'src/shared/copy/notifications'
export enum ActionTypes { export enum ActionTypes {
LoadProto = 'LOAD_PROTO', LoadProto = 'LOAD_PROTO',
@ -39,6 +47,7 @@ export const loadProto = (proto: Proto): LoadProtoAction => ({
export const getProtos = () => async (dispatch: Dispatch<Action>) => { export const getProtos = () => async (dispatch: Dispatch<Action>) => {
try { try {
const {protos} = await getProtosAJAX() const {protos} = await getProtosAJAX()
protos.forEach(p => { protos.forEach(p => {
dispatch(loadProto(p)) dispatch(loadProto(p))
}) })
@ -66,3 +75,37 @@ export const createDashFromProto = (
console.error(error) console.error(error)
} }
} }
export const createDashboardsForPlugins = () => async (
dispatch,
getState: GetState
) => {
await dispatch(getProtos())
const {
dataLoading: {
dataLoaders: {telegrafPlugins},
steps: {orgID},
},
protos,
} = getState()
const plugins = []
try {
telegrafPlugins.forEach(tp => {
if (tp.configured === ConfigurationState.Configured) {
if (protos[tp.name]) {
dispatch(createDashFromProto(protos[tp.name].id, orgID))
plugins.push(tp.name)
}
}
})
if (plugins.length) {
dispatch(notify(ProtoDashboardCreated(plugins)))
}
} catch (err) {
console.error(err)
dispatch(notify(ProtoDashboardFailed()))
}
}

View File

@ -725,3 +725,16 @@ export const fluxTimeSeriesError = (message: string): Notification => ({
...defaultErrorNotification, ...defaultErrorNotification,
message: `Could not get data: ${message}`, message: `Could not get data: ${message}`,
}) })
// Protos
export const ProtoDashboardCreated = (configs: string[]): Notification => ({
...defaultSuccessNotification,
message: `Successfully created dashboards for telegraf plugin${
configs.length > 1 ? 's' : ''
}: ${configs.join(', ')}.`,
})
export const ProtoDashboardFailed = (): Notification => ({
...defaultErrorNotification,
message: `Could not create dashboards for one or more plugins`,
})