1
- import React , { useContext , useState } from "react" ;
1
+ import React , { useContext , useEffect , useState } from "react" ;
2
2
import { useCollapsible , Collapsible } from "@docusaurus/theme-common" ;
3
3
import { ArrayFieldTemplateProps } from "@rjsf/utils" ;
4
4
import { BaseInputTemplate } from "@site/src/components/ParserOpenRPC/InteractiveBox/templates/BaseInputTemplate" ;
@@ -13,7 +13,9 @@ export const ArrayFieldTemplate = ({ items, canAdd, onAddClick, title, schema, f
13
13
const itemsType = schema ?. items ?. type ;
14
14
const isSimpleArray = itemsType === "string" || itemsType === "boolean" || itemsType === "number" || itemsType === "integer" ;
15
15
const addComplexArray = ( ) => {
16
- onAddClick ( ) ;
16
+ if ( formData ?. length === 0 ) {
17
+ onAddClick ( ) ;
18
+ }
17
19
setDrawerLabel ( title ) ;
18
20
setIsDrawerContentFixed ( true ) ;
19
21
setIsComplexArrayEditView ( true ) ;
@@ -26,6 +28,12 @@ export const ArrayFieldTemplate = ({ items, canAdd, onAddClick, title, schema, f
26
28
}
27
29
}
28
30
31
+ useEffect ( ( ) => {
32
+ if ( ! isComplexTypeView ) {
33
+ setIsComplexArrayEditView ( false ) ;
34
+ }
35
+ } , [ isComplexTypeView ] )
36
+
29
37
return (
30
38
< div >
31
39
< div className = { styles . tableRow } >
@@ -60,14 +68,14 @@ export const ArrayFieldTemplate = ({ items, canAdd, onAddClick, title, schema, f
60
68
< div className = { styles . tableComplexType } >
61
69
{ items . map ( ( { children, index, onDropIndexClick, hasRemove } ) => (
62
70
< div className = { styles . tableComplexTypeItem } key = { index } >
71
+ { hasRemove ?
72
+ < button className = { clsx ( styles . tableButton , styles . tableButtonAddNewArray ) } onClick = { onDropIndexClick ( index ) } >
73
+ < img src = "/img/icons/minus-icon.svg" alt = { `Add ${ title } ` } width = "16px" height = "16px" />
74
+ < span className = { styles . tableButtonAddArrayItemName } > Remove { title } </ span >
75
+ </ button > :
76
+ null
77
+ }
63
78
{ children }
64
- { hasRemove && (
65
- < span
66
- onClick = { onDropIndexClick ( index ) }
67
- className = { clsx ( styles . deleteIcon , styles . deleteIconComplex ) }
68
- >
69
- </ span >
70
- ) }
71
79
</ div >
72
80
) ) }
73
81
{ canAdd ?
0 commit comments