fix(logic): 🐛 Parse variables for code step
This commit is contained in:
@ -1,11 +1,14 @@
|
|||||||
import { Box, BoxProps } from '@chakra-ui/react'
|
import { Box, BoxProps } from '@chakra-ui/react'
|
||||||
import { EditorState, EditorView, basicSetup } from '@codemirror/basic-setup'
|
import { EditorState, EditorView, basicSetup } from '@codemirror/basic-setup'
|
||||||
import { json } from '@codemirror/lang-json'
|
import { json, jsonParseLinter } from '@codemirror/lang-json'
|
||||||
import { css } from '@codemirror/lang-css'
|
import { css } from '@codemirror/lang-css'
|
||||||
import { javascript } from '@codemirror/lang-javascript'
|
import { javascript } from '@codemirror/lang-javascript'
|
||||||
import { html } from '@codemirror/lang-html'
|
import { html } from '@codemirror/lang-html'
|
||||||
import { useEffect, useRef, useState } from 'react'
|
import { useEffect, useRef, useState } from 'react'
|
||||||
import { useDebouncedCallback } from 'use-debounce'
|
import { useDebouncedCallback } from 'use-debounce'
|
||||||
|
import { linter } from '@codemirror/lint'
|
||||||
|
|
||||||
|
const linterExtension = linter(jsonParseLinter())
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
value: string
|
value: string
|
||||||
@ -71,7 +74,10 @@ export const CodeEditor = ({
|
|||||||
basicSetup,
|
basicSetup,
|
||||||
EditorState.readOnly.of(isReadOnly),
|
EditorState.readOnly.of(isReadOnly),
|
||||||
]
|
]
|
||||||
if (lang === 'json') extensions.push(json())
|
if (lang === 'json') {
|
||||||
|
extensions.push(json())
|
||||||
|
extensions.push(linterExtension)
|
||||||
|
}
|
||||||
if (lang === 'css') extensions.push(css())
|
if (lang === 'css') extensions.push(css())
|
||||||
if (lang === 'js') extensions.push(javascript())
|
if (lang === 'js') extensions.push(javascript())
|
||||||
if (lang === 'html') extensions.push(html())
|
if (lang === 'html') extensions.push(html())
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
"docker:nuke": "docker compose -f docker-compose.dev.yml down --volumes --remove-orphans",
|
"docker:nuke": "docker compose -f docker-compose.dev.yml down --volumes --remove-orphans",
|
||||||
"dev:prepare": "turbo run build --scope=bot-engine --no-deps --include-dependencies",
|
"dev:prepare": "turbo run build --scope=bot-engine --no-deps --include-dependencies",
|
||||||
"dev": "yarn docker:up && yarn dev:prepare && turbo run dx --parallel",
|
"dev": "yarn docker:up && yarn dev:prepare && turbo run dx --parallel",
|
||||||
"dev:mocking": "yarn docker:up && NEXT_PUBLIC_E2E_TEST=enabled turbo run dev --parallel",
|
"dev:mocking": "yarn docker:up && NEXT_PUBLIC_E2E_TEST=enabled turbo run dx --parallel",
|
||||||
"build": "yarn docker:up && turbo run build",
|
"build": "yarn docker:up && turbo run build",
|
||||||
"test:builder": "cd apps/builder && yarn test",
|
"test:builder": "cd apps/builder && yarn test",
|
||||||
"lint": "turbo run lint",
|
"lint": "turbo run lint",
|
||||||
|
@ -48,7 +48,7 @@ export const executeLogic = async (
|
|||||||
case LogicStepType.REDIRECT:
|
case LogicStepType.REDIRECT:
|
||||||
return { nextEdgeId: executeRedirect(step, context) }
|
return { nextEdgeId: executeRedirect(step, context) }
|
||||||
case LogicStepType.CODE:
|
case LogicStepType.CODE:
|
||||||
return { nextEdgeId: executeCode(step) }
|
return { nextEdgeId: executeCode(step, context) }
|
||||||
case LogicStepType.TYPEBOT_LINK:
|
case LogicStepType.TYPEBOT_LINK:
|
||||||
return await executeTypebotLink(step, context)
|
return await executeTypebotLink(step, context)
|
||||||
}
|
}
|
||||||
@ -121,9 +121,12 @@ const executeRedirect = (
|
|||||||
return step.outgoingEdgeId
|
return step.outgoingEdgeId
|
||||||
}
|
}
|
||||||
|
|
||||||
const executeCode = (step: CodeStep) => {
|
const executeCode = (
|
||||||
|
step: CodeStep,
|
||||||
|
{ typebot: { variables } }: LogicContext
|
||||||
|
) => {
|
||||||
if (!step.options.content) return
|
if (!step.options.content) return
|
||||||
Function(step.options.content)()
|
Function(parseVariables(variables)(step.options.content))()
|
||||||
return step.outgoingEdgeId
|
return step.outgoingEdgeId
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user