Be the async await change

pull/1717/head
Andrew Watkins 2017-07-12 16:14:06 -07:00
parent 3f0e78e256
commit beb04bd3f6
2 changed files with 22 additions and 20 deletions

View File

@ -38,25 +38,27 @@ class KapacitorRulePage extends Component {
})
}
getKapacitorConfig(kapacitor)
.then(({data: {sections}}) => {
const enabledAlerts = Object.keys(sections).filter(section => {
return (
_.get(
sections,
[section, 'elements', '0', 'options', 'enabled'],
false
) && ALERTS.includes(section)
)
})
this.setState({kapacitor, enabledAlerts})
try {
const {data: {sections}} = await getKapacitorConfig(kapacitor)
const enabledAlerts = Object.keys(sections).filter(section => {
return (
_.get(
sections,
[section, 'elements', '0', 'options', 'enabled'],
false
) && ALERTS.includes(section)
)
})
.catch(() => {
addFlashMessage({
type: 'error',
text: 'There was a problem communicating with Kapacitor',
})
this.setState({kapacitor, enabledAlerts})
} catch (error) {
addFlashMessage({
type: 'error',
text: 'There was a problem communicating with Kapacitor',
})
console.error(error)
throw error
}
}
render() {

View File

@ -143,11 +143,11 @@ export function updateKapacitor({
})
}
export function getKapacitorConfig(kapacitor) {
return kapacitorProxy(kapacitor, 'GET', '/kapacitor/v1/config', '')
export const getKapacitorConfig = async kapacitor => {
return await kapacitorProxy(kapacitor, 'GET', '/kapacitor/v1/config', '')
}
export function getKapacitorConfigSection(kapacitor, section) {
export const getKapacitorConfigSection = (kapacitor, section) => {
return kapacitorProxy(kapacitor, 'GET', `/kapacitor/v1/config/${section}`, '')
}