ui: Don't show duplicate services in the intentions form dropdown (#8133)

* Add uniq-by helper
* Pass unique services through to intentions form
* Add acceptance test
This commit is contained in:
John Cowen 2020-06-17 14:11:40 +01:00 committed by GitHub
parent d31691dc87
commit 61433fabb4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 3 deletions

View File

@ -0,0 +1,13 @@
import { helper } from '@ember/component/helper';
import { isEmpty } from '@ember/utils';
import { A as emberArray } from '@ember/array';
export function uniqBy([byPath, array]) {
if (isEmpty(byPath)) {
return [];
}
return emberArray(array).uniqBy(byPath);
}
export default helper(uniqBy);

View File

@ -39,7 +39,7 @@
<BlockSlot @name="content">
<ConsulIntentionForm
@item={{item}}
@services={{services}}
@services={{uniq-by 'Name' services}}
@nspaces={{nspaces}}
@ondelete={{action "route" "delete"}}
@onsubmit={{action "route" (if item.isNew "create" "update")}}

View File

@ -8,9 +8,9 @@ Feature: dc / intentions / filtered-select: Intention Service Select Dropdowns
And 4 service models from yaml
---
- Name: service-0
Kind: consul
Kind: ~
- Name: service-1
Kind: consul
Kind: ~
- Name: service-2
Kind: connect-proxy
- Name: service-3
@ -32,3 +32,28 @@ Feature: dc / intentions / filtered-select: Intention Service Select Dropdowns
| source |
| destination |
---------------
Scenario: Opening the [Name] dropdown with 2 services with the same name from different nspaces
Given 1 datacenter model with the value "datacenter"
And 2 service models from yaml
---
- Name: service-0
Kind: ~
- Name: service-0
Namespace: nspace
Kind: ~
---
When I visit the intention page for yaml
---
dc: datacenter
intention: intention
---
Then the url should be /datacenter/intentions/intention
And I click "[data-test-[Name]-element] .ember-power-select-trigger"
Then I see the text "* (All Services)" in ".ember-power-select-option:nth-last-child(2)"
Then I see the text "service-0" in ".ember-power-select-option:last-child"
Where:
---------------
| Name |
| source |
| destination |
---------------