(childList: IContextMenuItemProps[], groupId: string, index = 0)
| 27 | |
| 28 | export const flatContextData = (contextData: Partial<IContextMenuItemProps>[], text2Id = false): IContextMenuItemProps[] => { |
| 29 | const dfs = (childList: IContextMenuItemProps[], groupId: string, index = 0) => { |
| 30 | const res: IContextMenuItemProps[] = []; |
| 31 | const childGroupId = `${groupId}_${index}`; |
| 32 | for (let i = 0; i < childList.length; i++) { |
| 33 | const item = childList[i]; |
| 34 | |
| 35 | if (!item) continue; |
| 36 | |
| 37 | const resultItem = { |
| 38 | ...item, |
| 39 | extraElement: item.shortcutKey, |
| 40 | groupId: childGroupId, |
| 41 | label: item.text, |
| 42 | key: generateKey(item, text2Id, index), |
| 43 | }; |
| 44 | res.push( |
| 45 | item.children |
| 46 | ? { |
| 47 | ...resultItem, |
| 48 | children: dfs(item.children, childGroupId, index + 1), |
| 49 | } |
| 50 | : resultItem, |
| 51 | ); |
| 52 | } |
| 53 | return res; |
| 54 | }; |
| 55 | |
| 56 | let groupId = 0; |
| 57 | return contextData |
no test coverage detected