2
0

🐛 (results) Fix results still appearing when deleted

Closes #316
This commit is contained in:
Baptiste Arnaud
2023-02-13 14:28:44 +01:00
parent 0dba994210
commit 3728bca173
5 changed files with 10 additions and 36 deletions

View File

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