open-consul/ui/packages/consul-ui/app/helpers/collection.js
John Cowen 13fb1445c0
ui: Add External Sources Filter to Node > Service Instances (#9368)
* Add service collections to get all ExternalServices

* Add a basic collection helper

* Use the collections to get all ExternalSources

* Remove old Controllers
2020-12-14 14:25:33 +00:00

24 lines
775 B
JavaScript

import Helper from '@ember/component/helper';
import { get } from '@ember/object';
import { Collection as Service } from 'consul-ui/models/service';
import { Collection as ServiceInstance } from 'consul-ui/models/service-instance';
const collections = {
service: Service,
'service-instance': ServiceInstance,
};
class EmptyCollection {}
export default class CollectionHelper extends Helper {
compute([collection, str], hash) {
if (collection.length > 0) {
// TODO: Looksee if theres ever going to be a public way to get this
const modelName = get(collection, 'firstObject')._internalModel.modelName;
const Collection = collections[modelName];
return new Collection(collection);
} else {
return new EmptyCollection();
}
}
}