@@ -448,7 +448,7 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:
448448 } , [ tableData , otherContentType ] ) ;
449449
450450 useEffect ( ( ) => {
451- if ( isUpdated && ! isCsCTypeUpdated ) {
451+ if ( isUpdated ) {
452452 setIsAllCheck ( false ) ;
453453 setTableData ( updatedRows ) ;
454454 setExistingField ( updatedExstingField ) ;
@@ -639,11 +639,55 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:
639639
640640 } , [ contentTypeSchema ] ) ;
641641 useEffect ( ( ) => {
642- if ( isCsCTypeUpdated ) {
643- // Clear existing field mappings and selected options when content type changes
644- setExistingField ( { } ) ;
645- setSelectedOptions ( [ ] ) ;
646- setsCsCTypeUpdated ( false ) ;
642+ if ( existingField && isCsCTypeUpdated ) {
643+ const matchedKeys = new Set < string > ( ) ;
644+
645+ contentTypeSchema ?. forEach ( ( item ) => {
646+ for ( const [ key , value ] of Object . entries ( existingField ) ) {
647+ if ( value ?. value ?. uid === item ?. uid ) {
648+ matchedKeys . add ( key ) ;
649+
650+ setExistingField ( ( prevOptions : ExistingFieldType ) => ( {
651+ ...prevOptions ,
652+ [ key ] : { label : item ?. display_name , value : item } ,
653+ } ) ) ;
654+ }
655+ if ( item ?. data_type === "group" && Array . isArray ( item ?. schema ) ) {
656+ item ?. schema ?. forEach ( ( schemaItem ) => {
657+ if ( value ?. value ?. uid === schemaItem ?. uid ) {
658+
659+ matchedKeys . add ( key ) ;
660+ setExistingField ( ( prevOptions : ExistingFieldType ) => ( {
661+ ...prevOptions ,
662+ [ key ] : { label : `${ item ?. display_name } > ${ schemaItem ?. display_name } ` , value : schemaItem } ,
663+ } ) ) ;
664+ }
665+ } ) ;
666+ }
667+ }
668+ } ) ;
669+
670+ if ( newMigrationData ?. content_mapping ?. content_type_mapping ?. [ otherCmsTitle ] !== otherContentType ?. label ) {
671+ setSelectedOptions ( [ ] ) ;
672+ }
673+ // Remove unmatched keys from existingField
674+ // setExistingField((prevOptions: ExistingFieldType) => {
675+ // const updatedOptions: ExistingFieldType = { ...prevOptions };
676+ // Object.keys(prevOptions).forEach((key) => {
677+ // if (matchedKeys?.has(key)) {
678+
679+ // const index = selectedOptions?.indexOf(updatedOptions?.[key]?.label ?? '');
680+
681+ // if (index > -1) {
682+ // selectedOptions?.splice(index, 1);
683+ // }
684+ // delete updatedOptions[key];
685+ // }
686+ // });
687+ // console.info("updatedOptions", updatedOptions);
688+ // return updatedOptions;
689+ // });
690+
647691 }
648692
649693 } , [ otherContentType ] ) ;
@@ -1774,7 +1818,7 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:
17741818 placeholder = "Select Field"
17751819 version = { 'v2' }
17761820 maxWidth = "290px"
1777- isClearable = { ! ! existingField [ data ?. backupFieldUid ] ?. label && selectedOptions ?. includes ?.( existingField [ data ?. backupFieldUid ] ?. label ?? '' ) }
1821+ isClearable = { isTypeMatch && selectedOptions ?. includes ?.( existingField ?. [ data ?. backupFieldUid ] ?. label ?? '' ) }
17781822 options = { adjustedOptions }
17791823 isDisabled = { OptionValue ?. isDisabled || newMigrationData ?. project_current_step > 4 }
17801824 menuPlacement = "auto"
0 commit comments