2
0

🐛 (text) Fix text bubble content parsing when starting with variable

Closes #1594
This commit is contained in:
Baptiste Arnaud
2024-06-24 15:03:18 +02:00
parent b10383e027
commit 7790cf4f27
5 changed files with 38 additions and 4 deletions

View File

@@ -206,7 +206,7 @@ const SetVariableValue = ({
} }
onSelect={updateIsCode} onSelect={updateIsCode}
/> />
{options?.isCode === undefined || options.isCode ? ( {options?.isCode ? (
<CodeEditor <CodeEditor
defaultValue={options?.expressionToEvaluate ?? ''} defaultValue={options?.expressionToEvaluate ?? ''}
onChange={updateExpression} onChange={updateExpression}

View File

@@ -236,6 +236,9 @@
}, },
"maxWidth": { "maxWidth": {
"type": "string" "type": "string"
},
"queryParamsStr": {
"type": "string"
} }
} }
} }
@@ -4572,6 +4575,9 @@
}, },
"maxWidth": { "maxWidth": {
"type": "string" "type": "string"
},
"queryParamsStr": {
"type": "string"
} }
} }
} }
@@ -8045,6 +8051,9 @@
}, },
"maxWidth": { "maxWidth": {
"type": "string" "type": "string"
},
"queryParamsStr": {
"type": "string"
} }
} }
} }
@@ -16560,6 +16569,9 @@
}, },
"maxWidth": { "maxWidth": {
"type": "string" "type": "string"
},
"queryParamsStr": {
"type": "string"
} }
} }
} }
@@ -22872,6 +22884,9 @@
}, },
"maxWidth": { "maxWidth": {
"type": "string" "type": "string"
},
"queryParamsStr": {
"type": "string"
} }
} }
} }
@@ -25714,6 +25729,9 @@
}, },
"maxWidth": { "maxWidth": {
"type": "string" "type": "string"
},
"queryParamsStr": {
"type": "string"
} }
} }
} }

View File

@@ -3433,6 +3433,9 @@
}, },
"maxWidth": { "maxWidth": {
"type": "string" "type": "string"
},
"queryParamsStr": {
"type": "string"
} }
} }
} }
@@ -7594,6 +7597,9 @@
}, },
"maxWidth": { "maxWidth": {
"type": "string" "type": "string"
},
"queryParamsStr": {
"type": "string"
} }
} }
} }
@@ -12777,6 +12783,9 @@
}, },
"maxWidth": { "maxWidth": {
"type": "string" "type": "string"
},
"queryParamsStr": {
"type": "string"
} }
} }
} }

View File

@@ -16,6 +16,7 @@ import { BubbleBlockType } from '@typebot.io/schemas/features/blocks/bubbles/con
import { defaultVideoBubbleContent } from '@typebot.io/schemas/features/blocks/bubbles/video/constants' import { defaultVideoBubbleContent } from '@typebot.io/schemas/features/blocks/bubbles/video/constants'
import { convertMarkdownToRichText } from '@typebot.io/lib/markdown/convertMarkdownToRichText' import { convertMarkdownToRichText } from '@typebot.io/lib/markdown/convertMarkdownToRichText'
import { convertRichTextToMarkdown } from '@typebot.io/lib/markdown/convertRichTextToMarkdown' import { convertRichTextToMarkdown } from '@typebot.io/lib/markdown/convertRichTextToMarkdown'
import { isSingleVariable } from '@typebot.io/variables/isSingleVariable'
type Params = { type Params = {
version: 1 | 2 version: 1 | 2
@@ -144,7 +145,9 @@ export const parseVariablesInRichText = (
: undefined : undefined
lastTextEndIndex = variableInText.endIndex lastTextEndIndex = variableInText.endIndex
const isStandaloneElement = const isStandaloneElement =
isEmpty(textBeforeVariable) && isEmpty(textAfterVariable) isEmpty(textBeforeVariable) &&
isEmpty(textAfterVariable) &&
variablesInText.length === 1
const variableElements = convertMarkdownToRichText( const variableElements = convertMarkdownToRichText(
isStandaloneElement isStandaloneElement
? variableInText.value ? variableInText.value
@@ -193,8 +196,7 @@ export const parseVariablesInRichText = (
const type = const type =
element.children.length === 1 && element.children.length === 1 &&
'text' in element.children[0] && 'text' in element.children[0] &&
(element.children[0].text as string).startsWith('{{') && isSingleVariable(element.children[0].text as string) &&
(element.children[0].text as string).endsWith('}}') &&
element.type !== 'a' element.type !== 'a'
? 'variable' ? 'variable'
: element.type : element.type

View File

@@ -0,0 +1,5 @@
export const isSingleVariable = (value: string | undefined): boolean =>
!!value &&
value.startsWith('{{') &&
value.endsWith('}}') &&
value.split('{{').length === 2