Skip to content

Commit

Permalink
🐛 (results) Fix results display when variable has undefined value
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Nov 23, 2022
1 parent ec0e4be commit d80cc1b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { canReadTypebot } from '@/utils/api/dbRules'
import { authenticatedProcedure } from '@/utils/server/trpc'
import { TRPCError } from '@trpc/server'
import { ResultWithAnswers, resultWithAnswersSchema } from 'models'
import { isDefined } from 'utils'
import { z } from 'zod'

const maxLimit = 200
Expand Down Expand Up @@ -57,5 +58,12 @@ export const getResultsProcedure = authenticatedProcedure
nextCursor = nextResult?.id
}

return { results, nextCursor }
return { results: parseResults(results), nextCursor }
})

// TODO: remove once DB entries are fixed
const parseResults = (results: ResultWithAnswers[]): ResultWithAnswers[] =>
results.map((result) => ({
...result,
variables: result.variables.filter((variable) => isDefined(variable.value)),
}))
3 changes: 1 addition & 2 deletions apps/docs/openapi/builder.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@
"type": "string"
},
"value": {
"type": "string",
"nullable": true
"type": "string"
}
},
"required": [
Expand Down
6 changes: 3 additions & 3 deletions packages/bot-engine/src/providers/AnswersProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { safeStringify } from '@/features/variables'
import {
Answer,
AnswerInput,
ResultValues,
VariableWithUnknowValue,
VariableWithValue,
} from 'models'
import { createContext, ReactNode, useContext, useState } from 'react'
import { isDefined } from 'utils'

const answersContext = createContext<{
resultId?: string
Expand Down Expand Up @@ -49,15 +49,15 @@ export const AnswersProvider = ({
const serializedNewVariables = newVariables.map((variable) => ({
...variable,
value: safeStringify(variable.value),
})) as VariableWithValue[]
}))

setResultValues((resultValues) => {
const updatedVariables = [
...resultValues.variables.filter((v) =>
serializedNewVariables.every((variable) => variable.id !== v.id)
),
...serializedNewVariables,
]
].filter((variable) => isDefined(variable.value)) as VariableWithValue[]
if (onVariablesUpdated) onVariablesUpdated(updatedVariables)
return {
...resultValues,
Expand Down
2 changes: 1 addition & 1 deletion packages/models/src/features/typebot/variable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const variableSchema = z.object({
export const variableWithValueSchema = z.object({
id: z.string(),
name: z.string(),
value: z.string().nullable(),
value: z.string(),
})

/**
Expand Down

5 comments on commit d80cc1b

@vercel
Copy link

@vercel vercel bot commented on d80cc1b Nov 23, 2022

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 d80cc1b Nov 23, 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-typebot-io.vercel.app
builder-v2-git-main-typebot-io.vercel.app
app.typebot.io

@vercel
Copy link

@vercel vercel bot commented on d80cc1b Nov 23, 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:

viewer-v2-alpha – ./apps/viewer

ns8.vn
yobot.me
247987.com
8jours.top
bot.aws.bj
bot.bbc.bj
finplex.be
sat.cr8.ai
bot.aipr.kr
minipost.uk
bt.id8rs.com
bot.krdfy.com
goldorayo.com
vhpage.cr8.ai
am.nigerias.io
an.nigerias.io
ar.nigerias.io
bot.enreso.org
bot.lalmon.com
ticketfute.com
apo.nigerias.io
apr.nigerias.io
aso.nigerias.io
bot.ageenda.com
bot.artiweb.app
bot.devitus.com
bot.tc-mail.com
chat.sureb4.com
eventhub.com.au
games.klujo.com
sakuranembro.it
typebot.aloe.do
bot.piccinato.co
botc.ceox.com.br
clo.closeer.work
faqs.nigerias.io
feedback.ofx.one
form.syncwin.com
kw.wpwakanda.com
myrentalhost.com
stan.vselise.com
start.taxtree.io
typebot.aloe.bot
voicehelp.cr8.ai
app.chatforms.net
bot.agfunnel.tech
bot.hostnation.de
offer.botscientis.us
sellmycarglasgow.com
talkbot.agfunnel.com
tenorioadvogados.com
uppity.wpwakanda.com
abutton.wpwakanda.com
aidigitalmarketing.kr
bbutton.wpwakanda.com
onboarding.growthside.io
reward.onlinebotdemo.xyz
type.opaulovieira.com.br
aibot.angrybranding.co.uk
bot.aidigitalmarketing.kr
bot.arraesecenteno.com.br
bot.blackboxsports.com.br
bot.cabinrentalagency.com
boyfriend-breakup.riku.ai
brigadeirosemdrama.com.br
chat.ertcrebateportal.com
chat.thisiscrushhouse.com
sellmyharleylouisiana.com
verfica.botmachine.com.br
configurator.bouclidom.com
help.atlasoutfittersk9.com
ted.meujalecobrasil.com.br
type.dericsoncalari.com.br
chatbot.berbelanjabiz.trade
designguide.techyscouts.com
presente.empresarias.com.mx
sell.sellthemotorhome.co.uk
anamnese.odontopavani.com.br
austin.channelautomation.com
bot.marketingplusmindset.com
piazzatorre.barrettamario.it
requests.swamprecordsgnv.com
type.cookieacademyonline.com
bot.brigadeirosemdrama.com.br
onboarding.libertydreamcare.ie
type.talitasouzamarques.com.br
agendamento.sergiolimajr.com.br
anamnese.clinicamegasjdr.com.br
bookings.littlepartymonkeys.com
bot.comercializadoraomicron.com
yourfeedback.comebackreward.com
personal-trainer.barrettamario.it
preagendamento.sergiolimajr.com.br
studiotecnicoimmobiliaremerelli.it
download.thailandmicespecialist.com
register.thailandmicespecialist.com
viewer-v2-alpha-typebot-io.vercel.app
pesquisa.escolamodacomproposito.com.br
anamnese.clinicaramosodontologia.com.br
viewer-v2-alpha-git-main-typebot-io.vercel.app

@vercel
Copy link

@vercel vercel bot commented on d80cc1b Nov 23, 2022

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 d80cc1b Nov 23, 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:

docs – ./apps/docs

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

Please sign in to comment.