diff --git a/ui/src/data_explorer/actions/view/index.js b/ui/src/data_explorer/actions/view/index.js
index 8101499174..e65d7005d9 100644
--- a/ui/src/data_explorer/actions/view/index.js
+++ b/ui/src/data_explorer/actions/view/index.js
@@ -1,8 +1,10 @@
import uuid from 'node-uuid'
import {getQueryConfig} from 'shared/apis'
+import {writeData} from 'src/data_explorer/apis'
import {errorThrown} from 'shared/actions/errors'
+import {publishAutoDismissingNotification} from 'shared/dispatchers'
export function addQuery(options = {}) {
return {
@@ -160,3 +162,18 @@ export const editRawTextAsync = (url, id, text) => async dispatch => {
dispatch(errorThrown(error))
}
}
+
+export const writeDataAsync = (source, db, data) => async dispatch => {
+ try {
+ await writeData(source, db, data)
+ dispatch(
+ publishAutoDismissingNotification(
+ 'success',
+ 'Data was written successfully'
+ )
+ )
+ } catch (response) {
+ dispatch(errorThrown(response, response.data.error))
+ throw response
+ }
+}
diff --git a/ui/src/data_explorer/components/WriteDataForm.js b/ui/src/data_explorer/components/WriteDataForm.js
index cf5d1da328..2ef3a060c3 100644
--- a/ui/src/data_explorer/components/WriteDataForm.js
+++ b/ui/src/data_explorer/components/WriteDataForm.js
@@ -1,14 +1,8 @@
import React, {Component, PropTypes} from 'react'
-import {connect} from 'react-redux'
-import {bindActionCreators} from 'redux'
import DatabaseDropdown from 'shared/components/DatabaseDropdown'
import OnClickOutside from 'shared/components/OnClickOutside'
-import {writeData} from 'src/data_explorer/apis'
-import {publishAutoDismissingNotification} from 'shared/dispatchers'
-import {errorThrown as errorThrownAction} from 'shared/actions/errors'
-
class WriteDataForm extends Component {
constructor(props) {
super(props)
@@ -17,7 +11,6 @@ class WriteDataForm extends Component {
}
this.handleSelectDatabase = ::this.handleSelectDatabase
- this.handleError = ::this.handleError
this.handleWrite = ::this.handleWrite
this.handleClickOutside = ::this.handleClickOutside
}
@@ -26,30 +19,19 @@ class WriteDataForm extends Component {
this.setState({selectedDatabase: item.text})
}
- handleError(error) {
- const {errorThrown} = this.props
- errorThrown(error)
- }
-
handleClickOutside() {
const {onClose} = this.props
onClose()
}
- async handleWrite() {
- const {onClose, source, notify, errorThrown} = this.props
+ handleWrite() {
+ const {onClose, source, writeData} = this.props
const {selectedDatabase} = this.state
- try {
- await writeData(source, selectedDatabase, this.editor.value)
- notify('success', 'Data was written successfully')
- onClose()
- } catch (response) {
- errorThrown(response, response.data.error)
- }
+ writeData(source, selectedDatabase, this.editor.value).then(() => onClose())
}
render() {
- const {onClose} = this.props
+ const {onClose, errorThrown} = this.props
const {selectedDatabase} = this.state
return (
@@ -60,7 +42,7 @@ class WriteDataForm extends Component {