Skip to content

Commit

Permalink
🐛 (googleAnalytics) Fix output validation when using variable as even…
Browse files Browse the repository at this point in the history
…t value
  • Loading branch information
baptisteArno committed May 3, 2023
1 parent f2d3174 commit 65c6f66
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 24 deletions.
24 changes: 13 additions & 11 deletions apps/builder/src/components/inputs/NumberInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,24 @@ export const NumberInput = <HasVariable extends boolean>({
[onValueChangeDebounced]
)

const handleValueChange = (value: string) => {
setValue(value)
if (value.endsWith('.') || value.endsWith(',')) return
if (value === '') return onValueChangeDebounced(undefined)
const handleValueChange = (newValue: string) => {
if (value.startsWith('{{') && value.endsWith('}}') && newValue !== '')
return
setValue(newValue)
if (newValue.endsWith('.') || newValue.endsWith(',')) return
if (newValue === '') return onValueChangeDebounced(undefined)
if (
value.startsWith('{{') &&
value.endsWith('}}') &&
value.length > 4 &&
newValue.startsWith('{{') &&
newValue.endsWith('}}') &&
newValue.length > 4 &&
(withVariableButton ?? true)
) {
onValueChangeDebounced(value as Value<HasVariable>)
onValueChangeDebounced(newValue as Value<HasVariable>)
return
}
const newValue = parseFloat(value)
if (isNaN(newValue)) return
onValueChangeDebounced(newValue)
const numberedValue = parseFloat(newValue)
if (isNaN(numberedValue)) return
onValueChangeDebounced(numberedValue)
}

const handleVariableSelected = (variable?: Variable) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,7 @@ export const BlockNodeContent = ({ block, indices }: Props): JSX.Element => {
)
}
case IntegrationBlockType.GOOGLE_ANALYTICS: {
return (
<GoogleAnalyticsNodeBody
action={
block.options?.action
? `Track "${block.options?.action}" `
: undefined
}
/>
)
return <GoogleAnalyticsNodeBody action={block.options?.action} />
}
case IntegrationBlockType.WEBHOOK: {
return <WebhookContent block={block} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ export const executeGoogleAnalyticsBlock = (
outgoingEdgeId: block.outgoingEdgeId,
clientSideActions: [
{
googleAnalytics: deepParseVariables(variables)(block.options),
googleAnalytics: deepParseVariables(variables, {
guessCorrectType: true,
})(block.options),
lastBubbleBlockId,
},
],
Expand Down
13 changes: 10 additions & 3 deletions apps/viewer/src/features/variables/deepParseVariable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,28 @@ import {
parseVariables,
ParseVariablesOptions,
} from './parseVariables'
import { parseGuessedValueType } from './parseGuessedValueType'

export const deepParseVariables =
(
variables: Variable[],
options: ParseVariablesOptions = defaultParseVariablesOptions
options: ParseVariablesOptions & {
guessCorrectType?: boolean
} = defaultParseVariablesOptions
) =>
<T extends Record<string, unknown>>(object: T): T =>
Object.keys(object).reduce<T>((newObj, key) => {
const currentValue = object[key]

if (typeof currentValue === 'string')
if (typeof currentValue === 'string') {
const parsedVariable = parseVariables(variables, options)(currentValue)
return {
...newObj,
[key]: parseVariables(variables, options)(currentValue),
[key]: options.guessCorrectType
? parseGuessedValueType(parsedVariable)
: parsedVariable,
}
}

if (currentValue instanceof Object && currentValue.constructor === Object)
return {
Expand Down

4 comments on commit 65c6f66

@vercel
Copy link

@vercel vercel bot commented on 65c6f66 May 3, 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-git-main-typebot-io.vercel.app
docs-typebot-io.vercel.app
docs.typebot.io

@vercel
Copy link

@vercel vercel bot commented on 65c6f66 May 3, 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

bii.bj
yobot.me
sbutton.wpwakanda.com
test.leadbooster.help
zillabot.saaszilla.co
815639944.21000000.one
83720273.bouclidom.com
aplicacao.bmind.com.br
apply.ansuraniphone.my
bbutton.wpwwakanda.com
bolsamaisbrasil.app.br
bot.ilmuseoaiborghi.it
bot.louismarcondes.com
bot.pratikmandalia.com
bot.t20worldcup.com.au
bot2.mycompany.reviews
bot3.mycompany.reviews
bot4.mycompany.reviews
c23111azqw.nigerias.io
chat.footballmeetup.ie
dieta.barrettamario.it
felipewelington.com.br
form.bridesquadapp.com
form.searchcube.com.sg
gcase.barrettamario.it
help.giversforgood.com
info.clickasuransi.com
kodawariab736.skeep.it
michaeljackson.riku.ai
premium.kandabrand.com
report.gratirabbit.com
resume.gratirabbit.com
83242573.actualizar.xyz
87656003.actualizar.xyz
88152257.actualizar.xyz
91375310.actualizar.xyz
app.youvisitedthis.site
arrivalx2.wpwakanda.com
bot.blackboxtips.com.br
bot.hotelplayarimini.it
bot.upgradesolutions.eu
bots.baptiste-arnaud.fr
help.comebackreward.com
link.venturasuceder.com
mainmenu.diddancing.com
manualhandlingcourse.ie
primitive-shapes.cr8.ai
register.kandabrand.com
sell.sellitwithgary.com
signup.hypemarketing.in
subfooter.wpwakanda.com
newsletter.itshcormeos.com
rsvp.virtuesocialmedia.com
tarian.theiofoundation.org
ted.meujalecobrasil.com.br
type.dericsoncalari.com.br
bot.pinpointinteractive.com
bot.polychromes-project.com
bot.seidinembroseanchetu.it
chat.semanalimpanome.com.br
designguide.techyscouts.com
liveconvert2.kandalearn.com
poll.mosaicohairboutique.it
presente.empresarias.com.mx
register.algorithmpress.com
sell.sellthemotorhome.co.uk
anamnese.odontopavani.com.br
austin.channelautomation.com
bot.marketingplusmindset.com
bot.seidibergamoseanchetu.it
desabafe.sergiolimajr.com.br
download.venturemarketing.in
piazzatorre.barrettamario.it
type.cookieacademyonline.com
upload.atlasoutfittersk9.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
bot.cabin-rentals-of-georgia.net
open.campus.bot.aalen.university
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
chrome-os-inquiry-system.itschromeos.com
viewer-v2-git-main-typebot-io.vercel.app
main-menu-for-itschromeos.itschromeos.com

@vercel
Copy link

@vercel vercel bot commented on 65c6f66 May 3, 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
builder-v2-typebot-io.vercel.app
app.typebot.io

@vercel
Copy link

@vercel vercel bot commented on 65c6f66 May 3, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.