Skip to content

Commit

Permalink
fix(logic): 🐛 Parse variables for code step
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Mar 15, 2022
1 parent eef60fd commit fb3d2bc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
10 changes: 8 additions & 2 deletions apps/builder/components/shared/CodeEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { Box, BoxProps } from '@chakra-ui/react'
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 { javascript } from '@codemirror/lang-javascript'
import { html } from '@codemirror/lang-html'
import { useEffect, useRef, useState } from 'react'
import { useDebouncedCallback } from 'use-debounce'
import { linter } from '@codemirror/lint'

const linterExtension = linter(jsonParseLinter())

type Props = {
value: string
Expand Down Expand Up @@ -71,7 +74,10 @@ export const CodeEditor = ({
basicSetup,
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 === 'js') extensions.push(javascript())
if (lang === 'html') extensions.push(html())
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"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": "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",
"test:builder": "cd apps/builder && yarn test",
"lint": "turbo run lint",
Expand Down
9 changes: 6 additions & 3 deletions packages/bot-engine/src/services/logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const executeLogic = async (
case LogicStepType.REDIRECT:
return { nextEdgeId: executeRedirect(step, context) }
case LogicStepType.CODE:
return { nextEdgeId: executeCode(step) }
return { nextEdgeId: executeCode(step, context) }
case LogicStepType.TYPEBOT_LINK:
return await executeTypebotLink(step, context)
}
Expand Down Expand Up @@ -121,9 +121,12 @@ const executeRedirect = (
return step.outgoingEdgeId
}

const executeCode = (step: CodeStep) => {
const executeCode = (
step: CodeStep,
{ typebot: { variables } }: LogicContext
) => {
if (!step.options.content) return
Function(step.options.content)()
Function(parseVariables(variables)(step.options.content))()
return step.outgoingEdgeId
}

Expand Down

2 comments on commit fb3d2bc

@vercel
Copy link

@vercel vercel bot commented on fb3d2bc Mar 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-v2 – ./apps/builder

builder-v2-git-main-typebot-io.vercel.app
builder-v2-typebot-io.vercel.app
app.typebot.io

Please sign in to comment.