MCPcopy
hub / github.com/baidu/amis / convertFieldSetTabs2Controls

Function convertFieldSetTabs2Controls

packages/amis/src/compat.ts:37–89  ·  view source on GitHub ↗
(schema: any)

Source from the content-addressed store, hash-verified

35});
36
37function convertFieldSetTabs2Controls(schema: any) {
38 const toUpdate: any = {};
39 let flag = false;
40
41 toUpdate.controls = Array.isArray(schema.controls)
42 ? schema.controls.concat()
43 : [];
44 toUpdate.controls = toUpdate.controls.map((control: any) => {
45 if (Array.isArray(control)) {
46 let converted = convertFieldSetTabs2Controls({
47 type: 'group',
48 controls: control
49 });
50
51 if (converted !== control) {
52 flag = true;
53 }
54
55 return converted;
56 }
57 return control;
58 });
59
60 schema.fieldSet &&
61 (Array.isArray(schema.fieldSet)
62 ? schema.fieldSet
63 : [schema.fieldSet]
64 ).forEach((fieldSet: any) => {
65 flag = true;
66 toUpdate.controls.push({
67 ...convertFieldSetTabs2Controls(fieldSet),
68 type: 'fieldSet',
69 collapsable: schema.collapsable
70 });
71 });
72
73 schema.tabs &&
74 (flag = true) &&
75 toUpdate.controls.push({
76 type: 'tabs',
77 tabs: schema.tabs.map((tab: any) => convertFieldSetTabs2Controls(tab))
78 });
79
80 if (flag) {
81 schema = {
82 ...schema,
83 ...toUpdate
84 };
85 delete schema.fieldSet;
86 delete schema.tabs;
87 }
88 return schema;
89}
90
91// Form 中,把 fieldSet 和 tabs 转成 {type: 'fieldSet', controls: []}
92// 同时把数组用法转成 {type: 'group', controls: []}

Callers 1

compat.tsFile · 0.85

Calls 2

forEachMethod · 0.80
pushMethod · 0.65

Tested by

no test coverage detected