open-consul/ui/packages/consul-ui/app/helpers/policy/group.js

30 lines
701 B
JavaScript
Raw Normal View History

2020-06-17 09:25:54 +00:00
import { helper } from '@ember/component/helper';
import { get } from '@ember/object';
import { MANAGEMENT_ID } from 'consul-ui/models/policy';
2020-06-17 09:25:54 +00:00
export default helper(function policyGroup([items] /*, hash*/) {
return items.reduce(
function(prev, item) {
let group;
switch (true) {
case get(item, 'ID') === MANAGEMENT_ID:
group = 'management';
break;
case get(item, 'template') !== '':
group = 'identities';
break;
default:
group = 'policies';
break;
}
prev[group].push(item);
return prev;
},
{
management: [],
identities: [],
policies: [],
}
);
});