Skip to content

Commit

Permalink
Merge pull request #1423 from contentstack/fix/DX-647
Browse files Browse the repository at this point in the history
DX - 647 - fixed the bug with rich text type and bugs in entries helper
  • Loading branch information
cs-raj authored Jun 4, 2024
2 parents 301d39f + f57d92b commit 7df5a10
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 95 deletions.
120 changes: 63 additions & 57 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/contentstack-clone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dependencies": {
"@colors/colors": "^1.5.0",
"@contentstack/cli-cm-export": "~1.11.4",
"@contentstack/cli-cm-import": "~1.15.6",
"@contentstack/cli-cm-import": "~1.15.7",
"@contentstack/cli-command": "~1.2.18",
"@contentstack/cli-utilities": "~1.6.2",
"async": "^3.2.4",
Expand Down Expand Up @@ -72,4 +72,4 @@
"cm:stack-clone": "O-CLN"
}
}
}
}
4 changes: 2 additions & 2 deletions packages/contentstack-import/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli-cm-import",
"description": "Contentstack CLI plugin to import content into stack",
"version": "1.15.6",
"version": "1.15.7",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
Expand Down Expand Up @@ -99,4 +99,4 @@
}
},
"repository": "https://github.com/contentstack/cli"
}
}
10 changes: 5 additions & 5 deletions packages/contentstack-import/src/utils/asset-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ export const lookupAssets = function (
if (
schema[i].data_type === 'text' &&
schema[i].field_metadata &&
(schema[i].field_metadata.markdown || schema[i].field_metadata.rich_text_type)
(schema[i]?.field_metadata?.markdown || schema[i]?.field_metadata?.rich_text_type)
) {
parent.push(schema[i].uid);
findFileUrls(schema[i], entryToFind, assetUrls);
if (schema[i].field_metadata.rich_text_type) {
if (schema[i]?.field_metadata?.rich_text_type) {
findAssetIdsFromHtmlRte(entryToFind, schema[i]);
}
parent.pop();
Expand All @@ -110,7 +110,7 @@ export const lookupAssets = function (
}
// added rich_text_type field check because some marketplace extensions also
// have data_type has json
if (schema[i].data_type === 'json' && schema[i].field_metadata.rich_text_type) {
if (schema[i].data_type === 'json' && schema[i]?.field_metadata?.rich_text_type) {
parent.push(schema[i].uid);
// findFileUrls(schema[i], entry, assetUrls)
findAssetIdsFromJsonRte(data.entry, data.content_type.schema);
Expand Down Expand Up @@ -188,7 +188,7 @@ export const lookupAssets = function (
break;
}
case 'json': {
if (entryObj[element.uid] && element.field_metadata.rich_text_type) {
if (entryObj[element.uid] && element?.field_metadata?.rich_text_type) {
if (element.multiple) {
entryObj[element.uid].forEach((jsonRteData: any) => {
gatherJsonRteAssetIds(jsonRteData);
Expand Down Expand Up @@ -267,7 +267,7 @@ export const lookupAssets = function (
if (typeof uid !== 'undefined') {
const escapedAssetUid = assetUid.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
const regex = new RegExp(`\\b${escapedAssetUid}\\b`, 'img');
let { status } = validateRegex(new RegExp(regex, 'img'))
let { status } = validateRegex(new RegExp(regex, 'img'));
if (status === 'safe') {
entry = entry.replace(regex, uid);
matchedUids.push(assetUid);
Expand Down
18 changes: 9 additions & 9 deletions packages/contentstack-import/src/utils/content-type-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ export const suppressSchemaReference = function (schema: any, flag: any) {
}
} else if (schema[i].data_type === 'reference') {
flag.references = true;
} else if (schema[i].data_type === 'json' && schema[i].field_metadata.rich_text_type) {
} else if (schema[i].data_type === 'json' && schema[i]?.field_metadata?.rich_text_type) {
flag.jsonRte = true;
if (schema[i].field_metadata.embed_entry === true) flag.jsonRteEmbeddedEntries = true;
} else if (schema[i].data_type === 'text' && schema[i].field_metadata.rich_text_type) {
} else if (schema[i].data_type === 'text' && schema[i]?.field_metadata?.rich_text_type) {
flag.rte = true;
if (schema[i].field_metadata.embed_entry === true) flag.rteEmbeddedEntries = true;
}
Expand Down Expand Up @@ -143,18 +143,18 @@ export const removeReferenceFields = async function (
} else if (
// handling entry references in json rte
schema[i].data_type === 'json' &&
schema[i].field_metadata.rich_text_type &&
schema[i].field_metadata.embed_entry &&
schema[i].reference_to.length > 1
schema[i]?.field_metadata?.rich_text_type &&
schema[i]?.field_metadata?.embed_entry &&
schema[i]?.reference_to?.length > 1
) {
flag.supressed = true;
schema[i].reference_to = ['sys_assets'];
} else if (
// handling entry references in rte
schema[i].data_type === 'text' &&
schema[i].field_metadata.rich_text_type &&
schema[i].field_metadata.embed_entry &&
schema[i].reference_to.length >= 1
schema[i]?.field_metadata?.rich_text_type &&
schema[i]?.field_metadata?.embed_entry &&
schema[i]?.reference_to?.length >= 1
) {
flag.supressed = true;
schema[i].reference_to = ['sys_assets'];
Expand Down Expand Up @@ -185,4 +185,4 @@ export const updateFieldRules = function (contentType: any) {
}
}
return fieldRules;
}
};
Loading

0 comments on commit 7df5a10

Please sign in to comment.