🚸 (results) Improve list variables display in results table
This commit is contained in:
@@ -1,10 +1,11 @@
|
|||||||
|
import { Stack, Text } from '@chakra-ui/react'
|
||||||
import { isDefined } from '@typebot.io/lib'
|
import { isDefined } from '@typebot.io/lib'
|
||||||
import { Answer } from '@typebot.io/prisma'
|
|
||||||
import {
|
import {
|
||||||
ResultWithAnswers,
|
ResultWithAnswers,
|
||||||
ResultHeaderCell,
|
ResultHeaderCell,
|
||||||
VariableWithValue,
|
VariableWithValue,
|
||||||
InputBlockType,
|
InputBlockType,
|
||||||
|
Answer,
|
||||||
} from '@typebot.io/schemas'
|
} from '@typebot.io/schemas'
|
||||||
import { FileLinks } from '../components/FileLinks'
|
import { FileLinks } from '../components/FileLinks'
|
||||||
import { TableData } from '../types'
|
import { TableData } from '../types'
|
||||||
@@ -22,9 +23,9 @@ export const convertResultsToTableData = (
|
|||||||
},
|
},
|
||||||
...[...result.answers, ...result.variables].reduce<{
|
...[...result.answers, ...result.variables].reduce<{
|
||||||
[key: string]: { element?: JSX.Element; plainText: string }
|
[key: string]: { element?: JSX.Element; plainText: string }
|
||||||
}>((o, answerOrVariable) => {
|
}>((tableData, answerOrVariable) => {
|
||||||
if ('groupId' in answerOrVariable) {
|
if ('groupId' in answerOrVariable) {
|
||||||
const answer = answerOrVariable as Answer
|
const answer = answerOrVariable satisfies Answer
|
||||||
const header = answer.variableId
|
const header = answer.variableId
|
||||||
? headerCells.find((headerCell) =>
|
? headerCells.find((headerCell) =>
|
||||||
headerCell.variableIds?.includes(answer.variableId as string)
|
headerCell.variableIds?.includes(answer.variableId as string)
|
||||||
@@ -32,33 +33,52 @@ export const convertResultsToTableData = (
|
|||||||
: headerCells.find((headerCell) =>
|
: headerCells.find((headerCell) =>
|
||||||
headerCell.blocks?.some((block) => block.id === answer.blockId)
|
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 {
|
return {
|
||||||
...o,
|
...tableData,
|
||||||
[parseAccessor(header.label)]: {
|
[parseAccessor(header.label)]: parseCellContent(
|
||||||
element: parseContent(answer.content, header.blockType),
|
content,
|
||||||
plainText: answer.content,
|
header.blockType
|
||||||
},
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const variable = answerOrVariable as VariableWithValue
|
const variable = answerOrVariable satisfies VariableWithValue
|
||||||
if (variable.value === null) return o
|
if (variable.value === null) return tableData
|
||||||
const key = headerCells.find((headerCell) =>
|
const key = headerCells.find((headerCell) =>
|
||||||
headerCell.variableIds?.includes(variable.id)
|
headerCell.variableIds?.includes(variable.id)
|
||||||
)?.label
|
)?.label
|
||||||
if (!key) return o
|
if (!key) return tableData
|
||||||
if (isDefined(o[key])) return o
|
if (isDefined(tableData[key])) return tableData
|
||||||
return {
|
return {
|
||||||
...o,
|
...tableData,
|
||||||
[parseAccessor(key)]: { plainText: variable.value?.toString() },
|
[parseAccessor(key)]: parseCellContent(variable.value),
|
||||||
}
|
}
|
||||||
}, {}),
|
}, {}),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const parseContent = (
|
const parseCellContent = (
|
||||||
str: string,
|
content: VariableWithValue['value'],
|
||||||
blockType: InputBlockType
|
blockType?: InputBlockType
|
||||||
): JSX.Element | undefined =>
|
): { element?: JSX.Element; plainText: string } => {
|
||||||
blockType === InputBlockType.FILE ? (
|
if (!content) return { element: undefined, plainText: '' }
|
||||||
<FileLinks fileNamesStr={str} />
|
if (Array.isArray(content))
|
||||||
) : undefined
|
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() }
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,13 +7,13 @@ import { SmtpCredentials } from '@typebot.io/schemas'
|
|||||||
|
|
||||||
export const mockSmtpCredentials: SmtpCredentials['data'] = {
|
export const mockSmtpCredentials: SmtpCredentials['data'] = {
|
||||||
from: {
|
from: {
|
||||||
email: 'sunny.cremin66@ethereal.email',
|
email: 'pedro.morissette@ethereal.email',
|
||||||
name: 'Sunny Cremin',
|
name: 'Pedro Morissette',
|
||||||
},
|
},
|
||||||
host: 'smtp.ethereal.email',
|
host: 'smtp.ethereal.email',
|
||||||
port: 587,
|
port: 587,
|
||||||
username: 'sunny.cremin66@ethereal.email',
|
username: 'pedro.morissette@ethereal.email',
|
||||||
password: 'yJDHkf2bYbNydaRvTq',
|
password: 'ctDZ8SyeFyTT5MReJM',
|
||||||
}
|
}
|
||||||
|
|
||||||
test.beforeAll(async () => {
|
test.beforeAll(async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user