Skip to content

Commit

Permalink
🐛 (results) Fix results still appearing when deleted
Browse files Browse the repository at this point in the history
Closes #316
  • Loading branch information
baptisteArno committed Feb 13, 2023
1 parent 0dba994 commit 3728bca
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 36 deletions.
4 changes: 2 additions & 2 deletions apps/builder/src/features/results/ResultsProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ export const ResultsProvider = ({
const resultHeader = useMemo(
() =>
publishedTypebot
? parseResultHeader(publishedTypebot, linkedTypebots, flatResults)
? parseResultHeader(publishedTypebot, linkedTypebots)
: [],
[flatResults, linkedTypebots, publishedTypebot]
[linkedTypebots, publishedTypebot]
)

const tableData = useMemo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const getResultsProcedure = authenticatedProcedure
where: {
typebotId: typebot.id,
hasStarted: true,
isArchived: false,
},
orderBy: {
createdAt: 'desc',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,20 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
prisma.result.count({
where: {
typebotId: typebot.id,
isArchived: false,
},
}),
prisma.result.count({
where: {
typebotId: typebot.id,
isArchived: false,
hasStarted: true,
},
}),
prisma.result.count({
where: {
typebotId: typebot.id,
isArchived: false,
isCompleted: true,
},
}),
Expand Down
4 changes: 2 additions & 2 deletions packages/db/mysql/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ model Result {
answers Answer[]
logs Log[]
@@index([typebotId, hasStarted, createdAt(sort: Desc)])
@@index([typebotId, isCompleted])
@@index([typebotId, isArchived, hasStarted, createdAt(sort: Desc)])
@@index([typebotId, isArchived, isCompleted])
}

model Log {
Expand Down
34 changes: 2 additions & 32 deletions packages/utils/results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@ import {
VariableWithValue,
Typebot,
ResultWithAnswersInput,
ResultWithAnswers,
InputBlockType,
} from 'models'
import { isInputBlock, isDefined, byId, isNotEmpty } from './utils'
import { isInputBlock, isDefined, byId } from './utils'

export const parseResultHeader = (
typebot: Pick<Typebot, 'groups' | 'variables'>,
linkedTypebots: Pick<Typebot, 'groups' | 'variables'>[] | undefined,
results: ResultWithAnswers[] = []
linkedTypebots: Pick<Typebot, 'groups' | 'variables'>[] | undefined
): ResultHeaderCell[] => {
const parsedGroups = [
...typebot.groups,
Expand All @@ -35,7 +32,6 @@ export const parseResultHeader = (
{ label: 'Submitted at', id: 'date' },
...inputsResultHeader,
...parseVariablesHeaders(parsedVariables, inputsResultHeader),
...parseResultsFromPreviousBotVersions(results, inputsResultHeader),
]
}

Expand Down Expand Up @@ -172,32 +168,6 @@ const parseVariablesHeaders = (
return [...existingHeaders, newHeaderCell]
}, [])

const parseResultsFromPreviousBotVersions = (
results: ResultWithAnswers[],
existingInputResultHeaders: ResultHeaderCell[]
): ResultHeaderCell[] =>
results
.flatMap((result) => result.answers)
.filter(
(answer) =>
!answer.variableId &&
existingInputResultHeaders.every(
(header) => header.id !== answer.blockId
) &&
isNotEmpty(answer.content)
)
.map((answer) => ({
id: answer.blockId,
label: `Deleted block`,
blocks: [
{
id: answer.blockId,
groupId: answer.groupId,
},
],
blockType: InputBlockType.TEXT,
}))

export const parseAnswers =
(
typebot: Pick<Typebot, 'groups' | 'variables'>,
Expand Down

4 comments on commit 3728bca

@vercel
Copy link

@vercel vercel bot commented on 3728bca Feb 13, 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

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
test.bot.gives
stan.vselise.com
start.taxtree.io
typebot.aloe.bot
voicehelp.cr8.ai
zap.fundviser.in
app.chatforms.net
bot.hostnation.de
bot.maitempah.com
bot.phuonghub.com
bot.reviewzer.com
bot.rihabilita.it
cares.urlabout.me
chat.gaswadern.de
fmm.wpwakanda.com
gentleman-shop.fr
k1.kandabrand.com
lb.ticketfute.com
ov1.wpwakanda.com
ov2.wpwakanda.com
ov3.wpwakanda.com
support.triplo.ai
viewer.typebot.io
1988.bouclidom.com
andreimayer.com.br
bot.danyservice.it
bot.iconicbrows.it
bot.megafox.com.br
bot.neferlopez.com
bots.robomotion.io
cadu.uninta.edu.br
dicanatural.online
digitalhelp.com.au
goalsettingbot.com
pant.maxbot.com.br
positivobra.com.br
survey.digienge.io
this-is-a-test.com
zap.techadviser.in
bot.boston-voip.com
bot.cabinpromos.com
bot.digitalbled.com
bot.dsignagency.com
bot.eventhub.com.au
bot.jepierre.com.br
bot.ltmidias.com.br
bot.viralsangat.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
download.venturemarketing.in
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

@vercel
Copy link

@vercel vercel bot commented on 3728bca Feb 13, 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 3728bca Feb 13, 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

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

@vercel
Copy link

@vercel vercel bot commented on 3728bca Feb 13, 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

Please sign in to comment.