2
0

🚸 (results) Show deleted block answers if any

Also remove useEffects in ResultsTable.
This commit is contained in:
Baptiste Arnaud
2023-02-10 15:50:25 +01:00
parent 51f76700b2
commit 3ab67902c0
5 changed files with 104 additions and 44 deletions

View File

@ -7,12 +7,15 @@ import {
VariableWithValue,
Typebot,
ResultWithAnswersInput,
ResultWithAnswers,
InputBlockType,
} from 'models'
import { isInputBlock, isDefined, byId } from './utils'
import { isInputBlock, isDefined, byId, isNotEmpty } from './utils'
export const parseResultHeader = (
typebot: Pick<Typebot, 'groups' | 'variables'>,
linkedTypebots: Pick<Typebot, 'groups' | 'variables'>[] | undefined
linkedTypebots: Pick<Typebot, 'groups' | 'variables'>[] | undefined,
results: ResultWithAnswers[] = []
): ResultHeaderCell[] => {
const parsedGroups = [
...typebot.groups,
@ -32,6 +35,7 @@ export const parseResultHeader = (
{ label: 'Submitted at', id: 'date' },
...inputsResultHeader,
...parseVariablesHeaders(parsedVariables, inputsResultHeader),
...parseResultsFromPreviousBotVersions(results, inputsResultHeader),
]
}
@ -168,6 +172,32 @@ 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'>,