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
54 changes: 43 additions & 11 deletions ui/src/components/DestinationStack/Actions/LoadLanguageMapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ const Mapper = ({
cmsLocaleOptions,
handleLangugeDelete,
options,
sourceOptions
sourceOptions,
isDisabled
}: {
cmsLocaleOptions: Array<{ label: string; value: string }>;
handleLangugeDelete: (index: number, locale: { label: string; value: string }) => void;
options: Array<{ label: string; value: string }>;
sourceOptions: Array<{ label: string; value: string }>;
isDisabled: boolean
}) => {
const [selectedMappings, setSelectedMappings] = useState<{ [key: string]: string }>({});
const [existingField, setExistingField] = useState<ExistingFieldType>({});
Expand Down Expand Up @@ -259,7 +261,7 @@ const Mapper = ({
</Tooltip>
) : (
<Select
value={existingField[locale]}
value={locale?.value ? locale : existingField[locale]}
onChange={(key: { label: string; value: string }) => {
handleSelectedCsLocale(key, index, 'csLocale');
}}
Expand All @@ -273,7 +275,7 @@ const Mapper = ({
version="v2"
hideSelectedOptions={true}
isClearable={true}
isDisabled={false}
isDisabled={isDisabled}
className="select-container"
/>
)}
Expand All @@ -299,26 +301,31 @@ const Mapper = ({
className="select-container"
/> */
<Select
value={existingLocale[locale]}
value={locale?.value && locale?.value !== 'master_locale' ? {label: locale?.value, value: locale?.value} : existingLocale[locale]}
onChange={(data: { label: string; value: string }) =>
handleSelectedSourceLocale(data, index, 'sourceLocale', locale)
}
styles={{
menuPortal: (base:any) => ({ ...base, zIndex: 9999 })
}}
options={sourceoptions}
placeholder={placeholder}
isSearchable
maxMenuHeight={150}
maxMenuHeight={100}
multiDisplayLimit={5}
menuPortalTarget={document.querySelector('.language-mapper')}
//menuPortalTarget={document.querySelector('.mini-table')}
menuShouldScrollIntoView={true}
width="270px"
version="v2"
hideSelectedOptions={true}
isClearable={true}
isDisabled={false}
isDisabled={isDisabled}
className="select-container"
/>
}
<div className={''}>
{locale?.value !== 'master_locale' && (
{locale?.value !== 'master_locale' &&
!isDisabled && (
<Tooltip content={'Delete'} position="top" showArrow={false}>
<Icon
icon="Trash"
Expand All @@ -330,6 +337,7 @@ const Mapper = ({
hover
hoverType="secondary"
shadow="medium"
disabled={isDisabled}
/>
</Tooltip>
)}
Expand Down Expand Up @@ -373,7 +381,8 @@ const LanguageMapper = () => {
setsourceLocales(sourceLocale);

setoptions(allLocales);
setcmsLocaleOptions((prevList: { label: string; value: string }[]) => {
Object?.entries(newMigrationData?.destination_stack?.localeMapping)?.length === 0 &&
setcmsLocaleOptions((prevList: { label: string; value: string }[]) => {
const newLabel = newMigrationData?.destination_stack?.selectedStack?.master_locale;

const isPresent = prevList.some((item: { label: string; value: string }) => item?.value === 'master_locale');
Expand All @@ -390,14 +399,36 @@ const LanguageMapper = () => {

return prevList;
});
if (newMigrationData?.project_current_step > 2) {
Object.entries(newMigrationData?.destination_stack?.localeMapping || {})?.forEach(([key, value]) => {
setcmsLocaleOptions((prevList) => {
const labelKey = key?.replace(/-master_locale$/, "");

// Check if the key already exists in the list
const exists = prevList?.some((item) => item?.label === labelKey);

if (!exists) {
return [
...prevList,
{
label: labelKey,
value: String(value),
},
];
}

return prevList; // Return the same list if key exists
});
});
}
setisLoading(false);
} catch (error) {
console.error('Error fetching locales:', error);
}
};

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

// const fetchLocales = async () => {
// return await getStackLocales(newMigrationData?.destination_stack?.selectedOrg?.value);
Expand Down Expand Up @@ -435,6 +466,7 @@ const LanguageMapper = () => {
cmsLocaleOptions={cmsLocaleOptions}
handleLangugeDelete={handleDeleteLocale}
sourceOptions={sourceLocales}
isDisabled={newMigrationData?.project_current_step > 2}
/>
}
// footerComponent={
Expand All @@ -461,7 +493,7 @@ const LanguageMapper = () => {
disabled={
Object.keys(newMigrationData?.destination_stack?.localeMapping || {})?.length ===
newMigrationData?.destination_stack?.sourceLocale?.length ||
cmsLocaleOptions?.length === newMigrationData?.destination_stack?.sourceLocale?.length
cmsLocaleOptions?.length === newMigrationData?.destination_stack?.sourceLocale?.length || newMigrationData?.project_current_step > 2
}>
Add Language
</Button>
Expand Down
8 changes: 8 additions & 0 deletions ui/src/components/DestinationStack/DestinationStack.scss
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,12 @@
}
}
}
.field-content__content{
height: auto !important;
max-height: unset !important;
overflow: visible !important;
z-index: 9999;
}
}
.span {
padding: 10px 20px;
Expand All @@ -254,6 +260,8 @@
.mini-table {
margin-left: 40px;
margin-top: 10px;
overflow: visible !important;
position: relative;
//width: 120px;
}
.lang-container {
Expand Down
23 changes: 16 additions & 7 deletions ui/src/pages/Migration/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,15 @@ const Migration = () => {
const stackLink = `${CS_URL[projectData?.region]}/stack/${projectData?.current_test_stack_id}/dashboard`;
const stackName = projectData?.test_stacks?.find((stack:TestStacks)=> stack?.stackUid === projectData?.current_test_stack_id)?.stackName;

const masterLocaleEntries = projectData?.master_locale
? Object?.entries(projectData?.master_locale).map(([key, value]) => [`${key}-master_locale`, value])
: [];

const locales = {
...Object?.fromEntries(masterLocaleEntries),
...projectData?.locales
};

const projectMapper = {
...newMigrationData,
legacy_cms: {
Expand Down Expand Up @@ -258,7 +267,8 @@ const Migration = () => {
stackArray: [],
migratedStacks: migratedstacks?.data?.destinationStacks,
sourceLocale: projectData?.source_locales,
csLocale: csLocales?.data?.locales
csLocale: csLocales?.data?.locales,
localeMapping: locales
},
content_mapping: {
isDropDownChanged: false,
Expand Down Expand Up @@ -438,11 +448,10 @@ const Migration = () => {
setIsLoading(true);

const hasNonEmptyMapping =
newMigrationData?.destination_stack?.localeMapping &&
Object.values(newMigrationData?.destination_stack?.localeMapping)?.some(
(value) => value !== '' || value !== null || value !== undefined
);
console.log(hasNonEmptyMapping);
newMigrationData?.destination_stack?.localeMapping &&
Object.values(newMigrationData?.destination_stack?.localeMapping)?.every(
(value) => value !== '' && value !== null && value !== undefined
);

const master_locale:any = {};
const locales: any= {};
Expand All @@ -456,7 +465,7 @@ const Migration = () => {
if (
isCompleted &&
!isEmptyString(newMigrationData?.destination_stack?.selectedStack?.value) &&
hasNonEmptyMapping
hasNonEmptyMapping
) {
event?.preventDefault();
//Update Data in backend
Expand Down
Loading