open-consul/ui-v2/app/controllers/dc/services/index.js
Kenia ed201c3f17 ui: Add and use ProxyFor to get the connected with proxy boolean (#7820)
* Add and use ProxyFor to get the `connected with proxy` boolean

* Fix up page-navigation test

* Upgrade to @hashicorp/consul-api-double@2.14.7
2020-05-12 17:14:55 +00:00

47 lines
1.2 KiB
JavaScript

import Controller from '@ember/controller';
import { get, computed } from '@ember/object';
import WithEventSource from 'consul-ui/mixins/with-event-source';
import WithSearching from 'consul-ui/mixins/with-searching';
export default Controller.extend(WithEventSource, WithSearching, {
queryParams: {
sortBy: 'sort',
s: {
as: 'filter',
},
},
init: function() {
this.searchParams = {
service: 's',
};
this._super(...arguments);
},
searchable: computed('services.[]', function() {
return get(this, 'searchables.service')
.add(this.services)
.search(this.terms);
}),
services: computed('items.[]', function() {
return this.items.filter(function(item) {
return item.Kind !== 'connect-proxy';
});
}),
proxies: computed('items.[]', function() {
const proxies = {};
this.items
.filter(function(item) {
return item.Kind === 'connect-proxy';
})
.forEach(item => {
// Iterating to cover the usecase of a proxy being
// used by more than one service
if (item.ProxyFor) {
item.ProxyFor.forEach(service => {
proxies[service] = true;
});
}
});
return proxies;
}),
});