function findParents()

in packages/rc-components/rc-console-menu/src/RoutableMenu.tsx [315:333]


function findParents(
  activeKey: string,
  items: IItemDescriptor[],
  currentParents: IItemDescriptor[],
): IItemDescriptor[] | null {
  for (const item of items) {
    if (item.key === activeKey) {
      return currentParents;
    }
    if (Array.isArray(item.items)) {
      const found = findParents(activeKey, item.items, [
        ...currentParents,
        item,
      ]);
      if (found) return found;
    }
  }
  return null;
}