From d5ff6e9bb99fdcad4461c69e5d1bac9f04909b96 Mon Sep 17 00:00:00 2001 From: Iris Scholten Date: Wed, 13 Feb 2019 10:01:37 -0800 Subject: [PATCH] fix(ui): Ensure template dashboard only gets created on config creation --- CHANGELOG.md | 2 ++ .../verifyStep/CreateOrUpdateConfig.test.tsx | 1 + .../verifyStep/CreateOrUpdateConfig.tsx | 29 +++++++++++++++---- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0636c106e87..22c2c65f852 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ ### Bug Fixes 1. [11819](https://github.com/influxdata/influxdb/pull/11819): Update the inline edit for resource names to guard for empty strings +1. [11852](https://github.com/influxdata/influxdb/pull/11852): Prevent a new template dashboard from being created on every telegraf config update + ### UI Improvements 1. [11764](https://github.com/influxdata/influxdb/pull/11764): Move the download telegraf config button to view config overlay diff --git a/ui/src/dataLoaders/components/verifyStep/CreateOrUpdateConfig.test.tsx b/ui/src/dataLoaders/components/verifyStep/CreateOrUpdateConfig.test.tsx index 93a9484740d..8a1607ef6d4 100644 --- a/ui/src/dataLoaders/components/verifyStep/CreateOrUpdateConfig.test.tsx +++ b/ui/src/dataLoaders/components/verifyStep/CreateOrUpdateConfig.test.tsx @@ -15,6 +15,7 @@ const setup = async (override = {}) => { createDashboardsForPlugins: jest.fn(), notify: jest.fn(), authToken: '', + telegrafConfigID: '', ...override, } diff --git a/ui/src/dataLoaders/components/verifyStep/CreateOrUpdateConfig.tsx b/ui/src/dataLoaders/components/verifyStep/CreateOrUpdateConfig.tsx index 75d952828ba..a77ec0e8c97 100644 --- a/ui/src/dataLoaders/components/verifyStep/CreateOrUpdateConfig.tsx +++ b/ui/src/dataLoaders/components/verifyStep/CreateOrUpdateConfig.tsx @@ -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 @@ -51,6 +56,7 @@ export class CreateOrUpdateConfig extends PureComponent { onSaveTelegrafConfig, notify, createDashboardsForPlugins, + telegrafConfigID, } = this.props this.setState({loading: RemoteDataState.Loading}) @@ -58,7 +64,10 @@ export class CreateOrUpdateConfig extends PureComponent { try { await onSaveTelegrafConfig() notify(TelegrafConfigCreationSuccess) - await createDashboardsForPlugins() + + if (!telegrafConfigID) { + await createDashboardsForPlugins() + } this.setState({loading: RemoteDataState.Done}) } catch (error) { @@ -79,13 +88,21 @@ export class CreateOrUpdateConfig extends PureComponent { } } +const mstp = ({ + dataLoading: { + dataLoaders: {telegrafConfigID}, + }, +}: AppState): StateProps => { + return {telegrafConfigID} +} + const mdtp: DispatchProps = { notify: notifyAction, onSaveTelegrafConfig: createOrUpdateTelegrafConfigAsync, createDashboardsForPlugins: createDashboardsForPluginsAction, } -export default connect( - null, +export default connect( + mstp, mdtp )(CreateOrUpdateConfig)