Skip to content

Commit

Permalink
fix(ui): Ensure template dashboard only gets created on config creation
Browse files Browse the repository at this point in the history
  • Loading branch information
ischolten committed Feb 13, 2019
1 parent 2fca416 commit 1cebb1d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const setup = async (override = {}) => {
createDashboardsForPlugins: jest.fn(),
notify: jest.fn(),
authToken: '',
telegrafConfigID: '',
...override,
}

Expand Down
29 changes: 23 additions & 6 deletions ui/src/dataLoaders/components/verifyStep/CreateOrUpdateConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,24 @@ import {

// Types
import {RemoteDataState, NotificationAction} from 'src/types'
import {AppState} from 'src/types/v2'

export interface OwnProps {
interface OwnProps {
org: string
children: () => JSX.Element
}

export interface DispatchProps {
interface StateProps {
telegrafConfigID: string
}

interface DispatchProps {
notify: NotificationAction
onSaveTelegrafConfig: typeof createOrUpdateTelegrafConfigAsync
createDashboardsForPlugins: typeof createDashboardsForPluginsAction
}

type Props = OwnProps & DispatchProps
type Props = OwnProps & StateProps & DispatchProps

interface State {
loading: RemoteDataState
Expand All @@ -51,14 +56,18 @@ export class CreateOrUpdateConfig extends PureComponent<Props, State> {
onSaveTelegrafConfig,
notify,
createDashboardsForPlugins,
telegrafConfigID,
} = this.props

this.setState({loading: RemoteDataState.Loading})

try {
await onSaveTelegrafConfig()
notify(TelegrafConfigCreationSuccess)
await createDashboardsForPlugins()

if (!telegrafConfigID) {
await createDashboardsForPlugins()
}

this.setState({loading: RemoteDataState.Done})
} catch (error) {
Expand All @@ -79,13 +88,21 @@ export class CreateOrUpdateConfig extends PureComponent<Props, State> {
}
}

const mstp = ({
dataLoading: {
dataLoaders: {telegrafConfigID},
},
}: AppState): StateProps => {
return {telegrafConfigID}
}

const mdtp: DispatchProps = {
notify: notifyAction,
onSaveTelegrafConfig: createOrUpdateTelegrafConfigAsync,
createDashboardsForPlugins: createDashboardsForPluginsAction,
}

export default connect<null, DispatchProps, OwnProps>(
null,
export default connect<StateProps, DispatchProps, OwnProps>(
mstp,
mdtp
)(CreateOrUpdateConfig)

0 comments on commit 1cebb1d

Please sign in to comment.