Skip to content

Commit 2284709

Browse files
committed
Code refactored
2 parents 3782a11 + 4f78f7c commit 2284709

File tree

10 files changed

+95
-67
lines changed

10 files changed

+95
-67
lines changed

.github/workflows/repo-sync.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ jobs:
9898
git gc --prune=now # Garbage collect and prune unreachable objects
9999
100100
# Remove unused imports and missing file references
101-
echo "Running ESLint to remove unused imports..."
102-
npm install eslint -g
103-
eslint . --fix
101+
# echo "Running ESLint to remove unused imports..."
102+
# npm install eslint -g
103+
# eslint . --fix
104104
105105
echo "Running autoflake to remove unused imports..."
106106
pip install autoflake
@@ -164,9 +164,9 @@ jobs:
164164
git gc --prune=now # Garbage collect and prune unreachable objects
165165
166166
# Remove unused imports and missing file references
167-
echo "Running ESLint to remove unused imports..."
168-
npm install eslint -g
169-
eslint . --fix
167+
# echo "Running ESLint to remove unused imports..."
168+
# npm install eslint -g
169+
# eslint . --fix
170170
171171
echo "Running autoflake to remove unused imports..."
172172
pip install autoflake
@@ -230,9 +230,9 @@ jobs:
230230
git gc --prune=now # Garbage collect and prune unreachable objects
231231
232232
# Remove unused imports and missing file references
233-
echo "Running ESLint to remove unused imports..."
234-
npm install eslint -g
235-
eslint . --fix
233+
# echo "Running ESLint to remove unused imports..."
234+
# npm install eslint -g
235+
# eslint . --fix
236236
237237
echo "Running autoflake to remove unused imports..."
238238
pip install autoflake

api/src/services/auth.service.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import logger from "../utils/logger.js";
2121
* @returns A promise that resolves to a LoginServiceType object.
2222
* @throws ExceptionFunction if an error occurs during the login process.
2323
*/
24-
2524
const login = async (req: Request): Promise<LoginServiceType> => {
2625
const srcFun = "Login";
2726
/*

api/src/services/contentful.service.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import jsonpath from "jsonpath";
88
import pLimit from 'p-limit';
99
import { JSDOM } from "jsdom";
1010
import { jsonToHtml, jsonToMarkdown, htmlToJson } from '@contentstack/json-rte-serializer';
11-
1211
import { CHUNK_SIZE, LOCALE_MAPPER, MIGRATION_DATA_CONFIG } from "../constants/index.js";
1312
import { Locale } from "../models/types.js";
1413
import jsonRTE from "./contentful/jsonRTE.js";

api/src/services/migration.service.ts

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -417,28 +417,18 @@ const getLogs = async (req: Request): Promise<any> => {
417417
*/
418418
export const createSourceLocales = async (req: Request) => {
419419

420-
const projectFilePath = path.join(process.cwd(), 'database', 'project.json'); // Adjusted path to project.json
421420
const projectId = req.params.projectId;
422-
423421
const locales = req.body.locale
424422

425423
try {
426-
// Check if the project.json file exists
427-
if (!fs?.existsSync?.(projectFilePath)) {
428-
console.error(`project.json not found at ${projectFilePath}`);
429-
throw new Error(`project.json not found.`);
430-
}
431-
432424
// Find the project with the specified projectId
433-
const project: any = ProjectModelLowdb?.chain?.get?.("projects")?.find?.({ id: projectId })?.value?.();
434-
if (project) {
435-
const index = ProjectModelLowdb?.chain?.get?.("projects")?.findIndex?.({ id: projectId })?.value();
436-
if (index > -1) {
437-
438-
ProjectModelLowdb?.update((data: any) => {
439-
data.projects[index].source_locales = locales;
440-
});
441-
} // Write back the updated projects
425+
await ProjectModelLowdb?.read?.();
426+
const index = ProjectModelLowdb?.chain?.get?.("projects")?.findIndex?.({ id: projectId })?.value?.();
427+
if (index > -1) {
428+
ProjectModelLowdb?.update?.((data: any) => {
429+
data.projects[index].source_locales = locales;
430+
});
431+
// Write back the updated projects
442432
} else {
443433
logger.error(`Project with ID: ${projectId} not found`, {
444434
status: HTTP_CODES?.NOT_FOUND,
@@ -467,26 +457,19 @@ export const createSourceLocales = async (req: Request) => {
467457
*/
468458
export const updateLocaleMapper = async (req: Request) => {
469459
const mapperObject = req?.body;
470-
const projectFilePath = path?.join?.(process?.cwd(), 'database', 'project.json'); // Adjusted path to project.json
460+
// Adjusted path to project.json
471461
const projectId = req?.params?.projectId;
472462

473463
try {
474-
// Check if the project.json file exists
475-
if (!fs?.existsSync?.(projectFilePath)) {
476-
console.error(`project.json not found at ${projectFilePath}`);
477-
throw new Error(`project.json not found.`);
478-
}
479464
// Find the project with the specified projectId
480-
await ProjectModelLowdb.read();
481-
const project: any = ProjectModelLowdb?.chain?.get?.("projects")?.find?.({ id: projectId })?.value();
482-
if (project) {
483-
const index = ProjectModelLowdb?.chain?.get("projects")?.findIndex?.({ id: projectId })?.value();
484-
if (index > -1) {
485-
ProjectModelLowdb?.update((data: any) => {
486-
data.projects[index].master_locale = mapperObject?.master_locale;
487-
data.projects[index].locales = mapperObject?.locales;
488-
});
489-
} // Write back the updated projects
465+
await ProjectModelLowdb?.read?.();
466+
const index = ProjectModelLowdb?.chain?.get?.("projects")?.findIndex?.({ id: projectId })?.value?.();
467+
if (index > -1) {
468+
ProjectModelLowdb?.update?.((data: any) => {
469+
data.projects[index].master_locale = mapperObject?.master_locale;
470+
data.projects[index].locales = mapperObject?.locales;
471+
});
472+
// Write back the updated projects
490473
} else {
491474
logger.error(`Project with ID: ${projectId} not found`, {
492475
status: HTTP_CODES?.NOT_FOUND,

api/src/services/sitecore.service.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import customLogger from '../utils/custom-logger.utils.js';
1111

1212

1313
const append = "a";
14-
1514
const baseDirName = MIGRATION_DATA_CONFIG.DATA
1615
const {
1716
ENTRIES_DIR_NAME,

api/src/services/wordpress.service.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ const virtualConsole = new jsdom.VirtualConsole();
1515
// Get the current file's path
1616
const __filename = fileURLToPath(import.meta.url);
1717

18-
19-
2018
// Get the current directory
2119
const __dirname = path.dirname(__filename);
2220

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

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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(/-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+
});
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>

ui/src/components/DestinationStack/DestinationStack.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,12 @@
235235
}
236236
}
237237
}
238+
.field-content__content{
239+
height: auto !important;
240+
max-height: unset !important;
241+
overflow: visible !important;
242+
z-index: 9999;
243+
}
238244
}
239245
.span {
240246
padding: 10px 20px;
@@ -259,6 +265,8 @@
259265
.mini-table {
260266
margin-left: 40px;
261267
margin-top: 10px;
268+
overflow: visible !important;
269+
position: relative;
262270
//width: 120px;
263271
}
264272
.lang-container {

ui/src/pages/Migration/index.tsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,15 @@ const Migration = () => {
227227
const stackLink = `${CS_URL[projectData?.region]}/stack/${projectData?.current_test_stack_id}/dashboard`;
228228
const stackName = projectData?.test_stacks?.find((stack:TestStacks)=> stack?.stackUid === projectData?.current_test_stack_id)?.stackName;
229229

230+
const masterLocaleEntries = projectData?.master_locale
231+
? Object?.entries(projectData?.master_locale).map(([key, value]) => [`${key}-master_locale`, value])
232+
: [];
233+
234+
const locales = {
235+
...Object?.fromEntries(masterLocaleEntries),
236+
...projectData?.locales
237+
};
238+
230239
const projectMapper = {
231240
...newMigrationData,
232241
legacy_cms: {
@@ -258,7 +267,8 @@ const Migration = () => {
258267
stackArray: [],
259268
migratedStacks: migratedstacks?.data?.destinationStacks,
260269
sourceLocale: projectData?.source_locales,
261-
csLocale: csLocales?.data?.locales
270+
csLocale: csLocales?.data?.locales,
271+
localeMapping: locales
262272
},
263273
content_mapping: {
264274
isDropDownChanged: false,
@@ -438,10 +448,10 @@ const Migration = () => {
438448
setIsLoading(true);
439449

440450
const hasNonEmptyMapping =
441-
newMigrationData?.destination_stack?.localeMapping &&
442-
Object.values(newMigrationData?.destination_stack?.localeMapping)?.some(
443-
(value) => value !== '' || value !== null || value !== undefined
444-
);
451+
newMigrationData?.destination_stack?.localeMapping &&
452+
Object.values(newMigrationData?.destination_stack?.localeMapping)?.every(
453+
(value) => value !== '' && value !== null && value !== undefined
454+
);
445455

446456
const master_locale:any = {};
447457
const locales: any= {};
@@ -455,7 +465,7 @@ const Migration = () => {
455465
if (
456466
isCompleted &&
457467
!isEmptyString(newMigrationData?.destination_stack?.selectedStack?.value) &&
458-
hasNonEmptyMapping
468+
hasNonEmptyMapping
459469
) {
460470
event?.preventDefault();
461471
//Update Data in backend

upload-api/src/config/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export default {
22
plan: {
33
dropdown: { optionLimit: 100 }
44
},
5-
cmsType: 'contentful',
5+
cmsType: 'sitecore',
66
isLocalPath: true,
77
awsData: {
88
awsRegion: 'us-east-2',
@@ -12,6 +12,6 @@ export default {
1212
bucketName: 'migartion-test',
1313
buketKey: 'project/package 45.zip'
1414
},
15-
localPath: '/Users/sayali.joshi/Downloads/contentfulDummyEmbedData.json' //package 45.zip'
16-
// localPath: '/Users/umesh.more/Documents/ui-migration/migration-v2-node-server/upload-api/extracted_files/package 45.zip'
15+
// localPath: '/Users/sayali.joshi/Downloads/contentfulDummyEmbedData.json' //package 45.zip'
16+
localPath: '/Users/umesh.more/Documents/ui-migration/migration-v2-node-server/upload-api/extracted_files/package 45.zip'
1717
};

0 commit comments

Comments
 (0)