From 198d066cdf6c483b7dce3f081b1b78b85fd47f30 Mon Sep 17 00:00:00 2001 From: Alex P Date: Wed, 31 Jan 2018 17:17:15 -0800 Subject: [PATCH] Replace create & exit with just exit --- ui/src/kapacitor/actions/view/index.js | 51 +------------------ ui/src/kapacitor/components/Tickscript.js | 6 ++- .../kapacitor/components/TickscriptHeader.js | 8 +-- ui/src/kapacitor/containers/TickscriptPage.js | 36 ++----------- 4 files changed, 14 insertions(+), 87 deletions(-) diff --git a/ui/src/kapacitor/actions/view/index.js b/ui/src/kapacitor/actions/view/index.js index 02c7e1e06..5ee91d336 100644 --- a/ui/src/kapacitor/actions/view/index.js +++ b/ui/src/kapacitor/actions/view/index.js @@ -195,12 +195,7 @@ export const updateRuleStatus = (rule, status) => dispatch => { }) } -export const createTask = ( - kapacitor, - task, - router, - sourceID -) => async dispatch => { +export const createTask = (kapacitor, task) => async dispatch => { try { const {data} = await createTaskAJAX(kapacitor, task) dispatch(publishNotification('success', 'You made a TICKscript!')) @@ -219,7 +214,6 @@ export const updateTask = ( kapacitor, task, ruleID, - router, sourceID ) => async dispatch => { try { @@ -235,46 +229,3 @@ export const updateTask = ( return error.data } } - -export const createTaskExit = ( - kapacitor, - task, - router, - sourceID -) => async dispatch => { - try { - const {data} = await createTaskAJAX(kapacitor, task) - router.push(`/sources/${sourceID}/alert-rules`) - dispatch(publishNotification('success', 'TICKscript successfully created.')) - return data - } catch (error) { - if (!error) { - dispatch(errorThrown('Could not communicate with server')) - return - } - - return error.data - } -} - -export const updateTaskExit = ( - kapacitor, - task, - ruleID, - router, - sourceID -) => async dispatch => { - try { - const {data} = await updateTaskAJAX(kapacitor, task, ruleID, sourceID) - router.push(`/sources/${sourceID}/alert-rules`) - dispatch(publishNotification('success', 'TICKscript updated successully')) - return data - } catch (error) { - if (!error) { - dispatch(errorThrown('Could not communicate with server')) - return - } - - return error.data - } -} diff --git a/ui/src/kapacitor/components/Tickscript.js b/ui/src/kapacitor/components/Tickscript.js index 032ef70b4..73e38f095 100644 --- a/ui/src/kapacitor/components/Tickscript.js +++ b/ui/src/kapacitor/components/Tickscript.js @@ -8,7 +8,7 @@ import LogsTable from 'src/kapacitor/components/LogsTable' const Tickscript = ({ onSave, - onSaveAndExit, + onExit, task, logs, validation, @@ -26,8 +26,8 @@ const Tickscript = ({ : } @@ -66,6 +66,7 @@ const {arrayOf, bool, func, shape, string} = PropTypes TickscriptHeader.propTypes = { isNewTickscript: bool, onSave: func, + onExit: func.isRequired, areLogsVisible: bool, areLogsEnabled: bool, onToggleLogsVisibility: func.isRequired, @@ -77,6 +78,7 @@ TickscriptHeader.propTypes = { }) ), }), + unsavedChanges: bool, } export default TickscriptHeader diff --git a/ui/src/kapacitor/containers/TickscriptPage.js b/ui/src/kapacitor/containers/TickscriptPage.js index 14a879a40..947db6b6c 100644 --- a/ui/src/kapacitor/containers/TickscriptPage.js +++ b/ui/src/kapacitor/containers/TickscriptPage.js @@ -184,36 +184,10 @@ class TickscriptPage extends Component { } } - handleSaveAndExit = async () => { - const {kapacitor, task} = this.state - const { - source: {id: sourceID}, - router, - kapacitorActions: {createTaskExit, updateTaskExit}, - params: {ruleID}, - } = this.props + handleExit = () => { + const {source: {id: sourceID}, router} = this.props - let response - - try { - if (this._isEditing()) { - response = await updateTaskExit( - kapacitor, - task, - ruleID, - router, - sourceID - ) - } else { - response = await createTaskExit(kapacitor, task, router, sourceID) - } - if (response && response.code === 500) { - return this.setState({validation: response.message}) - } - } catch (error) { - console.error(error) - throw error - } + return router.push(`/sources/${sourceID}/alert-rules`) } handleChangeScript = tickscript => { @@ -258,7 +232,7 @@ class TickscriptPage extends Component { validation={validation} onSave={this.handleSave} unsavedChanges={unsavedChanges} - onSaveAndExit={this.handleSaveAndExit} + onExit={this.handleExit} isNewTickscript={!this._isEditing()} onSelectDbrps={this.handleSelectDbrps} onChangeScript={this.handleChangeScript} @@ -289,8 +263,6 @@ TickscriptPage.propTypes = { kapacitorActions: shape({ updateTask: func.isRequired, createTask: func.isRequired, - updateTaskExit: func.isRequired, - createTaskExit: func.isRequired, getRule: func.isRequired, }), router: shape({