fleet/frontend/components/forms/fields/SelectTargetsDropdown/helpers.js
Mike Stone 8bb2a39d86 Improves re-usability of the SelectTargetsDropdown (#518)
* Improves re-usability of the SelectTargetsDropdown
2016-11-21 10:38:23 -05:00

18 lines
475 B
JavaScript

import { flatMap } from 'lodash';
const filterTarget = (targetType) => {
return (target) => {
return target.target_type === targetType ? [target.id] : [];
};
};
export const formatSelectedTargetsForApi = (selectedTargets) => {
const targets = selectedTargets || [];
const hosts = flatMap(targets, filterTarget('hosts'));
const labels = flatMap(targets, filterTarget('labels'));
return { hosts, labels };
};
export default { formatSelectedTargetsForApi };