@@ -5,26 +5,70 @@ import FieldTemplate from "../formComponents/FieldTemplate";
55import { _validate } from "../utils" ;
66import { useSelector } from "react-redux" ;
77import CustomizationContext from "../../contexts/CustomizationContext" ;
8- import { useContext } from "react" ;
8+ import { useContext , useMemo } from "react" ;
99
1010const SchemaTree = ( ) => {
1111 const schema = useSelector ( ( state ) => state . schemaWizard . current . schema ) ;
1212 const uiSchema = useSelector ( ( state ) => state . schemaWizard . current . uiSchema ) ;
1313
1414 const customizationContext = useContext ( CustomizationContext ) ;
1515
16+ // Memoize removeUiWidget function so it's not recreated on every render
17+ const removeUiWidget = useMemo ( ( ) => {
18+ return function removeUiWidgetRecursive ( _obj ) {
19+ // Handle null/undefined
20+ if ( _obj == null ) {
21+ return _obj ;
22+ }
23+
24+ // Handle arrays - recursively process each element
25+ if ( Array . isArray ( _obj ) ) {
26+ return _obj . map ( ( item ) => removeUiWidgetRecursive ( item ) ) ;
27+ }
28+
29+ // Handle objects
30+ if ( typeof _obj === "object" ) {
31+ const obj = { } ;
32+ for ( const key in _obj ) {
33+ // Skip the ui:widget property if its value is "table"
34+ if ( key === "ui:widget" && _obj [ key ] === "table" ) {
35+ continue ;
36+ }
37+ // Recursively process nested objects/arrays
38+ obj [ key ] = removeUiWidgetRecursive ( _obj [ key ] ) ;
39+ }
40+ return obj ;
41+ }
42+
43+ // Return primitive values as-is
44+ return _obj ;
45+ } ;
46+ } , [ ] ) ;
47+
48+ // Memoize transformed schema - only recompute when schema changes
49+ const transformedSchema = useMemo (
50+ ( ) => customizationContext . transformSchema ( schema ) ,
51+ [ customizationContext , schema ] ,
52+ ) ;
53+
54+ // Memoize cleaned uiSchema - only recompute when uiSchema changes
55+ const cleanedUiSchema = useMemo (
56+ ( ) => removeUiWidget ( uiSchema ) ,
57+ [ removeUiWidget , uiSchema ] ,
58+ ) ;
59+
1660 return (
1761 < Form
18- schema = { customizationContext . transformSchema ( schema ) }
19- uiSchema = { uiSchema }
62+ schema = { transformedSchema }
63+ uiSchema = { cleanedUiSchema }
2064 formData = { { } }
2165 ObjectFieldTemplate = { ObjectFieldTemplate }
2266 ArrayFieldTemplate = { ArrayFieldTemplate }
2367 FieldTemplate = { FieldTemplate }
2468 onChange = { ( ) => { } }
2569 validate = { _validate }
2670 liveValidate
27- formContext = { { schema : [ ] , uiSchema : [ ] } }
71+ formContext = { { tree : true , schema : [ ] , uiSchema : [ ] } }
2872 className = "schemaTree"
2973 />
3074 ) ;
0 commit comments