| 1 | /** |
| 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | * |
| 4 | * This source code is licensed under the MIT license found in the |
| 5 | * LICENSE file in the root directory of this source tree. |
| 6 | * |
| 7 | * @flow |
| 8 | */ |
| 9 | |
| 10 | /** |
| 11 | * Converts nested hooks paths to the format expected by the backend. |
| 12 | * e.g. [''] => [''] |
| 13 | * e.g. [1, 'value', ...] => [...] |
| 14 | * e.g. [2, 'subhooks', 1, 'value', ...] => [...] |
| 15 | * e.g. [1, 'subhooks', 3, 'subhooks', 2, 'value', ...] => [...] |
| 16 | */ |
| 17 | export function parseHookPathForEdit( |
| 18 | path: Array<string | number>, |
| 19 | ): Array<string | number> { |
| 20 | let index = 0; |
| 21 | for (let i = 0; i < path.length; i++) { |
| 22 | if (path[i] === 'value') { |
| 23 | index = i + 1; |
| 24 | break; |
| 25 | } |
| 26 | } |
| 27 | return path.slice(index); |
| 28 | } |