fleet/frontend/pages/hosts/ManageHostsPage/helpers.js
Zachary Wasserman 4561aedd1f Fix inconsistencies with sidebar label counts (#1328)
- Fix a bug that caused hosts between 24 and 25 hours old to appear new
- Ensure "platform" labels use the count provided by the server

Fixes #1270
2017-03-01 10:50:09 -08:00

29 lines
715 B
JavaScript

import { filter, includes } from 'lodash';
import moment from 'moment';
const filterHosts = (hosts, label) => {
if (!label) {
return hosts;
}
if (label.type === 'status' && label.id === 'new') {
return filter(hosts, h => moment().diff(moment(h.created_at)) <= moment.duration(24, 'hours'));
}
const { host_ids: hostIDs, slug, type } = label;
switch (type) {
case 'all':
return hosts;
case 'status':
return filter(hosts, { status: slug });
case 'platform': // Platform labels are implemented the same as custom labels
case 'custom':
return filter(hosts, h => includes(hostIDs, h.id));
default:
return hosts;
}
};
export default { filterHosts };