Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit73adc1a

Browse files
author
FalkWolsky
committed
Enabling Single-Level & Multi-Level JSON Schema Form definitions
1 parent39b0370 commit73adc1a

File tree

1 file changed

+89
-19
lines changed

1 file changed

+89
-19
lines changed

‎client/packages/lowcoder/src/comps/comps/jsonSchemaFormComp/ObjectFieldTemplate.tsx‎

Lines changed: 89 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
importReact,{useEffect,useRef,useState}from"react";
2-
import{Row,Col}from'antd';
2+
import{Row,Col,Tabs}from'antd';
33
import{ObjectFieldTemplateProps,getTemplate,getUiOptions,descriptionId,titleId,canExpand}from'@rjsf/utils';
44
import{ConfigConsumer}from'antd/es/config-provider/context';
55
import{useContainerWidth}from"./jsonSchemaFormComp";
66
importstyledfrom"styled-components";
7+
importTabPanefrom"antd/es/tabs/TabPane";
8+
import{is}from"core-js/core/object";
79

810
constDESCRIPTION_COL_STYLE={
911
paddingBottom:'8px',
@@ -98,6 +100,67 @@ const ObjectFieldTemplate = (props: ObjectFieldTemplateProps) => {
98100
returnfieldName ?registry.fields[fieldName] :undefined;
99101
};
100102

103+
constrenderSingleLevel=(level :number)=>{
104+
return(
105+
<Rowgutter={rowGutter}>
106+
{properties.map((prop)=>{
107+
constisArray=prop.content.props.schema.type==="array";
108+
constcolSpan=isArray
109+
?{span:24}
110+
:calculateResponsiveColSpan(uiSchema?.[prop.name]||{});
111+
112+
return(
113+
<Colkey={prop.name}{...colSpan}>
114+
{/* Render legend for array fields */}
115+
{isArray&&(
116+
<><br/><legendstyle={getLegendStyle(level)}>
117+
{prop.content.props.schema.title}
118+
</legend></>
119+
)}
120+
{/* Render field content */}
121+
{prop.content}
122+
</Col>
123+
);
124+
})}
125+
</Row>
126+
);
127+
};
128+
129+
constrenderCategorization=(elements:any[])=>{
130+
return(
131+
<Tabs>
132+
{elements.map((category,index)=>(
133+
<TabPanetab={category.label||`Category${index+1}`}key={category.label||index}>
134+
{category.elements.map((element:any,elementIndex:number)=>{
135+
if(element.type==="HorizontalLayout"){
136+
return(
137+
<Rowkey={elementIndex}gutter={rowGutter}>
138+
{element.elements.map((field:any,fieldIndex:number)=>{
139+
constcolSpan=calculateResponsiveColSpan(field.uiSchema);
140+
return(
141+
<Colkey={fieldIndex}{...colSpan}>
142+
{properties.find((prop)=>prop.name===field.scope.replace("#/properties/",""))
143+
?.content}
144+
</Col>
145+
);
146+
})}
147+
</Row>
148+
);
149+
}
150+
151+
if(element.type==="Control"){
152+
returnproperties.find((prop)=>prop.name===element.scope.replace("#/properties/",""))
153+
?.content;
154+
}
155+
156+
returnnull;
157+
})}
158+
</TabPane>
159+
))}
160+
</Tabs>
161+
);
162+
};
163+
101164
constrenderFieldsFromSection=(section:any,level:number=0)=>{
102165
const{ formData, schema, uiSchema}=section.content.props;
103166

@@ -192,31 +255,38 @@ const ObjectFieldTemplate = (props: ObjectFieldTemplateProps) => {
192255
};
193256

194257
constrenderSections=(properties:any[],level:number)=>{
258+
259+
constisMultiLevel=properties.some(
260+
(prop)=>prop.content.props.schema?.type==="object"&&prop.content.props.schema?.properties
261+
);
262+
263+
if(!isMultiLevel){
264+
returnrenderSingleLevel(level);
265+
}
266+
195267
returnproperties.map((section)=>{
196268
constschema=section.content.props.schema;
197269
constisArray=typeofsection.content.props.index==='number';
198270
constsectionTitle=schema.title||section.name;
199271

200-
console.log("Section",sectionTitle,isArray,section);
201-
202272
return(
203-
<Row
204-
key={section.name}
205-
gutter={rowGutter}
206-
style={{marginBottom:"16px",width:"100%"}}
207-
>
208-
<Colspan={24}>
209-
<fieldset>
210-
{/* Always render the legend for the section itself */}
211-
{level===0&&!isArray ?(
212-
<legendstyle={getLegendStyle(level)}>{sectionTitle}</legend>
213-
) :null}
273+
<Row
274+
key={section.name}
275+
gutter={rowGutter}
276+
style={{marginBottom:"16px",width:"100%"}}
277+
>
278+
<Colspan={24}>
279+
<fieldset>
280+
{/* Always render the legend for the section itself */}
281+
{level===0&&!isArray ?(
282+
<legendstyle={getLegendStyle(level)}>{sectionTitle}</legend>
283+
) :null}
214284

215-
{/* Render the section content */}
216-
{renderFieldsFromSection(section,level+1)}
217-
</fieldset>
218-
</Col>
219-
</Row>
285+
{/* Render the section content */}
286+
{renderFieldsFromSection(section,level+1)}
287+
</fieldset>
288+
</Col>
289+
</Row>
220290
);
221291
});
222292
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp