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

Function flatContextData

packages/datasheet/src/pc/utils/flat.ts:28–74  ·  view source on GitHub ↗
(contextData: Partial<IContextMenuItemProps>[], text2Id = false)

Source from the content-addressed store, hash-verified

26};
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
58 .map((v) => {
59 groupId += 1;
60 return v.map((item: IContextMenuItemProps, index: number) => {
61 if (!item) return;
62 const res = {
63 ...item,
64 extraElement: item.shortcutKey,
65 groupId: groupId.toString(),
66 label: item.text,
67 key: generateKey(item, text2Id, index),
68 };
69 return item.children ? { ...res, children: dfs(item.children, groupId.toString()) } : res;
70 });
71 })
72 .flat()
73 .filter((v) => v);
74};

Callers 15

GroupHeadMenuFunction · 0.90
field_menu.tsxFile · 0.90
RecordMenuFunction · 0.90
index.tsxFile · 0.90
FolderShowcaseFunction · 0.90
DingTalkDaFunction · 0.90
EdgeContextMenuFunction · 0.90
NodeContextMenuFunction · 0.90
WidgetListFunction · 0.90
InfoFunction · 0.90
LeftFunction · 0.90
ViewFunction · 0.90

Calls 5

generateKeyFunction · 0.85
dfsFunction · 0.70
filterMethod · 0.45
mapMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected