Replace create & exit with just exit
parent
3899fa1033
commit
198d066cdf
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 = ({
|
|||
<TickscriptHeader
|
||||
task={task}
|
||||
onSave={onSave}
|
||||
onExit={onExit}
|
||||
unsavedChanges={unsavedChanges}
|
||||
onSaveAndExit={onSaveAndExit}
|
||||
areLogsVisible={areLogsVisible}
|
||||
areLogsEnabled={areLogsEnabled}
|
||||
onToggleLogsVisibility={onToggleLogsVisibility}
|
||||
|
@ -57,6 +57,7 @@ const {arrayOf, bool, func, shape, string} = PropTypes
|
|||
Tickscript.propTypes = {
|
||||
logs: arrayOf(shape()).isRequired,
|
||||
onSave: func.isRequired,
|
||||
onExit: func.isRequired,
|
||||
source: shape({
|
||||
id: string,
|
||||
}),
|
||||
|
@ -74,6 +75,7 @@ Tickscript.propTypes = {
|
|||
onChangeType: func.isRequired,
|
||||
onChangeID: func.isRequired,
|
||||
isNewTickscript: bool.isRequired,
|
||||
unsavedChanges: bool,
|
||||
}
|
||||
|
||||
export default Tickscript
|
||||
|
|
|
@ -7,7 +7,7 @@ import ConfirmButton from 'src/shared/components/ConfirmButton'
|
|||
const TickscriptHeader = ({
|
||||
task: {id},
|
||||
onSave,
|
||||
onSaveAndExit,
|
||||
onExit,
|
||||
unsavedChanges,
|
||||
areLogsVisible,
|
||||
areLogsEnabled,
|
||||
|
@ -48,12 +48,12 @@ const TickscriptHeader = ({
|
|||
? <ConfirmButton
|
||||
text="Exit"
|
||||
confirmText="Discard unsaved changes?"
|
||||
confirmAction={onSaveAndExit}
|
||||
confirmAction={onExit}
|
||||
/>
|
||||
: <button
|
||||
className="btn btn-default btn-sm"
|
||||
title="Return to Alert Rules Page"
|
||||
onClick={onSaveAndExit}
|
||||
onClick={onExit}
|
||||
>
|
||||
Exit
|
||||
</button>}
|
||||
|
@ -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
|
||||
|
|
|
@ -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({
|
||||
|
|
Loading…
Reference in New Issue