Skip to content

Commit

Permalink
♻️ Rename Code block to Script block
Browse files Browse the repository at this point in the history
Closes #245
  • Loading branch information
baptisteArno committed Jan 27, 2023
1 parent 068f9bb commit a842f57
Show file tree
Hide file tree
Showing 35 changed files with 113 additions and 103 deletions.

This file was deleted.

3 changes: 0 additions & 3 deletions apps/builder/src/features/blocks/logic/code/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { featherIconsBaseProps } from '@/components/icons'
import { Icon, IconProps, useColorModeValue } from '@chakra-ui/react'
import React from 'react'

export const ScriptIcon = (props: IconProps) => (
<Icon
viewBox="0 0 24 24"
color={useColorModeValue('purple.500', 'purple.300')}
{...featherIconsBaseProps}
{...props}
>
<polyline points="4 17 10 11 4 5"></polyline>
<line x1="12" y1="19" x2="20" y2="19"></line>
</Icon>
)
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react'
import { Text } from '@chakra-ui/react'
import { CodeOptions } from 'models'
import { ScriptOptions } from 'models'

type Props = CodeOptions
type Props = ScriptOptions

export const CodeNodeContent = ({ name, content }: Props) => (
export const ScriptNodeContent = ({ name, content }: Props) => (
<Text color={content ? 'currentcolor' : 'gray.500'} noOfLines={1}>
{content ? `Run ${name}` : 'Configure...'}
</Text>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { FormLabel, Stack, Text } from '@chakra-ui/react'
import { CodeEditor } from '@/components/CodeEditor'
import { CodeOptions } from 'models'
import React from 'react'
import { SwitchWithLabel } from '@/components/SwitchWithLabel'
import { Input } from '@/components/inputs'
import { ScriptOptions } from 'models'

type Props = {
options: CodeOptions
onOptionsChange: (options: CodeOptions) => void
options: ScriptOptions
onOptionsChange: (options: ScriptOptions) => void
}

export const CodeSettings = ({ options, onOptionsChange }: Props) => {
export const ScriptSettings = ({ options, onOptionsChange }: Props) => {
const handleNameChange = (name: string) =>
onOptionsChange({ ...options, name })
const handleCodeChange = (content: string) =>
Expand Down
3 changes: 3 additions & 0 deletions apps/builder/src/features/blocks/logic/script/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { ScriptSettings } from './components/ScriptSettings'
export { ScriptNodeContent } from './components/ScriptNodeContent'
export { ScriptIcon } from './components/ScriptIcon'
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { getTestAsset } from '@/test/utils/playwright'

const typebotId = cuid()

test.describe('Code block', () => {
test('code should trigger', async ({ page }) => {
await importTypebotInDatabase(getTestAsset('typebots/logic/code.json'), {
test.describe('Script block', () => {
test('script should trigger', async ({ page }) => {
await importTypebotInDatabase(getTestAsset('typebots/logic/script.json'), {
id: typebotId,
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { ZapierLogo } from '@/features/blocks/integrations/zapier'
import { WebhookIcon } from '@/features/blocks/integrations/webhook'
import { GoogleSheetsLogo } from '@/features/blocks/integrations/googleSheets'
import { TypebotLinkIcon } from '@/features/blocks/logic/typebotLink'
import { CodeIcon } from '@/features/blocks/logic/code'
import { RedirectIcon } from '@/features/blocks/logic/redirect'
import { ConditionIcon } from '@/features/blocks/logic/condition'
import { SetVariableIcon } from '@/features/blocks/logic/setVariable'
Expand All @@ -37,6 +36,7 @@ import { EmbedBubbleIcon } from '@/features/blocks/bubbles/embed'
import { GoogleAnalyticsLogo } from '@/features/blocks/integrations/googleAnalytics'
import { AudioBubbleIcon } from '@/features/blocks/bubbles/audio'
import { WaitIcon } from '@/features/blocks/logic/wait/components/WaitIcon'
import { ScriptIcon } from '@/features/blocks/logic/script/components/ScriptIcon'

type BlockIconProps = { type: BlockType } & IconProps

Expand Down Expand Up @@ -81,8 +81,8 @@ export const BlockIcon = ({ type, ...props }: BlockIconProps) => {
return <ConditionIcon color={purple} {...props} />
case LogicBlockType.REDIRECT:
return <RedirectIcon color={purple} {...props} />
case LogicBlockType.CODE:
return <CodeIcon color={purple} {...props} />
case LogicBlockType.SCRIPT:
return <ScriptIcon {...props} />
case LogicBlockType.WAIT:
return <WaitIcon color={purple} {...props} />
case LogicBlockType.TYPEBOT_LINK:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ export const BlockTypeLabel = ({ type }: Props): JSX.Element => {
return <Text>Condition</Text>
case LogicBlockType.REDIRECT:
return <Text>Redirect</Text>
case LogicBlockType.CODE:
case LogicBlockType.SCRIPT:
return (
<Tooltip label="Run Javascript code">
<Text>Code</Text>
<Text>Script</Text>
</Tooltip>
)
case LogicBlockType.TYPEBOT_LINK:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { SetVariableContent } from '@/features/blocks/logic/setVariable'
import { WebhookContent } from '@/features/blocks/integrations/webhook'
import { ChatwootBlockNodeLabel } from '@/features/blocks/integrations/chatwoot'
import { RedirectNodeContent } from '@/features/blocks/logic/redirect'
import { CodeNodeContent } from '@/features/blocks/logic/code'
import { PabblyConnectContent } from '@/features/blocks/integrations/pabbly'
import { WithVariableContent } from './WithVariableContent'
import { PaymentInputContent } from '@/features/blocks/inputs/payment'
Expand All @@ -38,6 +37,7 @@ import { isInputBlock, isChoiceInput, blockHasItems } from 'utils'
import { MakeComContent } from '@/features/blocks/integrations/makeCom'
import { AudioBubbleNode } from '@/features/blocks/bubbles/audio'
import { WaitNodeContent } from '@/features/blocks/logic/wait/components/WaitNodeContent'
import { ScriptNodeContent } from '@/features/blocks/logic/script/components/ScriptNodeContent'

type Props = {
block: Block | StartBlock
Expand Down Expand Up @@ -113,9 +113,9 @@ export const BlockNodeContent = ({ block, indices }: Props): JSX.Element => {
case LogicBlockType.REDIRECT: {
return <RedirectNodeContent url={block.options.url} />
}
case LogicBlockType.CODE: {
case LogicBlockType.SCRIPT: {
return (
<CodeNodeContent
<ScriptNodeContent
name={block.options.name}
content={block.options.content}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ const getHelpDocUrl = (blockType: BlockWithOptions['type']): string | null => {
return 'https://docs.typebot.io/editor/blocks/logic/set-variable'
case LogicBlockType.REDIRECT:
return 'https://docs.typebot.io/editor/blocks/logic/redirect'
case LogicBlockType.CODE:
return 'https://docs.typebot.io/editor/blocks/logic/code'
case LogicBlockType.SCRIPT:
return 'https://docs.typebot.io/editor/blocks/logic/script'
case LogicBlockType.WAIT:
return 'https://docs.typebot.io/editor/blocks/logic/wait'
case InputBlockType.TEXT:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import { GoogleSheetsSettingsBody } from '@/features/blocks/integrations/googleS
import { SendEmailSettings } from '@/features/blocks/integrations/sendEmail'
import { WebhookSettings } from '@/features/blocks/integrations/webhook'
import { ZapierSettings } from '@/features/blocks/integrations/zapier'
import { CodeSettings } from '@/features/blocks/logic/code'
import { RedirectSettings } from '@/features/blocks/logic/redirect'
import { SetVariableSettings } from '@/features/blocks/logic/setVariable'
import { TypebotLinkForm } from '@/features/blocks/logic/typebotLink'
Expand All @@ -42,6 +41,7 @@ import { ChatwootSettingsForm } from '@/features/blocks/integrations/chatwoot'
import { MakeComSettings } from '@/features/blocks/integrations/makeCom'
import { HelpDocButton } from './HelpDocButton'
import { WaitSettings } from '@/features/blocks/logic/wait/components/WaitSettings'
import { ScriptSettings } from '@/features/blocks/logic/script/components/ScriptSettings'

type Props = {
block: BlockWithOptions
Expand Down Expand Up @@ -197,9 +197,9 @@ export const BlockSettings = ({
/>
)
}
case LogicBlockType.CODE: {
case LogicBlockType.SCRIPT: {
return (
<CodeSettings
<ScriptSettings
options={block.options}
onOptionsChange={handleOptionsChange}
/>
Expand Down
6 changes: 3 additions & 3 deletions apps/builder/src/features/graph/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
BubbleBlockType,
defaultChatwootOptions,
defaultChoiceInputOptions,
defaultCodeOptions,
defaultConditionContent,
defaultDateInputOptions,
defaultEmailInputOptions,
Expand Down Expand Up @@ -38,6 +37,7 @@ import {
ItemType,
LogicBlockType,
defaultWaitOptions,
defaultScriptOptions,
} from 'models'
import {
stubLength,
Expand Down Expand Up @@ -433,8 +433,8 @@ const parseDefaultBlockOptions = (type: BlockWithOptionsType): BlockOptions => {
return defaultSetVariablesOptions
case LogicBlockType.REDIRECT:
return defaultRedirectOptions
case LogicBlockType.CODE:
return defaultCodeOptions
case LogicBlockType.SCRIPT:
return defaultScriptOptions
case LogicBlockType.WAIT:
return defaultWaitOptions
case LogicBlockType.TYPEBOT_LINK:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Code
# Script

The "Code" block allows you to execute Javascript code. If you want to set a variable value with Javascript, use the [Set variable block](./set-variable) instead.
The "Script" block allows you to execute Javascript code. If you want to set a variable value with Javascript, use the [Set variable block](./set-variable) instead.

**It doesn't allow you to create a custom visual block**

Expand Down
12 changes: 8 additions & 4 deletions apps/docs/openapi/builder/_spec_.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
"PRO",
"LIFETIME",
"OFFERED",
"CUSTOM"
"CUSTOM",
"UNLIMITED"
]
}
},
Expand Down Expand Up @@ -145,7 +146,8 @@
"PRO",
"LIFETIME",
"OFFERED",
"CUSTOM"
"CUSTOM",
"UNLIMITED"
]
},
"stripeId": {
Expand Down Expand Up @@ -280,7 +282,8 @@
"PRO",
"LIFETIME",
"OFFERED",
"CUSTOM"
"CUSTOM",
"UNLIMITED"
]
},
"stripeId": {
Expand Down Expand Up @@ -432,7 +435,8 @@
"PRO",
"LIFETIME",
"OFFERED",
"CUSTOM"
"CUSTOM",
"UNLIMITED"
]
},
"stripeId": {
Expand Down
8 changes: 4 additions & 4 deletions apps/docs/openapi/chat/_spec_.json
Original file line number Diff line number Diff line change
Expand Up @@ -4498,7 +4498,7 @@
{
"type": "object",
"properties": {
"codeToExecute": {
"scriptToExecute": {
"type": "object",
"properties": {
"content": {
Expand Down Expand Up @@ -4553,7 +4553,7 @@
}
},
"required": [
"codeToExecute"
"scriptToExecute"
],
"additionalProperties": false
},
Expand Down Expand Up @@ -4589,7 +4589,7 @@
"chatwoot": {
"type": "object",
"properties": {
"codeToExecute": {
"scriptToExecute": {
"type": "object",
"properties": {
"content": {
Expand Down Expand Up @@ -4644,7 +4644,7 @@
}
},
"required": [
"codeToExecute"
"scriptToExecute"
],
"additionalProperties": false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const executeChatwootBlock = (
{
lastBubbleBlockId,
chatwoot: {
codeToExecute: {
scriptToExecute: {
content: parseVariables(variables, { fieldToParse: 'id' })(
chatwootCode
),
Expand Down
1 change: 0 additions & 1 deletion apps/viewer/src/features/blocks/logic/code/api/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import {
parseCorrectValueType,
extractVariablesFromText,
} from '@/features/variables'
import { CodeBlock, SessionState } from 'models'
import { ScriptBlock, SessionState } from 'models'

export const executeCode = (
export const executeScript = (
{ typebot: { variables } }: SessionState,
block: CodeBlock,
block: ScriptBlock,
lastBubbleBlockId?: string
): ExecuteLogicResponse => {
if (!block.options.content) return { outgoingEdgeId: block.outgoingEdgeId }
Expand All @@ -27,7 +27,7 @@ export const executeCode = (
outgoingEdgeId: block.outgoingEdgeId,
clientSideActions: [
{
codeToExecute: {
scriptToExecute: {
content,
args,
},
Expand Down
6 changes: 3 additions & 3 deletions apps/viewer/src/features/chat/api/utils/executeLogic.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { executeCode } from '@/features/blocks/logic/code/api'
import { executeCondition } from '@/features/blocks/logic/condition/api'
import { executeRedirect } from '@/features/blocks/logic/redirect/api'
import { executeSetVariable } from '@/features/blocks/logic/setVariable/api'
import { executeTypebotLink } from '@/features/blocks/logic/typebotLink/api'
import { executeWait } from '@/features/blocks/logic/wait/api/utils/executeWait'
import { LogicBlock, LogicBlockType, SessionState } from 'models'
import { ExecuteLogicResponse } from '../../types'
import { executeScript } from '@/features/blocks/logic/script/executeScript'

export const executeLogic =
(state: SessionState, lastBubbleBlockId?: string) =>
Expand All @@ -17,8 +17,8 @@ export const executeLogic =
return executeCondition(state, block)
case LogicBlockType.REDIRECT:
return executeRedirect(state, block, lastBubbleBlockId)
case LogicBlockType.CODE:
return executeCode(state, block, lastBubbleBlockId)
case LogicBlockType.SCRIPT:
return executeScript(state, block, lastBubbleBlockId)
case LogicBlockType.TYPEBOT_LINK:
return executeTypebotLink(state, block)
case LogicBlockType.WAIT:
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { parseVariables, parseCorrectValueType } from '@/features/variables'
import { LogicState } from '@/types'
import { sendEventToParent } from '@/utils/chat'
import { isEmbedded } from '@/utils/helpers'
import { CodeBlock } from 'models'
import { ScriptBlock } from 'models'

export const executeCode = async (
block: CodeBlock,
export const executeScript = async (
block: ScriptBlock,
{ typebot: { variables } }: LogicState
) => {
if (!block.options.content) return
Expand Down
6 changes: 3 additions & 3 deletions packages/bot-engine/src/utils/executeLogic.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { TypebotViewerProps } from '@/components/TypebotViewer'
import { executeCode } from '@/features/blocks/logic/code'
import { executeCondition } from '@/features/blocks/logic/condition'
import { executeRedirect } from '@/features/blocks/logic/redirect'
import { executeSetVariable } from '@/features/blocks/logic/setVariable'
Expand All @@ -8,6 +7,7 @@ import { executeWait } from '@/features/blocks/logic/wait'
import { LinkedTypebot } from '@/providers/TypebotProvider'
import { EdgeId, LogicState } from '@/types'
import { LogicBlock, LogicBlockType } from 'models'
import { executeScript } from '@/features/blocks/logic/script/executeScript'

export const executeLogic = async (
block: LogicBlock,
Expand All @@ -23,8 +23,8 @@ export const executeLogic = async (
return { nextEdgeId: executeCondition(block, context) }
case LogicBlockType.REDIRECT:
return { nextEdgeId: executeRedirect(block, context) }
case LogicBlockType.CODE:
return { nextEdgeId: await executeCode(block, context) }
case LogicBlockType.SCRIPT:
return { nextEdgeId: await executeScript(block, context) }
case LogicBlockType.TYPEBOT_LINK:
return executeTypebotLink(block, context)
case LogicBlockType.WAIT:
Expand Down
Loading

4 comments on commit a842f57

@vercel
Copy link

@vercel vercel bot commented on a842f57 Jan 27, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on a842f57 Jan 27, 2023

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
app.typebot.io
builder-v2-typebot-io.vercel.app

@vercel
Copy link

@vercel vercel bot commented on a842f57 Jan 27, 2023

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:

docs – ./apps/docs

docs.typebot.io
docs-git-main-typebot-io.vercel.app
docs-typebot-io.vercel.app

@vercel
Copy link

@vercel vercel bot commented on a842f57 Jan 27, 2023

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:

viewer-v2 – ./apps/viewer

an.nigerias.io
app.yvon.earth
ar.nigerias.io
bot.enreso.org
bot.rslabs.pro
bots.bridge.ai
chat.hayuri.id
chicken.cr8.ai
gollum.riku.ai
gsbulletin.com
panther.cr7.ai
panther.cr8.ai
penguin.cr8.ai
talk.gocare.io
ticketfute.com
unicorn.cr8.ai
apo.nigerias.io
link.venturasuceder.com
mainmenu.diddancing.com
manualhandlingcourse.ie
register.kandabrand.com
signup.hypemarketing.in
subfooter.wpwakanda.com
survey.hypemarketing.in
testbot.afterorigin.com
91181264.your-access.one
ai.chromebookstoreph.com
form.sergiolimajr.com.br
hunterbot.saleshunter.ai
invite.bridesquadapp.com
link.cascadigital.com.br
onboarding.growthside.io
reward.onlinebotdemo.xyz
type.opaulovieira.com.br
aibot.angrybranding.co.uk
bot.aidigitalmarketing.kr
bot.amicidisanfaustino.it
bot.arraesecenteno.com.br
bot.blackboxsports.com.br
bot.cabinrentalagency.com
bot.fusionstarreviews.com
boyfriend-breakup.riku.ai
brigadeirosemdrama.com.br
chat.ertcrebateportal.com
chat.thehomebuyersusa.com
chat.thisiscrushhouse.com
forms.hiabhaykulkarni.com
healthandsafetycourses.uk
sellmyharleylouisiana.com
testbot.sharemyreview.net
typebot-viewer.vercel.app
verfica.botmachine.com.br
bot.adventureconsulting.hu
casestudyemb.wpwakanda.com
chat.atlasoutfittersk9.com
configurator.bouclidom.com
help.atlasoutfittersk9.com
herbalife.barrettamario.it
homepageonly.wpwakanda.com
liveconvert.kandalearn.com
mainmenu1one.wpwakanda.com
tarian.theiofoundation.org
ted.meujalecobrasil.com.br
type.dericsoncalari.com.br
bot.pinpointinteractive.com
bot.polychromes-project.com
bot.seidinembroseanchetu.it
chatbot.berbelanjabiz.trade
designguide.techyscouts.com
liveconvert2.kandalearn.com
presente.empresarias.com.mx
sell.sellthemotorhome.co.uk
anamnese.odontopavani.com.br
austin.channelautomation.com
bot.marketingplusmindset.com
bot.seidibergamoseanchetu.it
desabafe.sergiolimajr.com.br
piazzatorre.barrettamario.it
type.cookieacademyonline.com
bot.brigadeirosemdrama.com.br
forms.escoladeautomacao.com.br
onboarding.libertydreamcare.ie
type.talitasouzamarques.com.br
agendamento.sergiolimajr.com.br
anamnese.clinicamegasjdr.com.br
bookings.littlepartymonkeys.com
bot.comercializadoraomicron.com
elevateyourmind.groovepages.com
viewer-v2-typebot-io.vercel.app
yourfeedback.comebackreward.com
gerador.verificadordehospedes.com
personal-trainer.barrettamario.it
preagendamento.sergiolimajr.com.br
studiotecnicoimmobiliaremerelli.it
download.thailandmicespecialist.com
register.thailandmicespecialist.com
bot.studiotecnicoimmobiliaremerelli.it
pesquisa.escolamodacomproposito.com.br
anamnese.clinicaramosodontologia.com.br
viewer-v2-git-main-typebot-io.vercel.app

Please sign in to comment.