Skip to content

Commit a8f7e1c

Browse files
Merge pull request #552 from contentstack/feature/dropdown-field-choices
Feature/dropdown field choices
2 parents 230cea6 + 55bdbf7 commit a8f7e1c

File tree

8 files changed

+41
-26
lines changed

8 files changed

+41
-26
lines changed

ui/src/components/ContentMapper/index.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,15 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
501501
[key]: { label: item?.display_name, value: item },
502502
}));
503503
}
504-
if (item?.data_type === "group" && Array.isArray(item?.schema)) {
504+
if(contentTypeSchema?.every((item)=> value?.value?.uid !== item?.uid)){
505+
setExistingField((prevOptions: ExistingFieldType) => {
506+
const { [key]: _, ...rest } = prevOptions; // Destructure to exclude the key to remove
507+
return {
508+
...rest
509+
};
510+
})
511+
}
512+
else if (item?.data_type === "group" && Array.isArray(item?.schema)) {
505513
item?.schema?.forEach((schemaItem) => {
506514

507515
if (value?.value?.uid === schemaItem?.uid && value?.label === `${item?.display_name} > ${schemaItem?.display_name}`) {
@@ -1918,7 +1926,7 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
19181926
...newMigrationData,
19191927
content_mapping:{
19201928
...newMigrationData?.content_mapping,
1921-
existingCT: contentTypes,
1929+
[isContentType ? 'existingCT' : 'existingGlobal']: contentTypes,
19221930
content_type_mapping : updatedContentTypeMapping
19231931

19241932
}
@@ -2289,7 +2297,7 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
22892297
</span>
22902298
<span className='ml-10'>
22912299
<Tooltip content="Schema Preview" position="bottom">
2292-
<button className='list-button schema-preview' onClick={() => handleSchemaPreview(content?.otherCmsTitle, content?.id ?? '')}>{SCHEMA_PREVIEW}</button>
2300+
<button className='list-button schema-preview' aria-label="schemaPreview" onClick={() => handleSchemaPreview(content?.otherCmsTitle, content?.id ?? '')}>{SCHEMA_PREVIEW}</button>
22932301
</Tooltip>
22942302
</span>
22952303
</div>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ const LanguageMapper = () => {
386386

387387
setoptions(allLocales);
388388
Object?.entries(newMigrationData?.destination_stack?.localeMapping)?.length === 0 &&
389+
newMigrationData?.project_current_step <= 2 &&
389390
setcmsLocaleOptions((prevList: { label: string; value: string }[]) => {
390391
const newLabel = newMigrationData?.destination_stack?.selectedStack?.master_locale;
391392

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,10 @@ const LoadStacks = (props: LoadFileFormatProps) => {
236236
dispatch(updateNewMigrationData(newMigrationDataObj));
237237
}
238238
const newMigrationDataObj: INewMigration = {
239-
// ...newMigrationDataRef?.current,
240-
...newMigrationData,
239+
...newMigrationDataRef?.current,
240+
//...newMigrationData,
241241
destination_stack: {
242-
...newMigrationData?.destination_stack,
242+
...newMigrationDataRef?.current?.destination_stack,
243243
csLocale: csLocales?.data?.locales
244244
}
245245
};
@@ -316,15 +316,17 @@ const LoadStacks = (props: LoadFileFormatProps) => {
316316
</div>
317317
</div>
318318
<div className="col-12">
319-
<label className="title">Master Locale <span className='asterisk_input'></span>
319+
<label className="title" htmlFor="master_locale">Master Locale <span className='asterisk_input'></span>
320320
</label>
321321
<Tooltip content="Master Locale is auto-selected based on the chosen stack." position='right'>
322322
<Icon icon='Information' version='v2' size='small'></Icon>
323323
</Tooltip>
324324

325325
</div>
326-
<div className="col-12 pb-2">
326+
<div className="col-12 pb-2" id="master_locale">
327327
<TextInput
328+
id="master_locale"
329+
aria-label="master_locale"
328330
version={'v2'}
329331
placeholder={selectedStack?.master_locale ? '' : 'Master Locale will be set after stack selection'}
330332
value={selectedStack?.master_locale }

ui/src/components/LegacyCms/Actions/LoadFileFormat.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ const LoadFileFormat = (props: LoadFileFormatProps) => {
112112
...newMigrationDataRef?.current,
113113
legacy_cms: {
114114
...newMigrationDataRef?.current?.legacy_cms,
115-
selectedFileFormat: selectedFileFormatObj
115+
selectedFileFormat: selectedFileFormatObj,
116116
}
117117
};
118118

@@ -131,7 +131,7 @@ const LoadFileFormat = (props: LoadFileFormatProps) => {
131131
/**** ALL USEEffects HERE ****/
132132
useEffect(()=>{
133133
handleFileFormat();
134-
handleBtnClick();
134+
//handleBtnClick();
135135
},[]);
136136

137137
useEffect(() => {

ui/src/components/LegacyCms/Actions/LoadUploadFile.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ const LoadUploadFile = (props: LoadUploadFileProps) => {
8989
//const [isCancelLoading, setIsCancelLoading] = useState<boolean>(false);
9090
//const [setIsFormatValid] = useState<boolean>(false);
9191
const [affix, setAffix] = useState<string>(newMigrationData?.legacy_cms?.affix);
92+
const [reValidate, setReValidate] = useState<boolean>(newMigrationData?.legacy_cms?.uploadedFile?.reValidate || false);
9293

9394
const { projectId = '' } = useParams();
9495

@@ -394,6 +395,7 @@ const LoadUploadFile = (props: LoadUploadFileProps) => {
394395
if(!isEmptyString(newMigrationData?.legacy_cms?.affix) && !newMigrationData?.legacy_cms?.uploadedFile?.isValidated ){
395396
setIsDisabled(false);
396397
}
398+
setReValidate(newMigrationData?.legacy_cms?.uploadedFile?.reValidate || false);
397399

398400
// else{
399401
// setIsValidated(false);
@@ -466,7 +468,7 @@ const LoadUploadFile = (props: LoadUploadFileProps) => {
466468
isLoading={isLoading}
467469
loadingColor="#6c5ce7"
468470
version="v2"
469-
disabled={isDisabled || isEmptyString(affix)}
471+
disabled={isDisabled || isEmptyString(affix) || reValidate}
470472
>
471473
Validate File
472474
</Button>

ui/src/components/LegacyCms/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ const LegacyCMSComponent = forwardRef(({ legacyCMSData, isCompleted, handleOnAll
132132
? selectedCmsData.allowed_file_formats?.find(
133133
(cms: ICardType) => cms?.fileformat_id === legacyCMSData?.file_format
134134
)
135-
: defaultCardType;
135+
: newMigrationData?.legacy_cms?.selectedFileFormat;
136136

137137
//Make Step 1 Complete
138138
if (!isEmptyString(selectedCmsData?.cms_id || newMigrationData?.legacy_cms?.selectedCms?.cms_id)) {
@@ -164,7 +164,8 @@ const LegacyCMSComponent = forwardRef(({ legacyCMSData, isCompleted, handleOnAll
164164
awsData: legacyCMSData?.awsDetails,
165165
isLocalPath: legacyCMSData?.is_localPath
166166
},
167-
isValidated: legacyCMSData?.is_fileValid ,
167+
isValidated: legacyCMSData?.is_fileValid,
168+
reValidate: newMigrationData?.legacy_cms?.uploadedFile?.reValidate
168169
}, //need to add backend data once endpoint exposed.
169170
affix: legacyCMSData?.affix ?? '',
170171
isFileFormatCheckboxChecked: true, //need to add backend data once endpoint exposed.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ export const DEFAULT_NEW_MIGRATION: INewMigration = {
372372
destination_stack: DEFAULT_DESTINATION_STACK,
373373
content_mapping: DEFAULT_CONTENT_MAPPER,
374374
test_migration: DEFAULT_TEST_MIGRATION,
375-
isprojectMapped: false,
375+
isprojectMapped: true,
376376
stackDetails: DEFAULT_DROPDOWN,
377377
testStacks: [],
378378
migration_execution: DEFAULT_MIGRATION_EXECUTION_STEP,

ui/src/pages/Migration/index.tsx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,14 @@ const Migration = () => {
8484
const [isLoading, setIsLoading] = useState(false);
8585
const [currentStepIndex, setCurrentStepIndex] = useState(0);
8686
const [isCompleted, setIsCompleted] = useState<boolean>(false);
87-
const [isProjectMapper, setIsProjectMapper] = useState<boolean>(false);
87+
const [isProjectMapper, setIsProjectMapper] = useState<boolean>(true);
8888

8989
const [disableMigration, setDisableMigration] = useState(false);
9090
const [isModalOpen, setIsModalOpen] = useState(false);
9191

9292

9393
const saveRef = useRef<ContentTypeSaveHandles>(null);
94+
const newMigrationDataRef = useRef(newMigrationData);
9495

9596
useEffect(() => {
9697
fetchData();
@@ -99,14 +100,14 @@ const Migration = () => {
99100
/**
100101
* Dispatches the isprojectMapped key to redux
101102
*/
102-
useEffect(()=> {
103-
dispatch(updateNewMigrationData({
104-
...newMigrationData,
105-
isprojectMapped: isProjectMapper
103+
// useEffect(()=> {
104+
// dispatch(updateNewMigrationData({
105+
// ...newMigrationDataRef?.current,
106+
// isprojectMapped: isProjectMapper
106107

107-
}));
108+
// }));
108109

109-
},[isProjectMapper]);
110+
// },[isProjectMapper]);
110111

111112

112113
useBlockNavigation(isModalOpen);
@@ -182,15 +183,14 @@ const Migration = () => {
182183
*/
183184
const fetchProjectData = async () => {
184185
if (isEmptyString(selectedOrganisation?.value) || isEmptyString(params?.projectId)) return;
185-
186+
setIsProjectMapper(true);
186187
const data = await getMigrationData(selectedOrganisation?.value, params?.projectId ?? '');
187188
const migratedstacks = await getMigratedStacks(selectedOrganisation?.value, projectId );
188189

189190
if (data) {
190191
setIsLoading(false);
191192
setProjectData(data?.data);
192193
}
193-
setIsProjectMapper(true);
194194
const projectData = data?.data;
195195

196196
const legacyCmsData:ILegacyCMSComponent = await getCMSDataFromFile(CS_ENTRIES.LEGACY_CMS);
@@ -239,11 +239,11 @@ const Migration = () => {
239239
const projectMapper = {
240240
...newMigrationData,
241241
legacy_cms: {
242-
...newMigrationData?.legacy_cms,
242+
...newMigrationDataRef?.current?.legacy_cms,
243243
selectedCms: selectedCmsData,
244-
selectedFileFormat: selectedFileFormatData,
245244
affix: projectData?.legacy_cms?.affix ,
246245
uploadedFile: {
246+
...newMigrationDataRef?.current?.legacy_cms,
247247
file_details: {
248248
localPath: projectData?.legacy_cms?.file_path,
249249
awsData: {
@@ -289,6 +289,7 @@ const Migration = () => {
289289
},
290290
stackDetails: projectData?.stackDetails,
291291
testStacks: projectData?.test_stacks,
292+
isprojectMapped: false,
292293
project_current_step: projectData?.current_step,
293294
};
294295

@@ -502,7 +503,7 @@ const Migration = () => {
502503
} else if (! hasNonEmptyMapping) {
503504
setIsLoading(false);
504505
Notification({
505-
notificationContent: { text: 'Please complete the language mapping to preceed futher' },
506+
notificationContent: { text: 'Please complete the language mapping to proceed futher' },
506507
type: 'warning'
507508
});
508509
}

0 commit comments

Comments
 (0)