@@ -11,7 +11,7 @@ import {
1111 Icon ,
1212 Select ,
1313 Radio ,
14- Button ,
14+ Button
1515} from '@contentstack/venus-components' ;
1616
1717// Service
@@ -78,13 +78,28 @@ const AdvancePropertise = (props: SchemaProps) => {
7878 const [ embedObjectsLabels , setEmbedObjectsLabels ] = useState < string [ ] > (
7979 props ?. value ?. embedObjects
8080 ) ;
81- const [ referencedCT , setReferencedCT ] = useState < ContentTypeOption [ ] | null > ( referencedItems || null ) ;
81+ const [ referencedCT , setReferencedCT ] = useState < ContentTypeOption [ ] | null > (
82+ referencedItems || null
83+ ) ;
8284 const [ showOptions , setShowOptions ] = useState < Record < number , boolean > > ( { } ) ;
8385 const [ showIcon , setShowIcon ] = useState < number > ( ) ;
8486 const filterRef = useRef < HTMLDivElement | null > ( null ) ;
8587 const [ options , setOptions ] = useState ( props ?. value ?. options || [ ] ) ;
8688 const [ draggedIndex , setDraggedIndex ] = useState < number | null > ( null ) ;
8789
90+ useEffect ( ( ) => {
91+ if ( props ?. data ?. refrenceTo && Array . isArray ( props ?. data ?. refrenceTo ) ) {
92+ const updatedReferencedItems = props ?. data ?. refrenceTo . map ( ( item : string ) => ( {
93+ label : item ,
94+ value : item
95+ } ) ) ;
96+ setReferencedCT ( updatedReferencedItems ) ;
97+ setToggleStates ( ( prevStates ) => ( {
98+ ...prevStates ,
99+ referenedItems : props ?. data ?. refrenceTo
100+ } ) ) ;
101+ }
102+ } , [ props ?. data ?. refrenceTo ] ) ;
88103 useEffect ( ( ) => {
89104 const defaultIndex = toggleStates ?. option ?. findIndex (
90105 ( item : optionsType ) => toggleStates ?. default_value === item ?. key
@@ -342,9 +357,9 @@ const AdvancePropertise = (props: SchemaProps) => {
342357
343358 const option = validateArray ( contentTypesList )
344359 ? contentTypesList ?. map ( ( option : ContentType ) => ( {
345- label : option ?. contentstackTitle ,
346- value : option ?. contentstackUid
347- } ) )
360+ label : option ?. contentstackTitle ,
361+ value : option ?. contentstackUid
362+ } ) )
348363 : [ { label : contentTypesList , value : contentTypesList } ] ;
349364
350365 return (
@@ -370,8 +385,7 @@ const AdvancePropertise = (props: SchemaProps) => {
370385 draggable
371386 onDragStart = { ( ) => handleDragStart ( index ) }
372387 onDragOver = { ( e ) => handleDragOver ( e , index ) }
373- onDrop = { ( ) => handleDrop ( index ) }
374- >
388+ onDrop = { ( ) => handleDrop ( index ) } >
375389 < div className = "term-drag-icon" >
376390 < Icon icon = "ActionBar" size = "medium" version = "v2" />
377391 </ div >
@@ -385,8 +399,7 @@ const AdvancePropertise = (props: SchemaProps) => {
385399 index === showIcon && (
386400 < Icon icon = { 'CheckSquareOffset' } version = "v2" size = "medium" />
387401 )
388- }
389- > </ TextInput >
402+ } > </ TextInput >
390403
391404 < Button
392405 buttonType = "light"
@@ -395,8 +408,7 @@ const AdvancePropertise = (props: SchemaProps) => {
395408 canCloseOnClickOutside = { true }
396409 size = { 'small' }
397410 icon = { 'v2-DotsThreeLargeVertical' }
398- onClick = { ( ) => handleOnClick ( index ) }
399- > </ Button >
411+ onClick = { ( ) => handleOnClick ( index ) } > </ Button >
400412
401413 { showOptions [ index ] && (
402414 < div className = "dropdown-filter-wrapper" ref = { filterRef } >
@@ -406,8 +418,7 @@ const AdvancePropertise = (props: SchemaProps) => {
406418 buttonType = "light"
407419 icon = { 'v2-CheckSquareOffset' }
408420 size = { 'small' }
409- onClick = { ( ) => handleDefalutValue ( index , option ) }
410- >
421+ onClick = { ( ) => handleDefalutValue ( index , option ) } >
411422 Mark as Default
412423 </ Button >
413424 ) : (
@@ -416,8 +427,7 @@ const AdvancePropertise = (props: SchemaProps) => {
416427 buttonType = "light"
417428 icon = { 'v2-CheckSquareOffset' }
418429 size = { 'small' }
419- onClick = { ( ) => handleRemoveDefalutValue ( index ) }
420- >
430+ onClick = { ( ) => handleRemoveDefalutValue ( index ) } >
421431 Remove as Default
422432 </ Button >
423433 ) }
@@ -431,53 +441,52 @@ const AdvancePropertise = (props: SchemaProps) => {
431441
432442 { ( props ?. fieldtype === 'Single Line Textbox' ||
433443 props ?. fieldtype === 'Multi Line Textbox' ) && (
434- < >
435- < Field >
436- < FieldLabel htmlFor = "validation" version = "v2" >
437- Default Value
438- </ FieldLabel >
439- < Tooltip
440- content = {
441- 'Set a default field value for this field. The value will appear by default while creating an entry for this content type.'
442- }
443- position = "right"
444- >
445- < Icon icon = "Question" size = "small" version = "v2" className = "Help" />
446- </ Tooltip >
447- < TextInput
448- type = "text"
449- value = { toggleStates ?. default_value }
450- placeholder = "Enter value"
451- version = "v2"
452- onChange = {
453- handleOnChange &&
454- ( ( e : React . ChangeEvent < HTMLInputElement > ) =>
455- handleOnChange ( 'default_value' , e , true ) )
456- }
457- />
458- </ Field >
459-
460- < Field >
461- < FieldLabel htmlFor = "validation" version = "v2" >
462- Validation (Regex)
463- </ FieldLabel >
464- < Tooltip content = { 'Define the validation for the field.' } position = "right" >
465- < Icon icon = "Question" size = "small" version = "v2" className = "Help" />
466- </ Tooltip >
467- < TextInput
468- type = "text"
469- value = { toggleStates ?. validationRegex }
470- placeholder = "Enter value"
471- version = "v2"
472- onChange = {
473- handleOnChange &&
474- ( ( e : React . ChangeEvent < HTMLInputElement > ) =>
475- handleOnChange ( 'validationRegex' , e , true ) )
476- }
477- />
478- </ Field >
479- </ >
480- ) }
444+ < >
445+ < Field >
446+ < FieldLabel htmlFor = "validation" version = "v2" >
447+ Default Value
448+ </ FieldLabel >
449+ < Tooltip
450+ content = {
451+ 'Set a default field value for this field. The value will appear by default while creating an entry for this content type.'
452+ }
453+ position = "right" >
454+ < Icon icon = "Question" size = "small" version = "v2" className = "Help" />
455+ </ Tooltip >
456+ < TextInput
457+ type = "text"
458+ value = { toggleStates ?. default_value }
459+ placeholder = "Enter value"
460+ version = "v2"
461+ onChange = {
462+ handleOnChange &&
463+ ( ( e : React . ChangeEvent < HTMLInputElement > ) =>
464+ handleOnChange ( 'default_value' , e , true ) )
465+ }
466+ />
467+ </ Field >
468+
469+ < Field >
470+ < FieldLabel htmlFor = "validation" version = "v2" >
471+ Validation (Regex)
472+ </ FieldLabel >
473+ < Tooltip content = { 'Define the validation for the field.' } position = "right" >
474+ < Icon icon = "Question" size = "small" version = "v2" className = "Help" />
475+ </ Tooltip >
476+ < TextInput
477+ type = "text"
478+ value = { toggleStates ?. validationRegex }
479+ placeholder = "Enter value"
480+ version = "v2"
481+ onChange = {
482+ handleOnChange &&
483+ ( ( e : React . ChangeEvent < HTMLInputElement > ) =>
484+ handleOnChange ( 'validationRegex' , e , true ) )
485+ }
486+ />
487+ </ Field >
488+ </ >
489+ ) }
481490
482491 { props ?. fieldtype === 'Link' && (
483492 < >
@@ -489,8 +498,7 @@ const AdvancePropertise = (props: SchemaProps) => {
489498 content = {
490499 'Set a default field value for this field. The value will appear by default while creating an entry for this content type.'
491500 }
492- position = "right"
493- >
501+ position = "right" >
494502 < Icon icon = "Question" size = "small" version = "v2" className = "Help" />
495503 </ Tooltip >
496504 </ div >
@@ -538,13 +546,11 @@ const AdvancePropertise = (props: SchemaProps) => {
538546 < Radio
539547 label = { 'True' }
540548 checked = { toggleStates ?. default_value === true }
541- onChange = { ( ) => handleRadioChange ( 'default_value' , true ) }
542- > </ Radio >
549+ onChange = { ( ) => handleRadioChange ( 'default_value' , true ) } > </ Radio >
543550 < Radio
544551 label = { 'False' }
545552 checked = { toggleStates ?. default_value === false }
546- onChange = { ( ) => handleRadioChange ( 'default_value' , false ) }
547- > </ Radio >
553+ onChange = { ( ) => handleRadioChange ( 'default_value' , false ) } > </ Radio >
548554 </ div >
549555 </ Field >
550556 ) }
@@ -562,12 +568,19 @@ const AdvancePropertise = (props: SchemaProps) => {
562568 setReferencedCT ( selectedOptions ) ;
563569 const referencedArray = selectedOptions ?. map ( ( item : optionsType ) => item ?. value ) ;
564570
571+ setToggleStates ( ( prevStates ) => ( {
572+ ...prevStates ,
573+ referenedItems : referencedArray
574+ } ) ) ;
575+
565576 props ?. updateFieldSettings (
566577 props ?. rowId ,
567578 {
568579 ...props ?. value ,
580+ mandatory : toggleStates ?. mandatory ,
581+ nonLocalizable : toggleStates ?. nonLocalizable ,
569582 validationRegex : toggleStates ?. validationRegex ?? '' ,
570- referenedItems : referencedArray // <-- update only this property!
583+ referenedItems : referencedArray
571584 } ,
572585 true ,
573586 props ?. data ?. contentstackFieldUid
@@ -592,54 +605,56 @@ const AdvancePropertise = (props: SchemaProps) => {
592605 < div className = "options-class" >
593606 { ( props ?. fieldtype === 'HTML Rich text Editor' ||
594607 props ?. fieldtype === 'JSON Rich Text Editor' ) && (
595- < >
596- < div className = "ToggleWrap" >
597- < ToggleSwitch
598- label = "Embed Object(s)"
599- labelColor = "primary"
600- labelPosition = "right"
601- checked = { ( ctValue ?. length ?? 0 ) > 0 || toggleStates ?. embedObject }
602- onChange = {
603- handleToggleChange &&
604- ( ( e : React . MouseEvent < HTMLElement > ) =>
605- handleToggleChange (
606- 'embedObject' ,
607- ( e . target as HTMLInputElement ) ?. checked ,
608- true
609- ) )
610- }
611- />
612- </ div >
608+ < >
609+ < div className = "ToggleWrap" >
610+ < ToggleSwitch
611+ label = "Embed Object(s)"
612+ labelColor = "primary"
613+ labelPosition = "right"
614+ checked = { ( ctValue ?. length ?? 0 ) > 0 || toggleStates ?. embedObject }
615+ onChange = {
616+ handleToggleChange &&
617+ ( ( e : React . MouseEvent < HTMLElement > ) =>
618+ handleToggleChange (
619+ 'embedObject' ,
620+ ( e . target as HTMLInputElement ) ?. checked ,
621+ true
622+ ) )
623+ }
624+ />
625+ </ div >
613626
614- { ( ( ctValue && ctValue ?. length > 0 ) || toggleStates ?. embedObject ) && (
615- < Select
616- value = { ctValue }
617- isMulti = { true }
618- onChange = { ( selectedOptions : ContentTypeOption [ ] ) => {
619- setCTValue ( selectedOptions ) ;
620- const embedObject = selectedOptions ?. map ( ( item : optionsType ) => item ?. value ) ; // Update the state with the selected options
621- props ?. updateFieldSettings (
622- props ?. rowId ,
623- {
624- validationRegex : toggleStates ?. validationRegex ?? '' ,
625- embedObjects : embedObject
626- } ,
627- true ,
628- props ?. data ?. contentstackFieldUid
629- ) ;
630- } }
631- options = { option }
632- placeholder = "Select Content Types"
633- version = "v2"
634- isSearchable = { true }
635- isClearable = { true }
636- width = "350px"
637- maxMenuHeight = { 200 }
627+ { ( ( ctValue && ctValue ?. length > 0 ) || toggleStates ?. embedObject ) && (
628+ < Select
629+ value = { ctValue }
630+ isMulti = { true }
631+ onChange = { ( selectedOptions : ContentTypeOption [ ] ) => {
632+ setCTValue ( selectedOptions ) ;
633+ const embedObject = selectedOptions ?. map (
634+ ( item : optionsType ) => item ?. value
635+ ) ; // Update the state with the selected options
636+ props ?. updateFieldSettings (
637+ props ?. rowId ,
638+ {
639+ validationRegex : toggleStates ?. validationRegex ?? '' ,
640+ embedObjects : embedObject
641+ } ,
642+ true ,
643+ props ?. data ?. contentstackFieldUid
644+ ) ;
645+ } }
646+ options = { option }
647+ placeholder = "Select Content Types"
648+ version = "v2"
649+ isSearchable = { true }
650+ isClearable = { true }
651+ width = "350px"
652+ maxMenuHeight = { 200 }
638653 // isSelectAll={true}
639- />
640- ) }
641- </ >
642- ) }
654+ />
655+ ) }
656+ </ >
657+ ) }
643658 { props ?. fieldtype !== 'Global' && props ?. fieldtype !== 'Boolean' && (
644659 < div className = "ToggleWrap" >
645660 < ToggleSwitch
@@ -665,8 +680,7 @@ const AdvancePropertise = (props: SchemaProps) => {
665680 < Tooltip
666681 content = "Available only if there are multiple languages in your stack"
667682 position = "top"
668- disabled = { props ?. isLocalised }
669- >
683+ disabled = { props ?. isLocalised } >
670684 < ToggleSwitch
671685 id = "disabled"
672686 disabled = { ! props ?. isLocalised }
0 commit comments