Skip to content

Commit 003745f

Browse files
authored
Merge pull request #606 from contentstack/feature/dropdown-field-choices
Feature/dropdown field choices
2 parents 4eb8564 + 00e0a8d commit 003745f

File tree

3 files changed

+41
-36
lines changed

3 files changed

+41
-36
lines changed

api/src/services/projects.service.ts

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ const createProject = async (req: Request) => {
135135
//Add logic to create Project from DB
136136
await ProjectModelLowdb.read();
137137

138-
ProjectModelLowdb.update((data: any) => {
138+
await ProjectModelLowdb.update((data: any) => {
139139
data.projects.push(projectData);
140140
});
141141

@@ -204,7 +204,7 @@ const updateProject = async (req: Request) => {
204204

205205
try {
206206
// Update the project fields
207-
ProjectModelLowdb.update((data: any) => {
207+
await ProjectModelLowdb.update((data: any) => {
208208
data.projects[projectIndex].name = updateData?.name;
209209
data.projects[projectIndex].description = updateData?.description;
210210
if (
@@ -308,7 +308,7 @@ const updateLegacyCMS = async (req: Request) => {
308308
// }
309309

310310
try {
311-
ProjectModelLowdb.update((data: any) => {
311+
await ProjectModelLowdb.update((data: any) => {
312312
data.projects[projectIndex].legacy_cms.cms = legacy_cms;
313313
data.projects[projectIndex].current_step = STEPPER_STEPS.LEGACY_CMS;
314314
data.projects[projectIndex].status = NEW_PROJECT_STATUS[0];
@@ -368,7 +368,7 @@ const updateAffix = async (req: Request) => {
368368
true
369369
)) as number;
370370

371-
ProjectModelLowdb.update((data: any) => {
371+
await ProjectModelLowdb.update((data: any) => {
372372
data.projects[projectIndex].legacy_cms.affix = affix;
373373
data.projects[projectIndex].updated_at = new Date().toISOString();
374374
});
@@ -405,7 +405,7 @@ const affixConfirmation = async (req: Request) => {
405405
true
406406
)) as number;
407407

408-
ProjectModelLowdb.update((data: any) => {
408+
await ProjectModelLowdb.update((data: any) => {
409409
data.projects[projectIndex].legacy_cms.affix_confirmation =
410410
affix_confirmation;
411411
data.projects[projectIndex].updated_at = new Date().toISOString();
@@ -477,7 +477,7 @@ const updateFileFormat = async (req: Request) => {
477477
// }
478478

479479
try {
480-
ProjectModelLowdb.update((data: any) => {
480+
await ProjectModelLowdb.update((data: any) => {
481481
data.projects[projectIndex].legacy_cms.file_format = file_format;
482482
data.projects[projectIndex].legacy_cms.file_path = file_path;
483483
data.projects[projectIndex].legacy_cms.is_fileValid = is_fileValid;
@@ -546,7 +546,7 @@ const fileformatConfirmation = async (req: Request) => {
546546
)) as number;
547547

548548
if (!fileformat_confirmation) {
549-
ProjectModelLowdb.update((data: any) => {
549+
await ProjectModelLowdb.update((data: any) => {
550550
data.projects[projectIndex].legacy_cms.file_format_confirmation =
551551
fileformat_confirmation;
552552
data.projects[projectIndex].updated_at = new Date().toISOString();
@@ -643,7 +643,7 @@ const updateDestinationStack = async (req: Request) => {
643643
if (!res.data.stacks.find((stack: any) => stack.api_key === stack_api_key))
644644
throw new BadRequestError(HTTP_TEXTS.DESTINATION_STACK_NOT_FOUND);
645645

646-
ProjectModelLowdb.update((data: any) => {
646+
await ProjectModelLowdb.update((data: any) => {
647647
data.projects[projectIndex].destination_stack_id = stack_api_key;
648648
data.projects[projectIndex].current_step =
649649
STEPPER_STEPS.DESTINATION_STACK;
@@ -713,11 +713,6 @@ const updateCurrentStep = async (req: Request) => {
713713
const isStepCompleted =
714714
project?.legacy_cms?.cms && project?.legacy_cms?.file_format;
715715

716-
console.info((project.status === NEW_PROJECT_STATUS[0] ||
717-
!isStepCompleted ||
718-
!project?.destination_stack_id ||
719-
project?.content_mapper?.length === 0 ||
720-
!project?.current_test_stack_id) || !project?.migration_execution);
721716

722717
switch (project.current_step) {
723718
case STEPPER_STEPS.LEGACY_CMS: {
@@ -732,7 +727,7 @@ const updateCurrentStep = async (req: Request) => {
732727
throw new BadRequestError(HTTP_TEXTS.CANNOT_PROCEED_LEGACY_CMS);
733728
}
734729

735-
ProjectModelLowdb.update((data: any) => {
730+
await ProjectModelLowdb.update((data: any) => {
736731
data.projects[projectIndex].current_step =
737732
STEPPER_STEPS.DESTINATION_STACK;
738733
data.projects[projectIndex].status =
@@ -760,7 +755,7 @@ const updateCurrentStep = async (req: Request) => {
760755
);
761756
}
762757

763-
ProjectModelLowdb.update((data: any) => {
758+
await ProjectModelLowdb.update((data: any) => {
764759
data.projects[projectIndex].current_step =
765760
STEPPER_STEPS.CONTENT_MAPPING;
766761
data.projects[projectIndex].status = NEW_PROJECT_STATUS[3];
@@ -789,7 +784,7 @@ const updateCurrentStep = async (req: Request) => {
789784
);
790785
}
791786

792-
ProjectModelLowdb.update((data: any) => {
787+
await ProjectModelLowdb.update((data: any) => {
793788
data.projects[projectIndex].current_step =
794789
STEPPER_STEPS.TESTING;
795790
data.projects[projectIndex].status = NEW_PROJECT_STATUS[4];
@@ -818,7 +813,7 @@ const updateCurrentStep = async (req: Request) => {
818813
);
819814
}
820815

821-
ProjectModelLowdb.update((data: any) => {
816+
await ProjectModelLowdb.update((data: any) => {
822817
data.projects[projectIndex].current_step =
823818
STEPPER_STEPS.MIGRATION;
824819
data.projects[projectIndex].status = NEW_PROJECT_STATUS[4];
@@ -847,7 +842,7 @@ const updateCurrentStep = async (req: Request) => {
847842
);
848843
}
849844

850-
ProjectModelLowdb.update((data: any) => {
845+
await ProjectModelLowdb.update((data: any) => {
851846
data.projects[projectIndex].current_step =
852847
STEPPER_STEPS.MIGRATION;
853848
data.projects[projectIndex].status = NEW_PROJECT_STATUS[5];
@@ -913,7 +908,7 @@ const deleteProject = async (req: Request) => {
913908
await ContentTypesMapperModelLowdb.read();
914909
await FieldMapperModel.read();
915910
if (!isEmpty(content_mapper_id)) {
916-
content_mapper_id.map((item: any) => {
911+
content_mapper_id.map(async (item: any) => {
917912
const contentMapperData = ContentTypesMapperModelLowdb.chain
918913
.get("ContentTypesMappers")
919914
.find({ id: item, projectId: projectId })
@@ -940,17 +935,17 @@ const deleteProject = async (req: Request) => {
940935
.get("ContentTypesMappers")
941936
.findIndex({ id: item, projectId: projectId })
942937
.value();
943-
ContentTypesMapperModelLowdb.update((Cdata: any) => {
938+
await ContentTypesMapperModelLowdb.update((Cdata: any) => {
944939
delete Cdata.ContentTypesMappers[contentMapperID];
945940
});
946941
});
947942
}
948943
//delete Project
949-
ProjectModelLowdb.update((Pdata: any) => {
944+
await ProjectModelLowdb.update((Pdata: any) => {
950945
delete Pdata.projects[projectIndex];
951946
});
952947
} else {
953-
ProjectModelLowdb.update((data: any) => {
948+
await ProjectModelLowdb.update((data: any) => {
954949
data.projects[projectIndex].isDeleted = true;
955950
});
956951
}
@@ -1000,7 +995,7 @@ const revertProject = async (req: Request) => {
1000995
if (!projects) {
1001996
throw new NotFoundError(HTTP_TEXTS.PROJECT_NOT_FOUND);
1002997
} else {
1003-
ProjectModelLowdb.update((data: any) => {
998+
await ProjectModelLowdb.update((data: any) => {
1004999
data.projects[projectIndex].isDeleted = false;
10051000
});
10061001
logger.info(
@@ -1047,7 +1042,7 @@ const updateStackDetails = async (req: Request) => {
10471042
)) as number;
10481043

10491044
try {
1050-
ProjectModelLowdb.update((data: any) => {
1045+
await ProjectModelLowdb.update((data: any) => {
10511046
data.projects[projectIndex].stackDetails = stack_details;
10521047
data.projects[projectIndex].updated_at = new Date().toISOString();
10531048
});
@@ -1109,7 +1104,7 @@ const updateContentMapper = async (req: Request) => {
11091104
)) as number;
11101105

11111106
try {
1112-
ProjectModelLowdb.update((data: any) => {
1107+
await ProjectModelLowdb.update((data: any) => {
11131108
data.projects[projectIndex].mapperKeys = content_mapper;
11141109
data.projects[projectIndex].updated_at = new Date().toISOString();
11151110
});
@@ -1170,7 +1165,7 @@ const updateMigrationExecution = async (req: Request) => {
11701165
try {
11711166

11721167
// Update the project in the `ProjectModelLowdb` database
1173-
ProjectModelLowdb.update((data: any) => {
1168+
await ProjectModelLowdb.update((data: any) => {
11741169
data.projects[projectIndex].migration_execution = true; // Set migration execution to true
11751170
data.projects[projectIndex].updated_at = new Date().toISOString(); // Update the `updated_at` timestamp
11761171
});

ui/src/cmsData/legacyCms.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@
326326
"uid": "cs752bfd62296e4791"
327327
},
328328
"title": "Select CMS",
329-
"description": "Select the CMS you are migrating content from.",
329+
"description": "Select the CMS you are migrating content from",
330330
"step_lock_text": "Editing this step is currently disabled. To make changes in Draft mode, please deactivate the migration.",
331331
"lock": false,
332332
"active": true,
@@ -338,7 +338,7 @@
338338
"uid": "cs6c761d71844ac800"
339339
},
340340
"title": "Add Source Affix",
341-
"description": "Add a 2–5 character affix for the source name. Use only letters, no numbers or special characters.",
341+
"description": "Add a 2–5 character affix for the source name. Use only letters, no numbers or special characters",
342342
"step_lock_text": "Editing this step is currently disabled. To make changes in Draft mode, please deactivate the migration.",
343343
"lock": false,
344344
"active": false,
@@ -350,7 +350,7 @@
350350
"uid": "cs7c935e15de9ea7c8"
351351
},
352352
"title": "Select File Format",
353-
"description": "Select the file format compatible with the selected CMS.",
353+
"description": "Select the file format compatible with the selected CMS",
354354
"step_lock_text": "Editing this step is currently disabled. To make changes in Draft mode, please deactivate the migration.",
355355
"lock": false,
356356
"active": true,
@@ -362,7 +362,7 @@
362362
"uid": "cs0279f1f0ce13e83e"
363363
},
364364
"title": "Uploaded File",
365-
"description": "This is the file you have uploaded.",
365+
"description": "This is the file you have uploaded",
366366
"step_lock_text": "Editing this step is currently disabled. To make changes in Draft mode, please deactivate the migration.",
367367
"lock": false,
368368
"active": true,

ui/src/pages/Migration/index.tsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -623,12 +623,22 @@ const Migration = () => {
623623
}
624624
});
625625
} else {
626-
event.preventDefault();
627-
const url = `/projects/${projectId}/migration/steps/4`;
628-
navigate(url, { replace: true });
629626

630-
await updateCurrentStepData(selectedOrganisation.value, projectId);
631-
handleStepChange(3);
627+
const res = await updateCurrentStepData(selectedOrganisation.value, projectId);
628+
if (res?.status === 200) {
629+
setIsLoading(false);
630+
event.preventDefault();
631+
handleStepChange(3);
632+
const url = `/projects/${projectId}/migration/steps/4`;
633+
navigate(url, { replace: true });
634+
} else {
635+
setIsLoading(false);
636+
Notification({
637+
notificationContent: { text: res?.data?.error?.message },
638+
type: 'error'
639+
});
640+
}
641+
632642
}
633643
};
634644

@@ -722,7 +732,7 @@ const Migration = () => {
722732
<div className="steps-wrapper">
723733
<HorizontalStepper
724734
ref={stepperRef}
725-
steps={createStepper(projectData ?? defaultMigrationResponse, handleClick)}
735+
steps={createStepper(projectData ?? defaultMigrationResponse, handleStepChange)}
726736
handleSaveCT={saveRef?.current?.handleSaveContentType}
727737
changeDropdownState={changeDropdownState}
728738
projectData={projectData || defaultMigrationResponse}

0 commit comments

Comments
 (0)