From ea3e4a720a39ea2b00b70da60053dbfd51e47d0b Mon Sep 17 00:00:00 2001 From: John Cowen Date: Mon, 11 Jun 2018 15:53:12 +0100 Subject: [PATCH] Only offer to create a future service if the name doesn't already exist --- ui-v2/app/controllers/dc/intentions/edit.js | 3 +++ ui-v2/app/templates/dc/intentions/-form.hbs | 2 ++ 2 files changed, 5 insertions(+) diff --git a/ui-v2/app/controllers/dc/intentions/edit.js b/ui-v2/app/controllers/dc/intentions/edit.js index e20c7eccbe..df4bf8c53b 100644 --- a/ui-v2/app/controllers/dc/intentions/edit.js +++ b/ui-v2/app/controllers/dc/intentions/edit.js @@ -33,6 +33,9 @@ export default Controller.extend({ createNewLabel: function(term) { return `Use a future Consul Service called '${term}'`; }, + isUnique: function(term) { + return !get(this, 'items').findBy('Name', term); + }, change: function(e, value, _target) { // normalize back to standard event const target = e.target || { ..._target, ...{ name: e, value: value } }; diff --git a/ui-v2/app/templates/dc/intentions/-form.hbs b/ui-v2/app/templates/dc/intentions/-form.hbs index 37347b1212..739b212207 100644 --- a/ui-v2/app/templates/dc/intentions/-form.hbs +++ b/ui-v2/app/templates/dc/intentions/-form.hbs @@ -8,6 +8,7 @@ selected=SourceName searchPlaceholder='Type service name' buildSuggestion=(action 'createNewLabel') + showCreateWhen=(action "isUnique") oncreate=(action 'change' 'SourceName') onchange=(action 'change' 'SourceName') as |service search| }} @@ -27,6 +28,7 @@ selected=DestinationName searchPlaceholder='Type service name' buildSuggestion=(action 'createNewLabel') + showCreateWhen=(action "isUnique") oncreate=(action 'change' 'DestinationName') onchange=(action 'change' 'DestinationName') as |service| }}