Skip to content

Commit 2f1df2c

Browse files
authored
Proper truncate of long content in node preview (#313)
1 parent 3269b54 commit 2f1df2c

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/components/NodePreview.vue

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,20 @@ const slotInputDefs = allInputDefs.filter(
7373
const widgetInputDefs = allInputDefs.filter((input) =>
7474
nodeDefStore.inputIsWidget(input)
7575
)
76-
const truncateDefaultValue = (value: any): string => {
77-
if (value instanceof Object) {
78-
return _.truncate(JSON.stringify(value), { length: 20 })
76+
const truncateDefaultValue = (value: any, charLimit: number = 32): string => {
77+
let stringValue: string
78+
79+
if (typeof value === 'object' && value !== null) {
80+
stringValue = JSON.stringify(value)
81+
} else if (Array.isArray(value)) {
82+
stringValue = JSON.stringify(value)
83+
} else if (typeof value === 'string') {
84+
stringValue = value
85+
} else {
86+
stringValue = String(value)
7987
}
80-
return value
88+
89+
return _.truncate(stringValue, { length: charLimit })
8190
}
8291
</script>
8392

0 commit comments

Comments
 (0)