{"size": 1105, "ext": "js", "max_stars_repo_path": "app/scripts/helpers/dropdown-tree.js", "max_stars_repo_name": "resource-watch/prep-app", "max_stars_repo_stars_event_min_datetime": "2018-05-04T13:31:57.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-04T09:39:29.000Z", "max_issues_repo_path": "app/scripts/helpers/dropdown-tree.js", "max_issues_repo_name": "resource-watch/prep-app", "max_issues_repo_issues_event_min_datetime": "2016-07-22T10:48:09.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-08T22:44:21.000Z", "max_forks_repo_path": "app/scripts/helpers/dropdown-tree.js", "max_forks_repo_name": "resource-watch/prep-app", "max_forks_repo_forks_event_min_datetime": "2016-08-11T15:35:54.000Z", "max_forks_repo_forks_event_max_datetime": "2017-10-27T18:42:16.000Z"}
{"max_stars_count": 4, "max_issues_count": 31, "max_forks_count": 6, "avg_line_length": 26.9512195122, "max_line_length": 87, "alphanum_fraction": 0.6443438914}
/**
   * Sets checked values for selector based on previous one chosen.
   *
   * @param {Object} tree used to populate selectors. Contains all options available.
   * @param {Object[]} elements Contains values to be selected in the data tree.
   */
export const selectElementsFromTree = (tree = {}, elements = [], deselect = false) => {
  let found = false;
  for (let i = 0; i < elements.length && !found; i++) {
    if (elements[i] === tree.value) {
      Object.assign(tree, { checked: !deselect });
      found = true;
    }
  }

  if ((tree.children || []).length) {
    tree.children.forEach((child) => {
      selectElementsFromTree(child, elements, deselect);
    });
  }
};

export const getSelectedElements = (tree = {}, filters) => {
  const newTree = Object.assign({}, tree);

  Object.keys(filters).forEach((filterKey) => {
    const filterValues = filters[filterKey];
    const dataTree = newTree[filterKey] || [];

    dataTree.forEach(child => selectElementsFromTree(child, filterValues));
  });

  return newTree;
};

export default {
  selectElementsFromTree,
  getSelectedElements
};

