@@ -32,12 +32,14 @@ const Mapper = ({
3232 cmsLocaleOptions,
3333 handleLangugeDelete,
3434 options,
35- sourceOptions
35+ sourceOptions,
36+ isDisabled
3637} : {
3738 cmsLocaleOptions : Array < { label : string ; value : string } > ;
3839 handleLangugeDelete : ( index : number , locale : { label : string ; value : string } ) => void ;
3940 options : Array < { label : string ; value : string } > ;
4041 sourceOptions : Array < { label : string ; value : string } > ;
42+ isDisabled : boolean
4143} ) => {
4244 const [ selectedMappings , setSelectedMappings ] = useState < { [ key : string ] : string } > ( { } ) ;
4345 const [ existingField , setExistingField ] = useState < ExistingFieldType > ( { } ) ;
@@ -259,7 +261,7 @@ const Mapper = ({
259261 </ Tooltip >
260262 ) : (
261263 < Select
262- value = { existingField [ locale ] }
264+ value = { locale ?. value ? locale : existingField [ locale ] }
263265 onChange = { ( key : { label : string ; value : string } ) => {
264266 handleSelectedCsLocale ( key , index , 'csLocale' ) ;
265267 } }
@@ -273,7 +275,7 @@ const Mapper = ({
273275 version = "v2"
274276 hideSelectedOptions = { true }
275277 isClearable = { true }
276- isDisabled = { false }
278+ isDisabled = { isDisabled }
277279 className = "select-container"
278280 />
279281 ) }
@@ -299,26 +301,31 @@ const Mapper = ({
299301 className="select-container"
300302 /> */
301303 < Select
302- value = { existingLocale [ locale ] }
304+ value = { locale ?. value && locale ?. value !== 'master_locale' ? { label : locale ?. value , value : locale ?. value } : existingLocale [ locale ] }
303305 onChange = { ( data : { label : string ; value : string } ) =>
304306 handleSelectedSourceLocale ( data , index , 'sourceLocale' , locale )
305307 }
308+ styles = { {
309+ menuPortal : ( base :any ) => ( { ...base , zIndex : 9999 } )
310+ } }
306311 options = { sourceoptions }
307312 placeholder = { placeholder }
308313 isSearchable
309- maxMenuHeight = { 150 }
314+ maxMenuHeight = { 100 }
310315 multiDisplayLimit = { 5 }
311- menuPortalTarget = { document . querySelector ( '.language-mapper' ) }
316+ //menuPortalTarget={document.querySelector('.mini-table')}
317+ menuShouldScrollIntoView = { true }
312318 width = "270px"
313319 version = "v2"
314320 hideSelectedOptions = { true }
315321 isClearable = { true }
316- isDisabled = { false }
322+ isDisabled = { isDisabled }
317323 className = "select-container"
318324 />
319325 }
320326 < div className = { '' } >
321- { locale ?. value !== 'master_locale' && (
327+ { locale ?. value !== 'master_locale' &&
328+ ! isDisabled && (
322329 < Tooltip content = { 'Delete' } position = "top" showArrow = { false } >
323330 < Icon
324331 icon = "Trash"
@@ -330,6 +337,7 @@ const Mapper = ({
330337 hover
331338 hoverType = "secondary"
332339 shadow = "medium"
340+ disabled = { isDisabled }
333341 />
334342 </ Tooltip >
335343 ) }
@@ -373,7 +381,8 @@ const LanguageMapper = () => {
373381 setsourceLocales ( sourceLocale ) ;
374382
375383 setoptions ( allLocales ) ;
376- setcmsLocaleOptions ( ( prevList : { label : string ; value : string } [ ] ) => {
384+ Object ?. entries ( newMigrationData ?. destination_stack ?. localeMapping ) ?. length === 0 &&
385+ setcmsLocaleOptions ( ( prevList : { label : string ; value : string } [ ] ) => {
377386 const newLabel = newMigrationData ?. destination_stack ?. selectedStack ?. master_locale ;
378387
379388 const isPresent = prevList . some ( ( item : { label : string ; value : string } ) => item ?. value === 'master_locale' ) ;
@@ -390,14 +399,36 @@ const LanguageMapper = () => {
390399
391400 return prevList ;
392401 } ) ;
402+ if ( newMigrationData ?. project_current_step > 2 ) {
403+ Object . entries ( newMigrationData ?. destination_stack ?. localeMapping || { } ) ?. forEach ( ( [ key , value ] ) => {
404+ setcmsLocaleOptions ( ( prevList ) => {
405+ const labelKey = key ?. replace ( / - m a s t e r _ l o c a l e $ / , "" ) ;
406+
407+ // Check if the key already exists in the list
408+ const exists = prevList ?. some ( ( item ) => item ?. label === labelKey ) ;
409+
410+ if ( ! exists ) {
411+ return [
412+ ...prevList ,
413+ {
414+ label : labelKey ,
415+ value : String ( value ) ,
416+ } ,
417+ ] ;
418+ }
419+
420+ return prevList ; // Return the same list if key exists
421+ } ) ;
422+ } ) ;
423+ }
393424 setisLoading ( false ) ;
394425 } catch ( error ) {
395426 console . error ( 'Error fetching locales:' , error ) ;
396427 }
397428 } ;
398429
399430 fetchData ( ) ;
400- } , [ ] ) ;
431+ } , [ newMigrationData ?. destination_stack ] ) ;
401432
402433 // const fetchLocales = async () => {
403434 // return await getStackLocales(newMigrationData?.destination_stack?.selectedOrg?.value);
@@ -435,6 +466,7 @@ const LanguageMapper = () => {
435466 cmsLocaleOptions = { cmsLocaleOptions }
436467 handleLangugeDelete = { handleDeleteLocale }
437468 sourceOptions = { sourceLocales }
469+ isDisabled = { newMigrationData ?. project_current_step > 2 }
438470 />
439471 }
440472 // footerComponent={
@@ -461,7 +493,7 @@ const LanguageMapper = () => {
461493 disabled = {
462494 Object . keys ( newMigrationData ?. destination_stack ?. localeMapping || { } ) ?. length ===
463495 newMigrationData ?. destination_stack ?. sourceLocale ?. length ||
464- cmsLocaleOptions ?. length === newMigrationData ?. destination_stack ?. sourceLocale ?. length
496+ cmsLocaleOptions ?. length === newMigrationData ?. destination_stack ?. sourceLocale ?. length || newMigrationData ?. project_current_step > 2
465497 } >
466498 Add Language
467499 </ Button >
0 commit comments