2
0

chore(editor): ♻️ Revert tables to arrays

Yet another refacto. I improved many many mechanisms on this one including dnd. It is now end 2 end tested 🎉
This commit is contained in:
Baptiste Arnaud
2022-02-04 19:00:08 +01:00
parent 8a350eee6c
commit 524ef0812c
123 changed files with 2998 additions and 3112 deletions

View File

@ -3,7 +3,7 @@ import { useTypebot } from 'contexts/TypebotContext'
import React, { useMemo } from 'react'
import { AnswersCount } from 'services/analytics'
import { computeSourceCoordinates } from 'services/graph'
import { isDefined } from 'utils'
import { byId, isDefined } from 'utils'
type Props = {
answersCounts: AnswersCount[]
@ -21,11 +21,10 @@ export const DropOffNode = ({ answersCounts, blockId }: Props) => {
const { totalDroppedUser, dropOffRate } = useMemo(() => {
if (!typebot || totalAnswers === undefined)
return { previousTotal: undefined, dropOffRate: undefined }
const previousBlockIds = typebot.edges.allIds
.map((edgeId) => {
const edge = typebot.edges.byId[edgeId]
return edge.to.blockId === blockId ? edge.from.blockId : undefined
})
const previousBlockIds = typebot.edges
.map((edge) =>
edge.to.blockId === blockId ? edge.from.blockId : undefined
)
.filter((blockId) => isDefined(blockId))
const previousTotal = answersCounts
.filter((a) => previousBlockIds.includes(a.blockId))
@ -41,12 +40,11 @@ export const DropOffNode = ({ answersCounts, blockId }: Props) => {
}, [answersCounts, blockId, totalAnswers, typebot])
const labelCoordinates = useMemo(() => {
if (!typebot) return { x: 0, y: 0 }
const sourceBlock = typebot?.blocks.byId[blockId]
const sourceBlock = typebot?.blocks.find(byId(blockId))
if (!sourceBlock) return
return computeSourceCoordinates(
sourceBlock?.graphCoordinates,
sourceBlock?.stepIds.length - 1
sourceBlock?.steps.length - 1
)
}, [blockId, typebot])