2
0

🐛 Fix sample result parsing on complex flows

Make sure to ignore already visited group ids
This commit is contained in:
Baptiste Arnaud
2024-05-30 10:19:19 +02:00
parent 3d09ad1818
commit 409c55308e

View File

@ -166,22 +166,25 @@ const walkEdgesAndExtract =
)({ )({
groupId: currentGroupId, groupId: currentGroupId,
}) })
const otherGroupIds = getGroupIds(typebot, direction)(currentGroupId) const otherGroupIds = getGroupIdsLinkedToGroup(
return [ typebot,
...blocksInGroup, direction
...otherGroupIds.flatMap((groupId) => )(currentGroupId)
return blocksInGroup.concat(
otherGroupIds.flatMap((groupId) =>
extractBlocksInGroup(type, typebot)({ groupId }) extractBlocksInGroup(type, typebot)({ groupId })
), )
] )
} }
const getGroupIds = const getGroupIdsLinkedToGroup =
( (
typebot: Pick<Typebot | PublicTypebot, 'groups' | 'variables' | 'edges'>, typebot: Pick<Typebot | PublicTypebot, 'groups' | 'variables' | 'edges'>,
direction: 'backward' | 'forward', direction: 'backward' | 'forward',
existingGroupIds?: string[] existingGroupIds: string[] = []
) => ) =>
(groupId: string): string[] => { (groupId: string): string[] => {
if (existingGroupIds.includes(groupId)) return existingGroupIds
const groups = typebot.edges.reduce<string[]>((groupIds, edge) => { const groups = typebot.edges.reduce<string[]>((groupIds, edge) => {
const fromGroupId = typebot.groups.find((g) => const fromGroupId = typebot.groups.find((g) =>
g.blocks.some( g.blocks.some(
@ -193,16 +196,21 @@ const getGroupIds =
return (!existingGroupIds || return (!existingGroupIds ||
!existingGroupIds?.includes(edge.to.groupId)) && !existingGroupIds?.includes(edge.to.groupId)) &&
fromGroupId === groupId fromGroupId === groupId
? [...groupIds, edge.to.groupId] ? groupIds.concat(edge.to.groupId)
: groupIds : groupIds
return (!existingGroupIds || !existingGroupIds.includes(fromGroupId)) && return (!existingGroupIds || !existingGroupIds.includes(fromGroupId)) &&
edge.to.groupId === groupId edge.to.groupId === groupId
? [...groupIds, fromGroupId] ? groupIds.concat(fromGroupId)
: groupIds : groupIds
}, []) }, [])
const newGroups = [...(existingGroupIds ?? []), ...groups]
return groups.concat( return groups.concat(
groups.flatMap(getGroupIds(typebot, direction, newGroups)) groups.flatMap(
getGroupIdsLinkedToGroup(
typebot,
direction,
existingGroupIds.concat(groups)
)
)
) )
} }