Resolve a ``_children_props`` path expression to child Components. Mirrors the dash-renderer's path parsing in ``DashWrapper.tsx``. Supports: - ``"children"`` — simple prop - ``"control_groups[].children"`` — array, then sub-prop per element - ``"insights.title"`` — nested objec
(component: Any, prop_path: str)
| 64 | |
| 65 | |
| 66 | def get_children(component: Any, prop_path: str) -> list[Component]: |
| 67 | """Resolve a ``_children_props`` path expression to child Components. |
| 68 | |
| 69 | Mirrors the dash-renderer's path parsing in ``DashWrapper.tsx``. |
| 70 | Supports: |
| 71 | - ``"children"`` — simple prop |
| 72 | - ``"control_groups[].children"`` — array, then sub-prop per element |
| 73 | - ``"insights.title"`` — nested object prop |
| 74 | """ |
| 75 | clean_path = prop_path.replace("[]", "").replace("{}", "") |
| 76 | |
| 77 | if "." not in prop_path: |
| 78 | return _collect_components(getattr(component, clean_path, None)) |
| 79 | |
| 80 | parts = prop_path.split(".") |
| 81 | array_idx = next((i for i, p in enumerate(parts) if "[]" in p), len(parts)) |
| 82 | front = [p.replace("[]", "").replace("{}", "") for p in parts[: array_idx + 1]] |
| 83 | back = [p.replace("{}", "") for p in parts[array_idx + 1 :]] |
| 84 | |
| 85 | node = _resolve_path(component, front) |
| 86 | if node is None: |
| 87 | return [] |
| 88 | |
| 89 | if back and isinstance(node, (list, tuple)): |
| 90 | results: list[Component] = [] |
| 91 | for element in node: |
| 92 | child = _resolve_path(element, back) |
| 93 | results.extend(_collect_components(child)) |
| 94 | return results |
| 95 | |
| 96 | return _collect_components(node) |
| 97 | |
| 98 | |
| 99 | def _resolve_path(node: Any, keys: list[str]) -> Any: |
no test coverage detected
searching dependent graphs…