Skip to content

Commit 88648c3

Browse files
committed
fix:master-locale not showing for new stack and title and url bugs in content-mapper
1 parent 201ec5e commit 88648c3

File tree

3 files changed

+45
-16
lines changed

3 files changed

+45
-16
lines changed

ui/src/components/ContentMapper/index.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,9 +1076,9 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
10761076
options={option}
10771077
menuPlacement="auto"
10781078
isDisabled={
1079-
data?.otherCmsType === "Group" ||
1080-
data?.otherCmsField === 'title' ||
1081-
data?.otherCmsField === 'url' ||
1079+
data?.contentstackFieldType === 'group' ||
1080+
(data?.contentstackFieldType === 'text') ||
1081+
( data?.contentstackFieldType === 'url') ||
10821082
data?.backupFieldType === 'reference'||
10831083
data?.contentstackFieldType === "global_field" ||
10841084
data?.otherCmsType === undefined ||
@@ -1089,9 +1089,9 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
10891089
/>
10901090
</div>
10911091
{!(
1092-
data?.otherCmsType === 'Group' ||
1093-
data?.otherCmsField === 'title' ||
1094-
data?.otherCmsField === 'url' ||
1092+
data?.contentstackFieldType === 'Group' ||
1093+
data?.contentstackFieldType === 'text' ||
1094+
data?.contentstackFieldType === 'url' ||
10951095
data?.contentstackFieldType === 'global_field' ||
10961096
data?.otherCmsType === undefined ||
10971097
data?.backupFieldType === 'extension' ||

ui/src/components/DestinationStack/Actions/LoadLanguageMapper.tsx

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import {
88
Select,
99
Tooltip
1010
} from '@contentstack/venus-components';
11-
import { useEffect, useState } from 'react';
12-
import TableHeader from './tableHeader';
11+
import { useEffect, useRef, useState } from 'react';
12+
import TableHeader from './tableHeader'
1313
import { useDispatch, useSelector } from 'react-redux';
1414
import { RootState } from '../../../store';
1515
import { updateNewMigrationData } from '../../../store/slice/migrationDataSlice';
@@ -29,6 +29,8 @@ export type ExistingFieldType = {
2929
* @returns {JSX.Element | null} - Returns a JSX element if empty, otherwise null.
3030
*/
3131
const Mapper = ({
32+
key,
33+
stack,
3234
cmsLocaleOptions,
3335
handleLangugeDelete,
3436
options,
@@ -41,7 +43,9 @@ const Mapper = ({
4143
options: Array<{ label: string; value: string }>;
4244
sourceOptions: Array<{ label: string; value: string }>;
4345
isDisabled: boolean;
44-
localeChanged: boolean
46+
localeChanged: boolean,
47+
stack: IDropDown,
48+
key: string,
4549
}) => {
4650
const [selectedMappings, setSelectedMappings] = useState<{ [key: string]: string }>({});
4751
const [existingField, setExistingField] = useState<ExistingFieldType>({});
@@ -51,9 +55,14 @@ const Mapper = ({
5155
const [csOptions, setcsOptions] = useState(options);
5256
const [sourceoptions, setsourceoptions] = useState(sourceOptions);
5357
const newMigrationData = useSelector((state: RootState) => state?.migration?.newMigrationData);
58+
const [selectedStack,setselectedStack] = useState<IDropDown>();
5459
const dispatch = useDispatch();
5560
const [placeholder] = useState<string>('Select language');
5661

62+
useEffect(()=>{
63+
setselectedStack(stack)
64+
},[]);
65+
5766
useEffect(() => {
5867
const newMigrationDataObj: INewMigration = {
5968
...newMigrationData,
@@ -437,14 +446,28 @@ const Mapper = ({
437446
);
438447
};
439448

440-
const LanguageMapper = ({stack} :{ stack : IDropDown}) => {
449+
const LanguageMapper = ({stack, uid } :{ stack : IDropDown, uid: string}) => {
441450

442451
const newMigrationData = useSelector((state: RootState) => state?.migration?.newMigrationData);
443452
const [options, setoptions] = useState<{ label: string; value: string }[]>([]);
444453
const [cmsLocaleOptions, setcmsLocaleOptions] = useState<{ label: string; value: string }[]>([]);
445454
const [sourceLocales, setsourceLocales] = useState<{ label: string; value: string }[]>([]);
446455
const [isLoading, setisLoading] = useState<boolean>(false);
447456
const [localeChanged, setlocaleChanged] = useState<boolean>(false);
457+
const [currentStack, setcurrentStack] = useState<IDropDown>();
458+
const [previousStack, setpreviousStack] = useState<IDropDown>();
459+
const [isStackChanged, setisStackChanged] = useState<boolean>(false);
460+
461+
const prevStackRef:any = useRef(null);
462+
463+
useEffect(() => {
464+
if (prevStackRef.current && stack?.uid !== prevStackRef.current?.uid) {
465+
setisStackChanged(true);
466+
setcurrentStack(stack);
467+
setpreviousStack(prevStackRef?.current);
468+
}
469+
prevStackRef.current = stack;
470+
}, [stack]);
448471

449472
useEffect(() => {
450473
const fetchData = async () => {
@@ -463,16 +486,19 @@ const LanguageMapper = ({stack} :{ stack : IDropDown}) => {
463486
setsourceLocales(sourceLocale);
464487
setoptions(allLocales);
465488
const keys = Object?.keys(newMigrationData?.destination_stack?.localeMapping || {})?.find( key => key === `${newMigrationData?.destination_stack?.selectedStack?.master_locale}-master_locale`);
466-
467-
(Object?.entries(newMigrationData?.destination_stack?.localeMapping)?.length === 0 || !keys ) &&
468-
newMigrationData?.project_current_step <= 2 &&
489+
if((Object?.entries(newMigrationData?.destination_stack?.localeMapping)?.length === 0 ||
490+
!keys ||
491+
currentStack?.uid !== previousStack?.uid || isStackChanged) &&
492+
newMigrationData?.project_current_step <= 2)
493+
{
469494
setcmsLocaleOptions((prevList: { label: string; value: string }[]) => {
470495
const newLabel = stack?.master_locale;
471496

472497
const isPresent = prevList?.filter(
473498
(item: { label: string; value: string }) => (item?.value === 'master_locale')
474499
);
475-
if(isPresent?.[0]?.label !== newLabel){
500+
if(isPresent?.[0]?.label !== newLabel || currentStack?.uid !== previousStack?.uid || isStackChanged){
501+
setisStackChanged(false);
476502
setlocaleChanged(true);
477503
return [
478504
...prevList?.filter(item => (item?.value !== 'master_locale' && item?.value !== '')) ?? [],
@@ -493,7 +519,7 @@ const LanguageMapper = ({stack} :{ stack : IDropDown}) => {
493519
}
494520

495521
return prevList;
496-
});
522+
});}
497523
if (newMigrationData?.project_current_step > 2) {
498524
Object?.entries(newMigrationData?.destination_stack?.localeMapping || {})?.forEach(
499525
([key, value]) => {
@@ -525,7 +551,7 @@ const LanguageMapper = ({stack} :{ stack : IDropDown}) => {
525551
};
526552

527553
fetchData();
528-
}, [newMigrationData?.destination_stack?.selectedStack]);
554+
}, [newMigrationData?.destination_stack?.selectedStack, currentStack]);
529555

530556
// const fetchLocales = async () => {
531557
// return await getStackLocales(newMigrationData?.destination_stack?.selectedOrg?.value);
@@ -562,6 +588,8 @@ const LanguageMapper = ({stack} :{ stack : IDropDown}) => {
562588
}
563589
rowComponent={
564590
<Mapper
591+
key={stack?.value}
592+
stack={stack}
565593
localeChanged={localeChanged}
566594
options={options}
567595
cmsLocaleOptions={cmsLocaleOptions}

ui/src/components/DestinationStack/Actions/LoadStacks.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ const LoadStacks = (props: LoadFileFormatProps) => {
373373
</Tooltip>
374374
</div>
375375
<LanguageMapper
376+
uid={selectedStack?.uid ?? ''}
376377
stack={selectedStack ?? DEFAULT_DROPDOWN} />
377378
</div>
378379
)}

0 commit comments

Comments
 (0)