| 117 | } |
| 118 | |
| 119 | export function pathToDescendant( |
| 120 | ancestor: string, |
| 121 | descendant: string |
| 122 | ): string | undefined { |
| 123 | const ancestorPath = new JSONHeroPath(ancestor); |
| 124 | const descendantPath = new JSONHeroPath(descendant); |
| 125 | |
| 126 | const ancestorPathComponents = ancestorPath.components.map((component) => |
| 127 | component.toString() |
| 128 | ); |
| 129 | const descendantPathComponents = descendantPath.components.map((component) => |
| 130 | component.toString() |
| 131 | ); |
| 132 | |
| 133 | const pathComponents = []; |
| 134 | |
| 135 | for (let index = 0; index < descendantPathComponents.length; index++) { |
| 136 | const descendantPathComponent = descendantPathComponents[index]; |
| 137 | |
| 138 | if (ancestorPathComponents.length <= index) { |
| 139 | pathComponents.push(descendantPathComponent); |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | return pathComponents.join("."); |
| 144 | } |
| 145 | |
| 146 | //Given the previous path and where the selection is, we calculate the new path |
| 147 | //This allows us to keep the deepest item possible still visible whilst navigating around |