Convert promise pattern to async await

pull/2708/head
deniz kusefoglu 2018-01-16 18:12:18 -08:00
parent 443fc75766
commit b73c701840
1 changed files with 26 additions and 25 deletions

View File

@ -27,7 +27,6 @@ class AlertTabs extends Component {
super(props)
this.state = {
selectedHandler: 'smtp',
configSections: null,
}
}
@ -42,18 +41,17 @@ class AlertTabs extends Component {
}
}
refreshKapacitorConfig = kapacitor => {
getKapacitorConfig(kapacitor)
.then(({data: {sections}}) => {
this.setState({configSections: sections})
})
.catch(() => {
this.setState({configSections: null})
this.props.addFlashMessage({
type: 'error',
text: 'There was an error getting the Kapacitor config',
})
refreshKapacitorConfig = async kapacitor => {
try {
const {data: {sections}} = await getKapacitorConfig(kapacitor)
this.setState({configSections: sections})
} catch (error) {
this.setState({configSections: null})
this.props.addFlashMessage({
type: 'error',
text: 'There was an error getting the Kapacitor config',
})
}
}
getSection = (sections, section) => {
@ -72,23 +70,26 @@ class AlertTabs extends Component {
return this.getSection(sections, section)
}
handleSaveConfig = section => properties => {
handleSaveConfig = section => async properties => {
if (section !== '') {
const propsToSend = this.sanitizeProperties(section, properties)
updateKapacitorConfigSection(this.props.kapacitor, section, propsToSend)
.then(() => {
this.refreshKapacitorConfig(this.props.kapacitor)
this.props.addFlashMessage({
type: 'success',
text: `Alert configuration for ${section} successfully saved.`,
})
try {
await updateKapacitorConfigSection(
this.props.kapacitor,
section,
propsToSend
)
this.refreshKapacitorConfig(this.props.kapacitor)
this.props.addFlashMessage({
type: 'success',
text: `Alert configuration for ${section} successfully saved.`,
})
.catch(() => {
this.props.addFlashMessage({
type: 'error',
text: `There was an error saving the alert configuration for ${section}.`,
})
} catch (error) {
this.props.addFlashMessage({
type: 'error',
text: `There was an error saving the alert configuration for ${section}.`,
})
}
}
}