From b73c701840678ff23cb4331f0ff9f4c05733a816 Mon Sep 17 00:00:00 2001 From: deniz kusefoglu Date: Tue, 16 Jan 2018 18:12:18 -0800 Subject: [PATCH] Convert promise pattern to async await --- ui/src/kapacitor/components/AlertTabs.js | 51 ++++++++++++------------ 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/ui/src/kapacitor/components/AlertTabs.js b/ui/src/kapacitor/components/AlertTabs.js index 45cc33d61..30a2462f4 100644 --- a/ui/src/kapacitor/components/AlertTabs.js +++ b/ui/src/kapacitor/components/AlertTabs.js @@ -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}.`, }) + } } }