Skip to content

Commit

Permalink
🚸 (results) Improve list variables display in results table
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Apr 1, 2023
1 parent b9ae314 commit 411cf31
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Stack, Text } from '@chakra-ui/react'
import { isDefined } from '@typebot.io/lib'
import { Answer } from '@typebot.io/prisma'
import {
ResultWithAnswers,
ResultHeaderCell,
VariableWithValue,
InputBlockType,
Answer,
} from '@typebot.io/schemas'
import { FileLinks } from '../components/FileLinks'
import { TableData } from '../types'
Expand All @@ -22,43 +23,62 @@ export const convertResultsToTableData = (
},
...[...result.answers, ...result.variables].reduce<{
[key: string]: { element?: JSX.Element; plainText: string }
}>((o, answerOrVariable) => {
}>((tableData, answerOrVariable) => {
if ('groupId' in answerOrVariable) {
const answer = answerOrVariable as Answer
const answer = answerOrVariable satisfies Answer
const header = answer.variableId
? headerCells.find((headerCell) =>
headerCell.variableIds?.includes(answer.variableId as string)
)
: headerCells.find((headerCell) =>
headerCell.blocks?.some((block) => block.id === answer.blockId)
)
if (!header || !header.blocks || !header.blockType) return o
if (!header || !header.blocks || !header.blockType) return tableData
const variableValue = result.variables.find(
(variable) => variable.id === answer.variableId
)?.value
const content = variableValue ?? answer.content
return {
...o,
[parseAccessor(header.label)]: {
element: parseContent(answer.content, header.blockType),
plainText: answer.content,
},
...tableData,
[parseAccessor(header.label)]: parseCellContent(
content,
header.blockType
),
}
}
const variable = answerOrVariable as VariableWithValue
if (variable.value === null) return o
const variable = answerOrVariable satisfies VariableWithValue
if (variable.value === null) return tableData
const key = headerCells.find((headerCell) =>
headerCell.variableIds?.includes(variable.id)
)?.label
if (!key) return o
if (isDefined(o[key])) return o
if (!key) return tableData
if (isDefined(tableData[key])) return tableData
return {
...o,
[parseAccessor(key)]: { plainText: variable.value?.toString() },
...tableData,
[parseAccessor(key)]: parseCellContent(variable.value),
}
}, {}),
}))

const parseContent = (
str: string,
blockType: InputBlockType
): JSX.Element | undefined =>
blockType === InputBlockType.FILE ? (
<FileLinks fileNamesStr={str} />
) : undefined
const parseCellContent = (
content: VariableWithValue['value'],
blockType?: InputBlockType
): { element?: JSX.Element; plainText: string } => {
if (!content) return { element: undefined, plainText: '' }
if (Array.isArray(content))
return {
element: (
<Stack spacing={2}>
{content.map((item, idx) => (
<Text key={idx}>
{idx + 1}. {item}
</Text>
))}
</Stack>
),
plainText: content.join(', '),
}
return blockType === InputBlockType.FILE
? { element: <FileLinks fileNamesStr={content} />, plainText: content }
: { plainText: content.toString() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import { SmtpCredentials } from '@typebot.io/schemas'

export const mockSmtpCredentials: SmtpCredentials['data'] = {
from: {
email: 'sunny.cremin66@ethereal.email',
name: 'Sunny Cremin',
email: 'pedro.morissette@ethereal.email',
name: 'Pedro Morissette',
},
host: 'smtp.ethereal.email',
port: 587,
username: 'sunny.cremin66@ethereal.email',
password: 'yJDHkf2bYbNydaRvTq',
username: 'pedro.morissette@ethereal.email',
password: 'ctDZ8SyeFyTT5MReJM',
}

test.beforeAll(async () => {
Expand Down

4 comments on commit 411cf31

@vercel
Copy link

@vercel vercel bot commented on 411cf31 Apr 1, 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 411cf31 Apr 1, 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 411cf31 Apr 1, 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

bium.gratirabbit.com
bot.ansuraniphone.my
bot.barrettamario.it
bot.cotemeuplano.com
bot.leadbooster.help
bot.mycompay.reviews
chat.hayurihijab.com
chatbee.agfunnel.com
click.sevenoways.com
connect.growthguy.in
forms.bonanza.design
hello.advergreen.com
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
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
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
signup.hypemarketing.in
subfooter.wpwakanda.com
survey.hypemarketing.in
testbot.afterorigin.com
typebot.influencer.love
www.chatgpt-biliran.com
91181264.your-access.one
abg-assistent.m-vogel.de
ai.chromebookstoreph.com
bot.pinpointinteractive.com
bot.polychromes-project.com
bot.seidinembroseanchetu.it
chat.semanalimpanome.com.br
designguide.techyscouts.com
liveconvert2.kandalearn.com
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
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 411cf31 Apr 1, 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-typebot-io.vercel.app
builder-v2-git-main-typebot-io.vercel.app
app.typebot.io

Please sign in to comment.