11import { TDataOutMetadatumType } from '@plumber/types'
22
3- import { useMemo , useRef } from 'react'
3+ import { useMemo , useRef , useState } from 'react'
44import { IconType } from 'react-icons/lib'
55import {
66 Accordion ,
@@ -25,6 +25,7 @@ import TableVariableItem from './TableVariableItem'
2525
2626const VARIABLE_ITEM_HEIGHT = 77
2727const SUGGESTION_VARIABLE_ITEM_HEIGHT = 61
28+ const CHARACTER_LIMIT = 100
2829
2930function VariableTag ( {
3031 type,
@@ -92,24 +93,33 @@ export function VariableItem({
9293 isLast ?: boolean
9394 withIcon ?: IconType
9495} ) : JSX . Element {
96+ const [ isExpanded , setIsExpanded ] = useState ( false )
9597 const shouldShowBottomBorder = ! withIcon && ( onClick || isLast )
9698
9799 const displayValue =
98100 variable . displayedValue ?? variable . value ?. toString ( ) ?? ''
99101
100102 const isSuggestionVariable = onClick && ! withIcon
103+
104+ const shouldShowToggle =
105+ variable . type === 'ai_response' && displayValue . length > CHARACTER_LIMIT
106+
101107 return (
102108 < Box
103109 key = { `suggestion-${ variable . name } ` }
104110 data-test = "variable-suggestion-item"
105111 h = {
106112 isSuggestionVariable
107113 ? SUGGESTION_VARIABLE_ITEM_HEIGHT
114+ : shouldShowToggle
115+ ? 'auto'
108116 : VARIABLE_ITEM_HEIGHT
109117 }
110118 maxH = {
111119 isSuggestionVariable
112120 ? SUGGESTION_VARIABLE_ITEM_HEIGHT
121+ : shouldShowToggle
122+ ? 'auto'
113123 : VARIABLE_ITEM_HEIGHT
114124 }
115125 overflowY = "hidden"
@@ -149,22 +159,41 @@ export function VariableItem({
149159 >
150160 { variable . label ?? variable . name } < VariableTag type = { variable . type } />
151161 </ Text >
152- < Flex alignItems = "center" gap = { 2 } >
153- < Text
154- textStyle = "body-2"
155- color = "base.content.medium"
156- whiteSpace = "nowrap"
157- overflow = "hidden"
158- textOverflow = "ellipsis"
159- textDecoration = { withIcon ? 'underline' : undefined }
160- >
161- { displayValue . length ? (
162- displayValue
163- ) : (
164- < i style = { { opacity : 0.5 } } > empty</ i >
165- ) }
166- </ Text >
167- { withIcon && < Icon as = { withIcon } /> }
162+ < Flex flexDirection = "column" gap = { 1 } >
163+ < Flex alignItems = "center" gap = { 2 } >
164+ < Text
165+ textStyle = "body-2"
166+ color = "base.content.medium"
167+ whiteSpace = { isExpanded ? 'pre-wrap' : 'nowrap' }
168+ overflow = { isExpanded ? 'visible' : 'hidden' }
169+ textOverflow = { isExpanded ? 'clip' : 'ellipsis' }
170+ textDecoration = { withIcon ? 'underline' : undefined }
171+ >
172+ { displayValue . length ? (
173+ displayValue
174+ ) : (
175+ < i style = { { opacity : 0.5 } } > empty</ i >
176+ ) }
177+ </ Text >
178+ { withIcon && < Icon as = { withIcon } /> }
179+ </ Flex >
180+ { shouldShowToggle && (
181+ < Text
182+ textStyle = "body-2"
183+ color = "primary.500"
184+ cursor = "pointer"
185+ _hover = { { textDecoration : 'underline' } }
186+ onClick = { ( e ) => {
187+ e . stopPropagation ( )
188+ setIsExpanded ( ! isExpanded )
189+ } }
190+ onMouseDown = { ( e ) => {
191+ e . stopPropagation ( )
192+ } }
193+ >
194+ { isExpanded ? 'Show less' : 'Show more' }
195+ </ Text >
196+ ) }
168197 </ Flex >
169198 </ Box >
170199 )
0 commit comments