@@ -22,6 +22,11 @@ import { ContentType } from '../ContentMapper/contentMapper.interface';
2222// Styles
2323import './index.scss' ;
2424
25+ interface ContentTypeOption {
26+ label : string ;
27+ value : string ;
28+ }
29+
2530/**
2631 * Component for displaying advanced properties.
2732 * @param props - The schema properties.
@@ -44,17 +49,23 @@ const AdvancePropertise = (props: SchemaProps) => {
4449 allowImagesOnly : props ?. value ?. AllowImagesOnly ,
4550 nonLocalizable : props ?. value ?. NonLocalizable ,
4651 embedObject : true ,
47- embedAssests : true
52+ embedAssests : true ,
53+ multiple : props ?. value ?. Multiple ,
54+ embedObjects : props ?. value ?. EmbedObjects
4855 } ) ;
4956
57+ const embedObjects = props ?. value ?. EmbedObjects ?. map ( ( item : string ) => ( {
58+ label : item ,
59+ value : item ,
60+ } ) ) ;
5061 // State for content types
5162 const [ contentTypes , setContentTypes ] = useState < ContentType [ ] > ( [ ] ) ;
52- const [ ctValue , setCTValue ] = useState ( null ) ;
63+ const [ ctValue , setCTValue ] = useState < ContentTypeOption [ ] | null > ( embedObjects ) ;
64+ const [ embedObjectslabels , setEmbedObjectsLabels ] = useState < string [ ] > ( props ?. value ?. EmbedObjects ) ;
5365
5466 useEffect ( ( ) => {
5567 fetchContentTypes ( '' ) ;
5668 } , [ ] )
57-
5869 /**
5970 * Fetches the content types list.
6071 * @param searchText - The search text.
@@ -77,16 +88,27 @@ const AdvancePropertise = (props: SchemaProps) => {
7788 [ field ] : ( event . target as HTMLInputElement ) ?. value
7889 } ) ) ;
7990
91+ const currentToggleStates = {
92+ ...toggleStates ,
93+ [ field ] : ( event . target as HTMLInputElement ) ?. value ,
94+ } ;
95+
8096 props ?. updateFieldSettings (
8197 props ?. rowId ,
8298 {
99+ ...props ?. value ,
83100 [ field ?. charAt ( 0 ) ?. toUpperCase ( ) + field ?. slice ( 1 ) ] : ( event . target as HTMLInputElement ) ?. value ,
84101 validationRegex : '' ,
85- Mandatory : false ,
86- Multiple : false ,
102+ MinChars : currentToggleStates ?. minChars ,
103+ MaxChars :currentToggleStates ?. maxChars ,
104+ Mandatory : currentToggleStates ?. mandatory ,
105+ Multiple : currentToggleStates ?. multiple ,
87106 Unique : false ,
88- NonLocalizable : false ,
89- EmbedObject : false
107+ NonLocalizable : currentToggleStates ?. nonLocalizable ,
108+ EmbedObject : currentToggleStates ?. embedObject ,
109+ EmbedObjects : embedObjectslabels ,
110+ MinRange : currentToggleStates ?. minRange ,
111+ MaxRange : currentToggleStates ?. maxRange ,
90112 } ,
91113 checkBoxChanged
92114 ) ;
@@ -103,22 +125,35 @@ const AdvancePropertise = (props: SchemaProps) => {
103125 ...prevStates ,
104126 [ field ] : value
105127 } ) ) ;
106-
128+ const currentToggleStates = {
129+ ...toggleStates ,
130+ [ field ] : value ,
131+ } ;
132+
107133 props ?. updateFieldSettings (
108134 props ?. rowId ,
109135 {
110136 [ field ?. charAt ( 0 ) ?. toUpperCase ( ) + field ?. slice ( 1 ) ] : value ,
111137 validationRegex : '' ,
112- Mandatory : false ,
113- Multiple : false ,
138+ Mandatory : currentToggleStates ?. mandatory ,
139+ Multiple : currentToggleStates ?. multiple ,
114140 Unique : false ,
115- NonLocalizable : false ,
116- EmbedObject : false
141+ NonLocalizable : currentToggleStates ?. nonLocalizable ,
142+ EmbedObject : currentToggleStates ?. embedObject ,
143+ EmbedObjects : embedObjectslabels
117144 } ,
118145 checkBoxChanged
119146 ) ;
120147 } ;
121148
149+ useEffect ( ( ) => {
150+
151+ if ( ctValue && Array . isArray ( ctValue ) ) {
152+ const labels = ctValue . map ( ( item ) => item . label ) ;
153+ setEmbedObjectsLabels ( labels ) ;
154+ }
155+ } , [ ctValue ] ) ;
156+
122157 // Option for content types
123158 const option = Array . isArray ( contentTypes )
124159 ? contentTypes . map ( ( option ) => ( { label : option ?. otherCmsTitle , value : option ?. otherCmsTitle } ) )
@@ -323,7 +358,18 @@ const AdvancePropertise = (props: SchemaProps) => {
323358 < Select
324359 value = { ctValue }
325360 isMulti = { true }
326- onChange = { setCTValue }
361+ onChange = { ( selectedOptions :any ) => {
362+ setCTValue ( selectedOptions ) ;
363+ const embedObject = selectedOptions . map ( ( item : any ) => item . label ) ; // Update the state with the selected options
364+ props ?. updateFieldSettings (
365+ props ?. rowId ,
366+ {
367+ validationRegex : toggleStates ?. validationRegex || '' ,
368+ EmbedObjects : embedObject
369+ } ,
370+ true ,
371+ ) ;
372+ } }
327373 options = { option }
328374 placeholder = "Select Content Types"
329375 version = 'v2'
@@ -334,16 +380,6 @@ const AdvancePropertise = (props: SchemaProps) => {
334380 />
335381 ) }
336382
337- < div className = 'ToggleWrap' >
338- < ToggleSwitch
339- label = "Embed Asset(s)"
340- labelColor = "primary"
341- labelPosition = "right"
342- checked = { toggleStates ?. embedAssests }
343- disabled = { toggleStates ?. embedAssests }
344- onChange = { handleToggleChange && ( ( e : React . MouseEvent < HTMLElement > ) => handleToggleChange ( 'embedAssests' , ( e . target as HTMLInputElement ) ?. checked , true ) ) }
345- />
346- </ div >
347383 </ >
348384 ) }
349385 { props ?. fieldtype !== 'Global' && (
@@ -357,18 +393,6 @@ const AdvancePropertise = (props: SchemaProps) => {
357393 />
358394 </ div >
359395 ) }
360-
361- { props ?. fieldtype === 'File' && (
362- < div className = 'ToggleWrap' >
363- < ToggleSwitch
364- label = "Allow Images Only"
365- labelColor = "primary"
366- labelPosition = "right"
367- checked = { toggleStates ?. allowImagesOnly }
368- onChange = { handleToggleChange && ( ( e : React . MouseEvent < HTMLElement > ) => handleToggleChange ( 'allowImagesOnly' , ( e . target as HTMLInputElement ) ?. checked , true ) ) }
369- />
370- </ div >
371- ) }
372396
373397 < div className = 'ToggleWrap' >
374398 < Tooltip
0 commit comments