flattenTree = (tree, parent = null, parentParentTypes = ["view"], result) => {
  if (!tree.children) return [];

  const children = tree.type === "pagedview" ? tree.children.slice(0, 1) : tree.children;

  for (const child of children) {
    /* Create a child without children and
    assign id of the parent for quick mathcing */
    const parentTypes = [...parentParentTypes, ...(parent?.type ? [parent?.type] : [])];
    const flatChild = { ...child, parent: parent?.id ?? null, parentTypes };

    delete flatChild.children;

    result.push(flatChild);

    if (Array.isArray(child.children)) {
      flattenTree(child, child, parentTypes, result);
    }
  }

  return result;
}
Flatten config tree for faster iterations and searches
@param {object} tree
@param {string | null;;} parent
@param {string[]} parentParentTypes
@param {object[]} result
@returns {object[]}