Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/src/services/contentMapper.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ const resetToInitialMapping = async (req: Request) => {

try {
if (!isEmpty(fieldMappingData)) {
await FieldMapperModel.read();
//await FieldMapperModel.read();
(fieldMappingData || []).forEach((field: any) => {
const fieldIndex = FieldMapperModel.data.field_mapper.findIndex(
(f: any) => f?.id === field?.id
Expand Down
51 changes: 40 additions & 11 deletions ui/src/components/ContentMapper/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
const [isFieldDeleted, setIsFieldDeleted] = useState<boolean>(false);
const [isContentDeleted, setIsContentDeleted] = useState<boolean>(false);
const [isCsCTypeUpdated, setsCsCTypeUpdated] = useState<boolean>(false);
const [isLoadingSaveButton, setisLoadingSaveButton] = useState<boolean>(false);


/** ALL HOOKS Here */
Expand Down Expand Up @@ -368,6 +369,9 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
contentTypeSchema?.forEach((schema) => {

if (row?.contentstackField === schema?.display_name) {
if (!updatedSelectedOptions.includes(schema?.display_name)) {
updatedSelectedOptions.push(schema?.display_name);
}
updatedExstingField[row?.uid] = {
label: schema?.display_name,
value: schema
Expand All @@ -379,6 +383,9 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
schema?.schema?.forEach((childSchema) => {
if(row?.contentstackField === `${schema?.display_name} > ${childSchema?.display_name}`) {
if(!isFieldDeleted) {
if (!updatedSelectedOptions.includes(`${schema?.display_name} > ${childSchema?.display_name}`)) {
updatedSelectedOptions.push(`${schema?.display_name} > ${childSchema?.display_name}`);
}
updatedExstingField[row?.uid] = {
label: `${schema?.display_name} > ${childSchema?.display_name}`,
value: childSchema
Expand All @@ -391,6 +398,9 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
childSchema?.schema?.forEach((nestedSchema) => {
if (row?.contentstackField === `${schema?.display_name} > ${childSchema?.display_name} > ${nestedSchema?.display_name}`) {
if(!isFieldDeleted) {
if (!updatedSelectedOptions.includes(`${schema?.display_name} > ${childSchema?.display_name} > ${nestedSchema?.display_name}`)) {
updatedSelectedOptions.push(`${schema?.display_name} > ${childSchema?.display_name} > ${nestedSchema?.display_name}`);
}
updatedExstingField[row?.uid] = {
label: `${schema?.display_name} > ${childSchema?.display_name} > ${nestedSchema?.display_name}`,
value: nestedSchema
Expand All @@ -403,6 +413,9 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
nestedSchema?.schema?.forEach((nestedChild) => {
if (row?.contentstackField === `${schema?.display_name} > ${childSchema?.display_name} > ${nestedSchema?.display_name} > ${nestedChild?.display_name}`) {
if(!isFieldDeleted) {
if (!updatedSelectedOptions.includes(`${schema?.display_name} > ${childSchema?.display_name} > ${nestedSchema?.display_name} > ${nestedChild?.display_name}`)) {
updatedSelectedOptions.push(`${schema?.display_name} > ${childSchema?.display_name} > ${nestedSchema?.display_name} > ${nestedChild?.display_name}`);
}
updatedExstingField[row?.uid] = {
label: `${schema?.display_name} > ${childSchema?.display_name} > ${nestedSchema?.display_name} > ${nestedChild?.display_name}`,
value: nestedChild
Expand All @@ -417,7 +430,7 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
}
});
});

setSelectedOptions(updatedSelectedOptions);
setExistingField(updatedExstingField);
}
}, [tableData, otherContentType]);
Expand Down Expand Up @@ -478,7 +491,10 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
contentTypeSchema?.forEach((item) => {
for (const [key, value] of Object.entries(existingField)) {
if (value?.value?.uid === item?.uid) {

if (!updatedSelectedOptions.includes(item?.display_name)) {
updatedSelectedOptions.push(item?.display_name);
}
setSelectedOptions(updatedSelectedOptions);
setExistingField((prevOptions: ExistingFieldType) => ({
...prevOptions,
[key]: { label: item?.display_name, value: item },
Expand All @@ -487,6 +503,10 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
if (item?.data_type === "group" && Array.isArray(item?.schema)) {
item.schema.forEach((schemaItem) => {
if (value?.value?.uid === schemaItem?.uid) {
if (!updatedSelectedOptions.includes(`${item?.display_name} > ${schemaItem?.display_name}`)) {
updatedSelectedOptions.push(`${item?.display_name} > ${schemaItem?.display_name}`);
}
setSelectedOptions(updatedSelectedOptions);
setExistingField((prevOptions: ExistingFieldType) => ({
...prevOptions,
[key]: { label: `${item?.display_name} > ${schemaItem?.display_name}`, value: schemaItem },
Expand Down Expand Up @@ -1567,6 +1587,7 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
};

const handleSaveContentType = async () => {
setisLoadingSaveButton(true);
const orgId = selectedOrganisation?.uid;
const projectID = projectId;
if (
Expand Down Expand Up @@ -1605,6 +1626,7 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
);

if (data?.status == 200) {
setisLoadingSaveButton(false);
Notification({
notificationContent: { text: 'Content type saved successfully' },
notificationProps: {
Expand Down Expand Up @@ -1704,7 +1726,12 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
setIsDropDownChanged(false);

const updatedRows: FieldMapType[] = tableData.map((row) => {
return { ...row, contentstackFieldType: row?.backupFieldType };
return { ...row,
contentstackFieldType: row?.backupFieldType,
contentstackField: row?.otherCmsField,
contentstackFieldUid: row?.uid,

};
});
setTableData(updatedRows);
setSelectedEntries(updatedRows);
Expand Down Expand Up @@ -1755,14 +1782,6 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
);
setFilteredContentTypes(resetCT);
setContentTypes(resetCT);

try {
await updateContentMapper(orgId, projectID, {...newstate} );
} catch (err) {
console.log(err);
return err;
}

Notification({
notificationContent: { text: data?.message },
notificationProps: {
Expand All @@ -1771,6 +1790,15 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
},
type: 'success'
});

try {
await updateContentMapper(orgId, projectID, {...newstate} );
} catch (err) {
console.log(err);
return err;
}


}
} catch (error) {
console.log(error);
Expand Down Expand Up @@ -2316,6 +2344,7 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
onClick={handleSaveContentType}
version="v2"
disabled={newMigrationData?.project_current_step > 4}
isLoading={isLoadingSaveButton}
>
Save
</Button>
Expand Down