From 2f1df2c6ce0ad826fe50a1db07b5372447a592f5 Mon Sep 17 00:00:00 2001 From: Chenlei Hu Date: Mon, 5 Aug 2024 16:57:36 -0400 Subject: [PATCH] Proper truncate of long content in node preview (#313) --- src/components/NodePreview.vue | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/components/NodePreview.vue b/src/components/NodePreview.vue index 43d21331f..1bf8c35b0 100644 --- a/src/components/NodePreview.vue +++ b/src/components/NodePreview.vue @@ -73,11 +73,20 @@ const slotInputDefs = allInputDefs.filter( const widgetInputDefs = allInputDefs.filter((input) => nodeDefStore.inputIsWidget(input) ) -const truncateDefaultValue = (value: any): string => { - if (value instanceof Object) { - return _.truncate(JSON.stringify(value), { length: 20 }) +const truncateDefaultValue = (value: any, charLimit: number = 32): string => { + let stringValue: string + + if (typeof value === 'object' && value !== null) { + stringValue = JSON.stringify(value) + } else if (Array.isArray(value)) { + stringValue = JSON.stringify(value) + } else if (typeof value === 'string') { + stringValue = value + } else { + stringValue = String(value) } - return value + + return _.truncate(stringValue, { length: charLimit }) }