export function getFiltersWithUsedComponents({ filters = [], componentsById = {} }) {
  const componentsByFilterId = {};

  Object.keys(componentsById).forEach((id) => {
    const component = componentsById[id];
    const { parent, name, filters = [] } = component;
    const componentInfo = {
      id: +id,
      name,
      parent
    };

    filters.forEach((d) => {
      if (componentsByFilterId[d.id]) {
        componentsByFilterId[d.id].push(componentInfo);
      } else {
        componentsByFilterId[d.id] = [componentInfo];
      }
    });
  });

  const filtersWithUsedComponents = filters.map((d: any) => {
    return {
      ...d,
      usedComponents: componentsByFilterId[d.id]
    };
  });

  return filtersWithUsedComponents;
}
