mirror of
https://github.com/empayre/fleet.git
synced 2024-11-07 17:28:54 +00:00
4561aedd1f
- 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
29 lines
715 B
JavaScript
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 };
|