Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions ui/src/components/ContentMapper/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1076,9 +1076,9 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
options={option}
menuPlacement="auto"
isDisabled={
data?.otherCmsType === "Group" ||
data?.otherCmsField === 'title' ||
data?.otherCmsField === 'url' ||
data?.contentstackFieldType === 'group' ||
(data?.contentstackFieldType === 'text') ||
( data?.contentstackFieldType === 'url') ||
data?.backupFieldType === 'reference'||
data?.contentstackFieldType === "global_field" ||
data?.otherCmsType === undefined ||
Expand All @@ -1089,9 +1089,9 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
/>
</div>
{!(
data?.otherCmsType === 'Group' ||
data?.otherCmsField === 'title' ||
data?.otherCmsField === 'url' ||
data?.contentstackFieldType === 'Group' ||
data?.contentstackFieldType === 'text' ||
data?.contentstackFieldType === 'url' ||
data?.contentstackFieldType === 'global_field' ||
data?.otherCmsType === undefined ||
data?.backupFieldType === 'extension' ||
Expand Down
48 changes: 38 additions & 10 deletions ui/src/components/DestinationStack/Actions/LoadLanguageMapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
Select,
Tooltip
} from '@contentstack/venus-components';
import { useEffect, useState } from 'react';
import TableHeader from './tableHeader';
import { useEffect, useRef, useState } from 'react';
import TableHeader from './tableHeader'
import { useDispatch, useSelector } from 'react-redux';
import { RootState } from '../../../store';
import { updateNewMigrationData } from '../../../store/slice/migrationDataSlice';
Expand All @@ -29,6 +29,8 @@ export type ExistingFieldType = {
* @returns {JSX.Element | null} - Returns a JSX element if empty, otherwise null.
*/
const Mapper = ({
key,
stack,
cmsLocaleOptions,
handleLangugeDelete,
options,
Expand All @@ -41,7 +43,9 @@ const Mapper = ({
options: Array<{ label: string; value: string }>;
sourceOptions: Array<{ label: string; value: string }>;
isDisabled: boolean;
localeChanged: boolean
localeChanged: boolean,
stack: IDropDown,
key: string,
}) => {
const [selectedMappings, setSelectedMappings] = useState<{ [key: string]: string }>({});
const [existingField, setExistingField] = useState<ExistingFieldType>({});
Expand All @@ -51,9 +55,14 @@ const Mapper = ({
const [csOptions, setcsOptions] = useState(options);
const [sourceoptions, setsourceoptions] = useState(sourceOptions);
const newMigrationData = useSelector((state: RootState) => state?.migration?.newMigrationData);
const [selectedStack,setSelectedStack] = useState<IDropDown>();
const dispatch = useDispatch();
const [placeholder] = useState<string>('Select language');

useEffect(()=>{
setSelectedStack(stack)
},[]);

useEffect(() => {
const newMigrationDataObj: INewMigration = {
...newMigrationData,
Expand Down Expand Up @@ -437,14 +446,28 @@ const Mapper = ({
);
};

const LanguageMapper = ({stack} :{ stack : IDropDown}) => {
const LanguageMapper = ({stack, uid } :{ stack : IDropDown, uid: string}) => {

const newMigrationData = useSelector((state: RootState) => state?.migration?.newMigrationData);
const [options, setoptions] = useState<{ label: string; value: string }[]>([]);
const [cmsLocaleOptions, setcmsLocaleOptions] = useState<{ label: string; value: string }[]>([]);
const [sourceLocales, setsourceLocales] = useState<{ label: string; value: string }[]>([]);
const [isLoading, setisLoading] = useState<boolean>(false);
const [localeChanged, setlocaleChanged] = useState<boolean>(false);
const [currentStack, setCurrentStack] = useState<IDropDown>();
const [previousStack, setPreviousStack] = useState<IDropDown>();
const [isStackChanged, setisStackChanged] = useState<boolean>(false);

const prevStackRef:any = useRef(null);

useEffect(() => {
if (prevStackRef.current && stack?.uid !== prevStackRef.current?.uid) {
setisStackChanged(true);
setCurrentStack(stack);
setPreviousStack(prevStackRef?.current);
}
prevStackRef.current = stack;
}, [stack]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow same proper format in useState above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


useEffect(() => {
const fetchData = async () => {
Expand All @@ -463,16 +486,19 @@ const LanguageMapper = ({stack} :{ stack : IDropDown}) => {
setsourceLocales(sourceLocale);
setoptions(allLocales);
const keys = Object?.keys(newMigrationData?.destination_stack?.localeMapping || {})?.find( key => key === `${newMigrationData?.destination_stack?.selectedStack?.master_locale}-master_locale`);

(Object?.entries(newMigrationData?.destination_stack?.localeMapping)?.length === 0 || !keys ) &&
newMigrationData?.project_current_step <= 2 &&
if((Object?.entries(newMigrationData?.destination_stack?.localeMapping)?.length === 0 ||
!keys ||
currentStack?.uid !== previousStack?.uid || isStackChanged) &&
newMigrationData?.project_current_step <= 2)
{
setcmsLocaleOptions((prevList: { label: string; value: string }[]) => {
const newLabel = stack?.master_locale;

const isPresent = prevList?.filter(
(item: { label: string; value: string }) => (item?.value === 'master_locale')
);
if(isPresent?.[0]?.label !== newLabel){
if(isPresent?.[0]?.label !== newLabel || currentStack?.uid !== previousStack?.uid || isStackChanged){
setisStackChanged(false);
setlocaleChanged(true);
return [
...prevList?.filter(item => (item?.value !== 'master_locale' && item?.value !== '')) ?? [],
Expand All @@ -493,7 +519,7 @@ const LanguageMapper = ({stack} :{ stack : IDropDown}) => {
}

return prevList;
});
});}
if (newMigrationData?.project_current_step > 2) {
Object?.entries(newMigrationData?.destination_stack?.localeMapping || {})?.forEach(
([key, value]) => {
Expand Down Expand Up @@ -525,7 +551,7 @@ const LanguageMapper = ({stack} :{ stack : IDropDown}) => {
};

fetchData();
}, [newMigrationData?.destination_stack?.selectedStack]);
}, [newMigrationData?.destination_stack?.selectedStack, currentStack]);

// const fetchLocales = async () => {
// return await getStackLocales(newMigrationData?.destination_stack?.selectedOrg?.value);
Expand Down Expand Up @@ -562,6 +588,8 @@ const LanguageMapper = ({stack} :{ stack : IDropDown}) => {
}
rowComponent={
<Mapper
key={stack?.value}
stack={stack}
localeChanged={localeChanged}
options={options}
cmsLocaleOptions={cmsLocaleOptions}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ const LoadStacks = (props: LoadFileFormatProps) => {
</Tooltip>
</div>
<LanguageMapper
uid={selectedStack?.uid ?? ''}
stack={selectedStack ?? DEFAULT_DROPDOWN} />
</div>
)}
Expand Down
Loading