MCPcopy Create free account
hub / github.com/apitable/apitable / dfs

Function dfs

packages/datasheet/src/pc/utils/flat.ts:29–54  ·  view source on GitHub ↗
(childList: IContextMenuItemProps[], groupId: string, index = 0)

Source from the content-addressed store, hash-verified

27
28export 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

Callers 1

flatContextDataFunction · 0.70

Calls 2

generateKeyFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected