Fix inability to add kapacitor from source page

The kapacitors array on source was not yet defined.  So, I added
a default empty array to the kapacitors key off of source.  Also,
cleaned up some logic regarding the duplication of kapacitor names.
pull/10616/head
Andrew Watkins 2017-08-29 16:11:43 -07:00
parent 60d3433405
commit 6de0c0a5c0
1 changed files with 10 additions and 3 deletions

View File

@ -68,11 +68,18 @@ class KapacitorPage extends Component {
handleSubmit(e) {
e.preventDefault()
const {addFlashMessage, source, params, router} = this.props
const {
addFlashMessage,
source,
source: {kapacitors = []},
params,
router,
} = this.props
const {kapacitor} = this.state
const kapNames = source.kapacitors.map(k => k.name)
if (kapNames.includes(kapacitor.name)) {
const isNameTaken = kapacitors.some(k => k.name === kapacitor.name)
if (isNameTaken) {
addFlashMessage({
type: 'error',
text: `There is already a Kapacitor configuration named "${kapacitor.name}"`,