@@ -15,7 +15,11 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
1515import { faTimes } from '@fortawesome/free-solid-svg-icons/faTimes' ;
1616import { faPlus } from '@fortawesome/free-solid-svg-icons/faPlus' ;
1717import validator from '@rjsf/validator-ajv8' ;
18- import type { ArrayFieldTemplateProps , UiSchema } from '@rjsf/utils' ;
18+ import type {
19+ ArrayFieldTemplateProps ,
20+ ArrayFieldItemTemplateProps ,
21+ UiSchema ,
22+ } from '@rjsf/utils' ;
1923import {
2024 Box ,
2125 Button ,
@@ -30,81 +34,89 @@ import type { IChangeEvent } from '@rjsf/core';
3034import { DialogWithCloseButton } from '../../../DialogWithCloseButton' ;
3135import { RJSForm } from '../../../Form' ;
3236
33- const ArrayFieldTemplate : React . FC < ArrayFieldTemplateProps > = ( {
37+ const ArrayFieldTemplate = ( {
3438 items,
3539 canAdd,
3640 onAddClick,
37- } ) => {
41+ } : ArrayFieldTemplateProps ) => {
3842 const { t } = useTranslation ( ) ;
3943 return (
40- < >
41- { items ?. map ( ( element , index ) => {
42- return (
43- < Box key = { element . key } >
44- { index > 0 && (
45- < Typography
46- sx = { {
47- width : 'calc(100% - 50px)' ,
48- textAlign : 'center' ,
49- fontWeight : 'bold' ,
50- } }
51- >
52- { t ( 'commons.or' ) . toUpperCase ( ) }
53- </ Typography >
54- ) }
55- < Box
56- sx = { {
57- display : 'flex' ,
58- '& .form-group.field.field-object' : {
59- display : 'flex' ,
60- flex : 1 ,
61- } ,
62- '& label' : {
63- display : 'none' ,
64- } ,
65- // This is necessary to remove the gap of Tags label. RJSF render nested objects with multi label levels.
66- '.MuiGrid-root > .form-group.field.field-object > .MuiFormControl-root > .MuiGrid-root.MuiGrid-container.MuiGrid-spacing-xs-2' :
67- {
68- marginTop : '-8px!important' ,
69- } ,
70- } }
44+ < Box className = "array" >
45+ { items }
46+ { canAdd && (
47+ < Box className = "rjsf-array-item-add" >
48+ < Button
49+ aria-label = { t ( 'aria_labels.add_filter_in_or' ) }
50+ variant = "text"
51+ color = "primary"
52+ onClick = { onAddClick }
53+ startIcon = { < FontAwesomeIcon icon = { faPlus } /> }
54+ >
55+ { t ( 'actions.add_alternative' ) }
56+ </ Button >
57+ </ Box >
58+ ) }
59+ </ Box >
60+ ) ;
61+ } ;
62+
63+ const ArrayFieldItemTemplate = ( {
64+ children,
65+ buttonsProps,
66+ itemKey,
67+ index,
68+ } : ArrayFieldItemTemplateProps ) => {
69+ const { t } = useTranslation ( ) ;
70+ return (
71+ < Box key = { itemKey } className = "rjsf-array-item" >
72+ { index > 0 && (
73+ < Typography
74+ sx = { {
75+ width : 'calc(100% - 50px)' ,
76+ textAlign : 'center' ,
77+ fontWeight : 'bold' ,
78+ } }
79+ >
80+ { t ( 'commons.or' ) . toUpperCase ( ) }
81+ </ Typography >
82+ ) }
83+ < Box
84+ sx = { {
85+ display : 'flex' ,
86+ '& .rjsf-field.rjsf-field-object' : {
87+ display : 'flex' ,
88+ flex : 1 ,
89+ } ,
90+ '& label' : {
91+ display : 'none' ,
92+ } ,
93+ // This is necessary to remove the gap of Tags label. RJSF render nested objects with multi label levels.
94+ '.MuiGrid-root > .rjsf-field.rjsf-field-object > .MuiFormControl-root > .MuiGrid-root.MuiGrid-container.MuiGrid-spacing-xs-2' :
95+ {
96+ marginTop : '-8px!important' ,
97+ } ,
98+ } }
99+ >
100+ { children }
101+ < Box
102+ display = "flex"
103+ width = "50px"
104+ alignItems = "center"
105+ justifyContent = "center"
106+ >
107+ { index !== 0 && (
108+ < IconButton
109+ aria-label = { t ( 'actions.remove_filter' ) }
110+ onClick = { buttonsProps . onRemoveItem }
111+ sx = { { mt : 2 } }
112+ className = "rjsf-array-item-remove"
71113 >
72- { element . children }
73- < Box
74- display = "flex"
75- width = "50px"
76- alignItems = "center"
77- justifyContent = "center"
78- >
79- { index !== 0 && (
80- < IconButton
81- aria-label = { t ( 'actions.remove_filter' ) }
82- // @ts -expect-error The typing of the current version of @rjsf/utils does not show that `onDropIndexClick` exists, even though it does
83- onClick = { element . onDropIndexClick ( element . index ) }
84- sx = { { mt : 2 } }
85- >
86- < FontAwesomeIcon icon = { faTimes } />
87- </ IconButton >
88- ) }
89- </ Box >
90- </ Box >
91- < Box display = "flex" my = { 2 } >
92- { canAdd && index === items . length - 1 && (
93- < Button
94- aria-label = { t ( 'aria_labels.add_filter_in_or' ) }
95- variant = "text"
96- color = "primary"
97- onClick = { onAddClick }
98- startIcon = { < FontAwesomeIcon icon = { faPlus } /> }
99- >
100- { t ( 'actions.add_alternative' ) }
101- </ Button >
102- ) }
103- </ Box >
104- </ Box >
105- ) ;
106- } ) }
107- </ >
114+ < FontAwesomeIcon icon = { faTimes } />
115+ </ IconButton >
116+ ) }
117+ </ Box >
118+ </ Box >
119+ </ Box >
108120 ) ;
109121} ;
110122
@@ -286,6 +298,7 @@ export const FiltersDialog = ({
286298
287299 const uiSchema = {
288300 'ui:ArrayFieldTemplate' : ArrayFieldTemplate ,
301+ 'ui:ArrayFieldItemTemplate' : ArrayFieldItemTemplate ,
289302 items : {
290303 'ui:grid' : {
291304 field : { size : { xs : 4 , sm : 4 } } ,
0 commit comments