Skip to content

Commit dd1af64

Browse files
authored
Merge pull request #378 from contentstack/feature/dropdown-field-choices
Feature/dropdown field choices
2 parents 2944096 + 6e012da commit dd1af64

File tree

5 files changed

+27
-37
lines changed

5 files changed

+27
-37
lines changed

ui/src/components/ContentMapper/index.tsx

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,6 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
227227
value: contentTypeMapped?.[otherCmsTitle] ?? `Select ${isContentType ? 'Content Type' : 'Global Field'} from Existing Stack`,
228228
});
229229
const [otherCmsUid, setOtherCmsUid] = useState<string>(contentTypes[0]?.otherCmsUid);
230-
231-
const [advancePropertise, setAdvancePropertise] = useState<Advanced>({
232-
validationRegex: '',
233-
mandatory: false,
234-
multiple: false,
235-
unique: false,
236-
nonLocalizable: false
237-
});
238230

239231
const [active, setActive] = useState<number | null>(0);
240232

@@ -248,7 +240,6 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
248240
const [count, setCount] = useState<number>(0);
249241
const [isModalOpen, setIsModalOpen] = useState(false);
250242
const [nestedList, setNestedList] = useState<FieldMapType[]>([]);
251-
const [disabledOptions, setDisabledOptions] = useState<Set<string>>(new Set());
252243
const [isUpdated, setIsUpdated] = useState(false);
253244
let updatedRows: FieldMapType[] = tableData;
254245
let updatedExstingField: ExistingFieldType = existingField;
@@ -261,7 +252,7 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
261252

262253

263254
/** ALL HOOKS Here */
264-
const { projectId = '', stepId = '' } = useParams();
255+
const { projectId = '' } = useParams();
265256
const navigate = useNavigate();
266257

267258
const filterRef = useRef<HTMLDivElement | null>(null);
@@ -445,12 +436,10 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
445436
// maaped fields
446437
useEffect(() => {
447438
if (existingField) {
448-
const matchedKeys = new Set<string>();
449439

450440
contentTypeSchema?.forEach((item) => {
451441
for (const [key, value] of Object.entries(existingField)) {
452442
if (value?.value?.uid === item?.uid) {
453-
matchedKeys.add(key);
454443

455444
setExistingField((prevOptions: ExistingFieldType) => ({
456445
...prevOptions,
@@ -460,7 +449,6 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
460449
if (item?.data_type === "group" && Array.isArray(item?.schema)) {
461450
item.schema.forEach((schemaItem) => {
462451
if (value?.value?.uid === schemaItem?.uid) {
463-
matchedKeys.add(key);
464452
setExistingField((prevOptions: ExistingFieldType) => ({
465453
...prevOptions,
466454
[key]: { label: `${item?.display_name} > ${schemaItem?.display_name}`, value: schemaItem },
@@ -512,11 +500,11 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
512500
}
513501
// Remove unmatched keys from existingField
514502
setExistingField((prevOptions: ExistingFieldType) => {
515-
const updatedOptions:any = { ...prevOptions };
503+
const updatedOptions:ExistingFieldType = { ...prevOptions };
516504
Object.keys(prevOptions).forEach((key) => {
517505
if (matchedKeys.has(key)) {
518506

519-
const index = selectedOptions?.indexOf(updatedOptions?.[key]?.label);
507+
const index = selectedOptions?.indexOf(updatedOptions?.[key]?.label ?? '');
520508

521509
if ( index > -1) {
522510
selectedOptions.splice(index, 1);
@@ -702,7 +690,6 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
702690

703691
const newTableData = tableData?.map((row) => {
704692
if (row?.uid === rowId) {
705-
setAdvancePropertise({ ...row?.advanced, ...updatedSettings });
706693

707694
return { ...row, advanced: { ...row?.advanced, ...updatedSettings } };
708695
}
@@ -1031,20 +1018,6 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
10311018
...prevOptions,
10321019
[rowIndex]: { label: selectedValue?.label, value: selectedValue?.value }
10331020
}));
1034-
1035-
setAdvancePropertise({
1036-
validationRegex: selectedValue?.value?.format,
1037-
mandatory: selectedValue?.value?.mandatory,
1038-
multiple: selectedValue?.value?.multiple,
1039-
unique: selectedValue?.value?.unique,
1040-
nonLocalizable: selectedValue?.value?.non_localizable
1041-
});
1042-
1043-
setDisabledOptions((prevDisabledOptions) => {
1044-
const newDisabledOptions = new Set(prevDisabledOptions);
1045-
newDisabledOptions.add(selectedValue?.label);
1046-
return newDisabledOptions;
1047-
});
10481021

10491022
//add selected option to array if it is not mapped to any other field
10501023
setSelectedOptions((prevSelected) => {
@@ -1284,7 +1257,8 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
12841257
'reference': 'reference',
12851258
'dropdown': 'enum',
12861259
'Droplist': 'display_type',
1287-
'radio': 'enum'
1260+
'radio': 'enum',
1261+
'General Link':'link'
12881262
};
12891263

12901264
const OptionsForRow: OptionsType[] = [];

ui/src/components/LogScreen/MigrationLogViewer.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,11 @@ const MigrationLogViewer = ({ serverPath }: LogsType) => {
135135

136136
const newMigrationDataObj: INewMigration = {
137137
...newMigrationData,
138-
migration_execution: { ...newMigrationData?.migration_execution, migrationStarted: true }
138+
migration_execution: {
139+
...newMigrationData?.migration_execution,
140+
migrationStarted: false,
141+
migrationCompleted:true
142+
}
139143
};
140144

141145
dispatch(updateNewMigrationData((newMigrationDataObj)));
@@ -163,7 +167,7 @@ const MigrationLogViewer = ({ serverPath }: LogsType) => {
163167
return (
164168
<div className='logs-wrapper'>
165169
<div className="logs-container" style={{ height: '400px', overflowY: 'auto' }} ref={logsContainerRef}>
166-
{newMigrationData?.migration_execution?.migrationStarted
170+
{newMigrationData?.migration_execution?.migrationCompleted
167171
? <div className="log-entry text-center">
168172
<div className="log-message">
169173
Migration Execution process is completed. You can view in the selected stack

ui/src/components/Stepper/HorizontalStepper/HorizontalStepper.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ const HorizontalStepper = forwardRef(
193193
const disableStep = newMigrationData?.isprojectMapped && stepsCompleted.includes(idx) && idx !== showStep ? 'disableEvents'
194194
: '';
195195

196-
const completeDisable = stepsCompleted?.includes(idx) && newMigrationData?.test_migration?.isMigrationStarted ? 'disableEvents' : '';
196+
const completeDisable = stepsCompleted?.includes(idx) && (newMigrationData?.test_migration?.isMigrationStarted || newMigrationData?.migration_execution?.migrationStarted) ? 'disableEvents' : '';
197197

198198
const disableMapper = stepsCompleted?.includes(idx) && idx === 2 && newMigrationData?.test_migration?.isMigrationStarted && !newMigrationData?.test_migration?.isMigrationComplete ? 'disableEvents' : '';
199199

ui/src/context/app/app.interface.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ export interface ITestMigration {
231231

232232
export interface IMigrationExecutionStep {
233233
migrationStarted: boolean;
234+
migrationCompleted: boolean;
234235
}
235236
export interface IAppContext {
236237
authToken: string;
@@ -349,7 +350,8 @@ export const DEFAULT_TEST_MIGRATION: ITestMigration = {
349350
};
350351

351352
export const DEFAULT_MIGRATION_EXECUTION_STEP: IMigrationExecutionStep = {
352-
migrationStarted: false
353+
migrationStarted: false,
354+
migrationCompleted:false
353355
}
354356

355357
export const DEFAULT_NEW_MIGRATION: INewMigration = {

ui/src/pages/Migration/index.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ const Migration = () => {
224224
...newMigrationData?.legacy_cms,
225225
selectedCms: selectedCmsData,
226226
selectedFileFormat: selectedFileFormatData,
227-
affix: projectData?.legacy_cms?.affix ?? newMigrationData?.legacy_cms?.affix,
227+
affix: projectData?.legacy_cms?.affix ,
228228
uploadedFile: {
229229
file_details: {
230230
localPath: projectData?.legacy_cms?.file_path,
@@ -235,7 +235,7 @@ const Migration = () => {
235235
},
236236
isLocalPath: projectData?.legacy_cms?.is_localPath
237237
},
238-
isValidated: projectData?.legacy_cms?.is_fileValid || newMigrationData?.legacy_cms?.uploadedFile?.isValidated,
238+
isValidated: projectData?.legacy_cms?.is_fileValid ,
239239
reValidate: newMigrationData?.legacy_cms?.uploadedFile?.reValidate
240240
},
241241
isFileFormatCheckboxChecked: true,
@@ -517,6 +517,16 @@ const Migration = () => {
517517
if (migrationRes?.status === 200) {
518518
setIsLoading(false);
519519
setDisableMigration(true);
520+
const newMigrationDataObj : INewMigration = {
521+
...newMigrationData,
522+
migration_execution:{
523+
...newMigrationData?.migration_execution,
524+
migrationStarted: true,
525+
}
526+
527+
}
528+
dispatch(updateNewMigrationData(newMigrationDataObj));
529+
520530
Notification({
521531
notificationContent: { text: 'Migration Execution process started' },
522532
notificationProps: {

0 commit comments

Comments
 (0)