Skip to content

Commit dd21771

Browse files
committed
Merge branch 'feature/live-preview' of https://github.com/contentstack/contentstack-utils-javascript into feature/live-preview
2 parents a3a51ed + 1a01734 commit dd21771

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/entry-editable.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { EntryModel } from ".";
22

3-
export function addTags(entry: EntryModel, contentTypeUid: string, tagsAsObject: boolean, locale: string = 'en-us') : void {
4-
entry["$"] = getTag(entry, `${contentTypeUid}.${entry.uid}.${locale}`, tagsAsObject, locale)
3+
export function addTags(entry: EntryModel, contentTypeUid: string, tagsAsObject: boolean, locale: string = 'en-us') : void {
4+
if (entry)
5+
entry["$"] = getTag(entry, `${contentTypeUid}.${entry.uid}.${locale}`, tagsAsObject, locale)
56
}
67

78
function getTag(content: object, prefix: string, tagsAsObject: boolean, locale: string): object {
@@ -11,7 +12,7 @@ function getTag(content: object, prefix: string, tagsAsObject: boolean, locale:
1112
case "object":
1213
if (Array.isArray(value)) {
1314
value.forEach((obj, index) => {
14-
if (obj._content_type_uid !== undefined && obj.uid !== undefined) {
15+
if ((typeof obj !== 'undefined' || obj !== null) && obj._content_type_uid !== undefined && obj.uid !== undefined) {
1516
value[index]['$'] = getTag(obj, `${obj._content_type_uid}.${obj.uid}.${obj.locale || locale}`, tagsAsObject, locale)
1617
}else {
1718
if (typeof obj === "object") {
@@ -22,7 +23,9 @@ function getTag(content: object, prefix: string, tagsAsObject: boolean, locale:
2223
}
2324
})
2425
}else {
25-
value["$"] = getTag(value, `${prefix}.${key}`, tagsAsObject, locale)
26+
if (value) {
27+
value["$"] = getTag(value, `${prefix}.${key}`, tagsAsObject, locale)
28+
}
2629
}
2730
break;
2831
default:

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@
1919
"sourceMap": true,
2020
},
2121
"include": ["src"],
22-
"exclude": ["node_modules", "__tests__"]
22+
"exclude": ["node_modules", "__test__"]
2323
}

0 commit comments

Comments
 (0)