2023-03-14 13:18:55 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
2023-08-11 13:12:13 +00:00
|
|
|
* SPDX-License-Identifier: BUSL-1.1
|
2023-03-14 13:18:55 +00:00
|
|
|
*/
|
|
|
|
|
2020-12-14 14:25:33 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|