All files / src/hocs/components/actions utils.js

84.62% Statements 11/13
78.57% Branches 11/14
80% Functions 4/5
84.62% Lines 11/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34        1x     4x 4x     4x       4x 2x 3x     2x             1x 1x     1x    
import {
  forEach
} from 'lodash';
export function flattenItems(items) {
  const fields = [];
 
  function loop(item, keyName = '') {
    Eif (item.keyName) {
      keyName = `${keyName}${keyName ? '.' : ''}${item.keyName}`;
    }
 
    Iif (item.items && !item.items.type) {
      forEach(item.items, item => {
        loop(item, keyName);
      });
    } else if (item.items && item.items.type && item.items.items) {
      forEach(item.items.items, item => {
        loop(item, keyName);
      })
    } else {
      fields.push({
        ...item,
        keyName
      });
    }
  }
 
  forEach(items, item => {
    loop(item, '');
  });
 
  return fields;
}