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
36 changes: 16 additions & 20 deletions api/src/services/contentMapper.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,19 +442,21 @@ const getExistingContentTypes = async (req: Request) => {
let selectedContentType = null;

if (contentTypeUID) {
const [res] = await safePromise(
const [err, res] = await safePromise(
https({
method: 'GET',
url: `${baseUrl}/${contentTypeUID}`,
headers,
}),
);

selectedContentType = {
title: res?.data?.content_type?.title,
uid: res?.data?.content_type?.uid,
schema: res?.data?.content_type?.schema,
};
if (!err) {
selectedContentType = {
title: res?.data?.content_type?.title,
uid: res?.data?.content_type?.uid,
schema: res?.data?.content_type?.schema,
};
}
}
return {
contentTypes: processedContentTypes,
Expand Down Expand Up @@ -549,27 +551,21 @@ const getExistingGlobalFields = async (req: Request) => {
let selectedGlobalField = null;

if (globalFieldUID) {
const [res] = await safePromise(
const [err, res] = await safePromise(
https({
method: 'GET',
url: `${baseUrl}/${globalFieldUID}`,
headers,
}),
);

// if (err) {
// throw new Error(
// `Error fetching selected global field: ${
// err.response?.data || err.message
// }`
// );
// }

selectedGlobalField = {
title: res?.data?.global_field?.title,
uid: res?.data?.global_field?.uid,
schema: res?.data?.global_field?.schema,
};
if (!err) {
selectedGlobalField = {
title: res?.data?.global_field?.title,
uid: res?.data?.global_field?.uid,
schema: res?.data?.global_field?.schema,
};
}
}

return { globalFields: processedGlobalFields, selectedGlobalField };
Expand Down
56 changes: 31 additions & 25 deletions api/src/utils/content-type-creator.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,29 +160,24 @@ function buildFieldSchema(item: any, marketPlacePath: string, parentUid = ''): a
}
}

if (blockSchema.length > 0) {
blocks.push({
title: blockRawUid, // Keep original for title
uid: blockUid, // Snake case for uid
schema: removeDuplicateFields(blockSchema)
});
}
blocks.push({
title: blockRawUid, // Keep original for title
uid: blockUid, // Snake case for uid
schema: removeDuplicateFields(blockSchema)
});
}

if (blocks.length > 0) {
return {
data_type: "blocks",
display_name: item?.display_name || rawUid, // Keep original for display
field_metadata: {},
uid: itemUid, // Snake case uid
multiple: true,
mandatory: false,
unique: false,
non_localizable: false,
blocks: removeDuplicateFields(blocks)
};
}
return null;
return {
data_type: "blocks",
display_name: item?.display_name || rawUid, // Keep original for display
field_metadata: {},
uid: itemUid, // Snake case uid
multiple: true,
mandatory: false,
unique: false,
non_localizable: false,
blocks: removeDuplicateFields(blocks)
};
}

if (fieldType === 'group') {
Expand Down Expand Up @@ -316,14 +311,25 @@ export function buildSchemaTree(fields: any[], parentUid = '', parentType = '',

if (hasChildren) {
if (fieldType === 'modular_blocks') {
// Get modular block children
// Get modular block children (check both current and backup UIDs)
const mbChildren = fields.filter(f => {
if (!f) return false;
const fUid = f?.contentstackFieldUid || '';
if (!fUid || !fieldUid) return false;
return f?.contentstackFieldType === 'modular_blocks_child' &&
fUid.startsWith(fieldUid + '.') &&
!fUid.substring(fieldUid.length + 1).includes('.');
if (f?.contentstackFieldType !== 'modular_blocks_child') return false;

if (fUid.startsWith(fieldUid + '.') &&
!fUid.substring(fieldUid.length + 1).includes('.')) {
return true;
}

if (oldFieldUid && oldFieldUid !== fieldUid &&
fUid.startsWith(oldFieldUid + '.') &&
!fUid.substring(oldFieldUid.length + 1).includes('.')) {
return true;
}

return false;
});

result.schema = mbChildren.map(child => {
Expand Down