@@ -94,10 +94,31 @@ const Mapper = ({
9494 useEffect ( ( ) => {
9595 setExistingField ( ( prevExisting : ExistingFieldType ) => {
9696 const updatedExisting = { ...prevExisting } ;
97+ const validLabels = cmsLocaleOptions ?. map ( locale => locale . label ) || [ ] ;
98+ Object . entries ( updatedExisting ) . forEach ( ( [ index , entry ] ) => {
99+ const [ labelPart ] = entry . label . split ( '-' ) ;
100+ if ( ! validLabels . includes ( labelPart ) ) {
101+ delete updatedExisting [ index ] ;
102+ }
103+ } ) ;
104+
105+ setSelectedMappings ( ( prev ) => {
106+ const updated = { ...prev } ;
107+
108+ Object . keys ( updated ) . forEach ( ( key ) => {
109+ const [ labelPart ] = key . split ( '-' ) ;
110+ if ( ! validLabels . includes ( labelPart ) ) {
111+ delete updated [ key ] ;
112+ }
113+ } ) ;
114+
115+ return updated ;
116+ } ) ;
97117
98118 cmsLocaleOptions ?. forEach ( ( locale : { label : string ; value : string } , index : number ) => {
99119 if ( locale ?. value === 'master_locale' && ! updatedExisting ?. [ index ] ) {
100120 setSelectedMappings ( ( prev ) => ( {
121+
101122 ...prev ,
102123 [ `${ locale ?. label } -master_locale` ] : ''
103124 } ) ) ;
@@ -422,18 +443,28 @@ const LanguageMapper = () => {
422443 value : item
423444 } ) ) ;
424445 setsourceLocales ( sourceLocale ) ;
425-
426446 setoptions ( allLocales ) ;
427- Object ?. entries ( newMigrationData ?. destination_stack ?. localeMapping ) ?. length === 0 &&
447+ const keys = Object . keys ( newMigrationData ?. destination_stack ?. localeMapping || { } ) ?. find ( key => key === `${ newMigrationData ?. destination_stack ?. selectedStack ?. master_locale } -master_locale` ) ;
448+
449+ ( Object ?. entries ( newMigrationData ?. destination_stack ?. localeMapping ) ?. length === 0 || keys !== `${ newMigrationData ?. destination_stack ?. selectedStack ?. master_locale } -master_locale` ) &&
428450 newMigrationData ?. project_current_step <= 2 &&
429451 setcmsLocaleOptions ( ( prevList : { label : string ; value : string } [ ] ) => {
430452 const newLabel = newMigrationData ?. destination_stack ?. selectedStack ?. master_locale ;
431-
432- const isPresent = prevList . some (
433- ( item : { label : string ; value : string } ) => item ?. value === 'master_locale'
453+
454+ const isPresent = prevList . filter (
455+ ( item : { label : string ; value : string } ) => ( item ?. value === 'master_locale' )
434456 ) ;
435-
436- if ( ! isPresent ) {
457+
458+ if ( isPresent [ 0 ] ?. label !== newLabel ) {
459+ return [
460+ ...prevList . filter ( item => item . value !== 'master_locale' ) ,
461+ {
462+ label : newLabel ,
463+ value : 'master_locale' ,
464+ }
465+ ] ;
466+ }
467+ if ( isPresent ?. length <= 0 ) {
437468 return [
438469 ...prevList ,
439470 {
0 commit comments