🐛 (results) Fix bug preventing user from seeing linked typebots results

This commit is contained in:
Baptiste Arnaud
2022-11-06 09:57:08 +01:00
parent 63845effaf
commit 6dd7bd9562
18 changed files with 234 additions and 151 deletions

View File

@@ -203,16 +203,7 @@ const getBodyContent =
return body === '{{state}}'
? JSON.stringify(
resultValues
? parseAnswers({
groups: [
...typebot.groups,
...linkedTypebots.flatMap((t) => t.groups),
],
variables: [
...typebot.variables,
...linkedTypebots.flatMap((t) => t.variables),
],
})(resultValues)
? parseAnswers(typebot, linkedTypebots)(resultValues)
: await parseSampleResult(typebot, linkedTypebots)(groupId)
)
: body

View File

@@ -180,13 +180,7 @@ const getEmailBody = async ({
})) as unknown as PublicTypebot
if (!typebot) return
const linkedTypebots = await getLinkedTypebots(typebot)
const answers = parseAnswers({
groups: [...typebot.groups, ...linkedTypebots.flatMap((t) => t.groups)],
variables: [
...typebot.variables,
...linkedTypebots.flatMap((t) => t.variables),
],
})(resultValues)
const answers = parseAnswers(typebot, linkedTypebots)(resultValues)
return {
html: render(
<DefaultBotNotificationEmail

View File

@@ -26,8 +26,8 @@ test('can list typebots', async ({ request }) => {
const response = await request.get(`/api/typebots`, {
headers: { Authorization: `Bearer ${apiToken}` },
})
const { typebots } = await response.json()
expect(typebots).toHaveLength(1)
const { typebots } = (await response.json()) as { typebots: unknown[] }
expect(typebots.length).toBeGreaterThanOrEqual(1)
expect(typebots[0]).toMatchObject({
id: typebotId,
publishedTypebotId: null,

View File

@@ -18,13 +18,7 @@ export const parseSampleResult =
async (
currentGroupId: string
): Promise<Record<string, string | boolean | undefined>> => {
const header = parseResultHeader({
groups: [...typebot.groups, ...linkedTypebots.flatMap((t) => t.groups)],
variables: [
...typebot.variables,
...linkedTypebots.flatMap((t) => t.variables),
],
})
const header = parseResultHeader(typebot, linkedTypebots)
const linkedInputBlocks = await extractLinkedInputBlocks(
typebot,
linkedTypebots
@@ -33,7 +27,7 @@ export const parseSampleResult =
return {
message: 'This is a sample result, it has been generated ⬇️',
'Submitted at': new Date().toISOString(),
...parseGroupsResultSample(linkedInputBlocks, header),
...parseResultSample(linkedInputBlocks, header),
}
}
@@ -81,24 +75,26 @@ const extractLinkedInputBlocks =
).concat(linkedBotInputs.flatMap((l) => l))
}
const parseGroupsResultSample = (
const parseResultSample = (
inputBlocks: InputBlock[],
header: ResultHeaderCell[]
headerCells: ResultHeaderCell[]
) =>
header.reduce<Record<string, string | boolean | undefined>>(
(blocks, cell) => {
const inputBlock = inputBlocks.find((block) => block.id === cell.blockId)
headerCells.reduce<Record<string, string | boolean | undefined>>(
(resultSample, cell) => {
const inputBlock = inputBlocks.find((inputBlock) =>
cell.blocks?.some((block) => block.id === inputBlock.id)
)
if (isNotDefined(inputBlock)) {
if (cell.variableId)
if (cell.variableIds)
return {
...blocks,
...resultSample,
[cell.label]: 'content',
}
return blocks
return resultSample
}
const value = getSampleValue(inputBlock)
return {
...blocks,
...resultSample,
[cell.label]: value,
}
},