Skip to content

Commit 3f6c02a

Browse files
committed
Code formatting
1 parent affbb18 commit 3f6c02a

File tree

3 files changed

+457
-385
lines changed

3 files changed

+457
-385
lines changed

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

Lines changed: 79 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ import { updateNewMigrationData } from '../../../store/slice/migrationDataSlice'
1616
import { INewMigration } from '../../../context/app/app.interface';
1717

1818
export type ExistingFieldType = {
19-
[key: string]: { label: string ; value: string };
19+
[key: string]: { label: string; value: string };
2020
};
2121

2222
/**
2323
* A functional component that displays selection for language mapping.
24-
*
24+
*
2525
* @param {Array<{ label: string; value: string }>} cmsLocaleOptions - An array to dispaly number of locales select.
2626
* @param {Function} handleLangugeDelete - a function to delete the mapping.
2727
* @param {Array<{ label: string; value: string }>} options - option array of contentstack locales.
@@ -39,7 +39,7 @@ const Mapper = ({
3939
handleLangugeDelete: (index: number, locale: { label: string; value: string }) => void;
4040
options: Array<{ label: string; value: string }>;
4141
sourceOptions: Array<{ label: string; value: string }>;
42-
isDisabled: boolean
42+
isDisabled: boolean;
4343
}) => {
4444
const [selectedMappings, setSelectedMappings] = useState<{ [key: string]: string }>({});
4545
const [existingField, setExistingField] = useState<ExistingFieldType>({});
@@ -78,10 +78,12 @@ const Mapper = ({
7878

7979
useEffect(() => {
8080
const formattedoptions = options?.filter(
81-
(item: { label: string; value: string }) => !selectedCsOptions?.some((selected: string) => selected === item?.value)
81+
(item: { label: string; value: string }) =>
82+
!selectedCsOptions?.some((selected: string) => selected === item?.value)
8283
);
8384
const adjustedOptions = sourceOptions?.filter(
84-
(item: { label: string; value: string }) => !selectedSourceOption?.some((selected: string) => selected === item?.label)
85+
(item: { label: string; value: string }) =>
86+
!selectedSourceOption?.some((selected: string) => selected === item?.label)
8587
);
8688
setcsOptions(formattedoptions);
8789
setsourceoptions(adjustedOptions);
@@ -97,7 +99,10 @@ const Mapper = ({
9799
...prev,
98100
[`${locale?.label}-master_locale`]: ''
99101
}));
100-
updatedExisting[index] = { label: locale?.label, value: `${locale?.label}-master_locale` };
102+
updatedExisting[index] = {
103+
label: locale?.label,
104+
value: `${locale?.label}-master_locale`
105+
};
101106
}
102107
});
103108

@@ -128,7 +133,9 @@ const Mapper = ({
128133
return updatedOptions;
129134
});
130135
setselectedCsOption((prevSelected) => {
131-
const newSelectedOptions: string[] = prevSelected?.filter((item) => item !== selectedValue?.label);
136+
const newSelectedOptions: string[] = prevSelected?.filter(
137+
(item) => item !== selectedValue?.label
138+
);
132139
const newValue: string = selectedValue?.label;
133140
if (!newSelectedOptions?.includes(newValue)) {
134141
newSelectedOptions.push(newValue);
@@ -172,7 +179,9 @@ const Mapper = ({
172179
// Ensure selectedOption only contains values that exist in updatedOptions
173180
setselectedSourceOption((prevSelected) =>
174181
prevSelected?.filter((item) =>
175-
Object.values(updatedOptions)?.some((opt: {label: string, value: string}) => opt?.label === item)
182+
Object.values(updatedOptions)?.some(
183+
(opt: { label: string; value: string }) => opt?.label === item
184+
)
176185
)
177186
);
178187

@@ -194,8 +203,7 @@ const Mapper = ({
194203
[csLocaleKey]: selectedValue?.label || ''
195204
}));
196205
};
197-
const handleLanguageDeletaion = (index: number, locale: {label: string, value: string}) => {
198-
206+
const handleLanguageDeletaion = (index: number, locale: { label: string; value: string }) => {
199207
// Remove item at index from existingField
200208
let csLocale = '';
201209

@@ -238,11 +246,14 @@ const Mapper = ({
238246
{locale?.value === 'master_locale' ? (
239247
<Tooltip
240248
content="This is the master locale of above selected stacks and cannot be changed. Please select a corresponding language to map."
241-
position="top">
249+
position="top"
250+
>
242251
<div>
243252
<Select
244253
value={locale?.value === 'master_locale' ? locale : existingField[locale]}
245-
onChange={(key: { label: string; value: string }) => handleSelectedCsLocale(key, index, 'csLocale')}
254+
onChange={(key: { label: string; value: string }) =>
255+
handleSelectedCsLocale(key, index, 'csLocale')
256+
}
246257
options={csOptions}
247258
placeholder={placeholder}
248259
isSearchable
@@ -301,20 +312,24 @@ const Mapper = ({
301312
className="select-container"
302313
/> */
303314
<Select
304-
value={locale?.value && locale?.value !== 'master_locale' ? {label: locale?.value, value: locale?.value} : existingLocale[locale]}
315+
value={
316+
locale?.value && locale?.value !== 'master_locale'
317+
? { label: locale?.value, value: locale?.value }
318+
: existingLocale[locale]
319+
}
305320
onChange={(data: { label: string; value: string }) =>
306321
handleSelectedSourceLocale(data, index, 'sourceLocale', locale)
307322
}
308323
styles={{
309-
menuPortal: (base:any) => ({ ...base, zIndex: 9999 })
324+
menuPortal: (base: any) => ({ ...base, zIndex: 9999 })
310325
}}
311326
options={sourceoptions}
312327
placeholder={placeholder}
313328
isSearchable
314329
maxMenuHeight={100}
315330
multiDisplayLimit={5}
316331
//menuPortalTarget={document.querySelector('.mini-table')}
317-
menuShouldScrollIntoView={true}
332+
menuShouldScrollIntoView={true}
318333
width="270px"
319334
version="v2"
320335
hideSelectedOptions={true}
@@ -324,8 +339,7 @@ const Mapper = ({
324339
/>
325340
}
326341
<div className={''}>
327-
{locale?.value !== 'master_locale' &&
328-
!isDisabled && (
342+
{locale?.value !== 'master_locale' && !isDisabled && (
329343
<Tooltip content={'Delete'} position="top" showArrow={false}>
330344
<Icon
331345
icon="Trash"
@@ -382,44 +396,48 @@ const LanguageMapper = () => {
382396

383397
setoptions(allLocales);
384398
Object?.entries(newMigrationData?.destination_stack?.localeMapping)?.length === 0 &&
385-
setcmsLocaleOptions((prevList: { label: string; value: string }[]) => {
386-
const newLabel = newMigrationData?.destination_stack?.selectedStack?.master_locale;
387-
388-
const isPresent = prevList.some((item: { label: string; value: string }) => item?.value === 'master_locale');
389-
390-
if (!isPresent) {
391-
return [
392-
...prevList,
393-
{
394-
label: newLabel,
395-
value: 'master_locale'
396-
}
397-
];
398-
}
399+
setcmsLocaleOptions((prevList: { label: string; value: string }[]) => {
400+
const newLabel = newMigrationData?.destination_stack?.selectedStack?.master_locale;
401+
402+
const isPresent = prevList.some(
403+
(item: { label: string; value: string }) => item?.value === 'master_locale'
404+
);
405+
406+
if (!isPresent) {
407+
return [
408+
...prevList,
409+
{
410+
label: newLabel,
411+
value: 'master_locale'
412+
}
413+
];
414+
}
399415

400-
return prevList;
401-
});
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(/-master_locale$/, "");
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-
});
416+
return prevList;
422417
});
418+
if (newMigrationData?.project_current_step > 2) {
419+
Object.entries(newMigrationData?.destination_stack?.localeMapping || {})?.forEach(
420+
([key, value]) => {
421+
setcmsLocaleOptions((prevList) => {
422+
const labelKey = key?.replace(/-master_locale$/, '');
423+
424+
// Check if the key already exists in the list
425+
const exists = prevList?.some((item) => item?.label === labelKey);
426+
427+
if (!exists) {
428+
return [
429+
...prevList,
430+
{
431+
label: labelKey,
432+
value: String(value)
433+
}
434+
];
435+
}
436+
437+
return prevList; // Return the same list if key exists
438+
});
439+
}
440+
);
423441
}
424442
setisLoading(false);
425443
} catch (error) {
@@ -445,7 +463,9 @@ const LanguageMapper = () => {
445463

446464
const handleDeleteLocale = (id: number, locale: { label: string; value: string }) => {
447465
setcmsLocaleOptions((prevList) => {
448-
return prevList?.filter((item: { label: string; value: string }) => item?.label !== locale?.label);
466+
return prevList?.filter(
467+
(item: { label: string; value: string }) => item?.label !== locale?.label
468+
);
449469
});
450470
};
451471

@@ -493,8 +513,11 @@ const LanguageMapper = () => {
493513
disabled={
494514
Object.keys(newMigrationData?.destination_stack?.localeMapping || {})?.length ===
495515
newMigrationData?.destination_stack?.sourceLocale?.length ||
496-
cmsLocaleOptions?.length === newMigrationData?.destination_stack?.sourceLocale?.length || newMigrationData?.project_current_step > 2
497-
}>
516+
cmsLocaleOptions?.length ===
517+
newMigrationData?.destination_stack?.sourceLocale?.length ||
518+
newMigrationData?.project_current_step > 2
519+
}
520+
>
498521
Add Language
499522
</Button>
500523
</>

0 commit comments

Comments
 (0)