@ -49,9 +49,9 @@ export const ResultsProvider = ({
|
|||||||
const resultHeader = useMemo(
|
const resultHeader = useMemo(
|
||||||
() =>
|
() =>
|
||||||
publishedTypebot
|
publishedTypebot
|
||||||
? parseResultHeader(publishedTypebot, linkedTypebots, flatResults)
|
? parseResultHeader(publishedTypebot, linkedTypebots)
|
||||||
: [],
|
: [],
|
||||||
[flatResults, linkedTypebots, publishedTypebot]
|
[linkedTypebots, publishedTypebot]
|
||||||
)
|
)
|
||||||
|
|
||||||
const tableData = useMemo(
|
const tableData = useMemo(
|
||||||
|
@ -50,6 +50,7 @@ export const getResultsProcedure = authenticatedProcedure
|
|||||||
where: {
|
where: {
|
||||||
typebotId: typebot.id,
|
typebotId: typebot.id,
|
||||||
hasStarted: true,
|
hasStarted: true,
|
||||||
|
isArchived: false,
|
||||||
},
|
},
|
||||||
orderBy: {
|
orderBy: {
|
||||||
createdAt: 'desc',
|
createdAt: 'desc',
|
||||||
|
@ -23,17 +23,20 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
|||||||
prisma.result.count({
|
prisma.result.count({
|
||||||
where: {
|
where: {
|
||||||
typebotId: typebot.id,
|
typebotId: typebot.id,
|
||||||
|
isArchived: false,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
prisma.result.count({
|
prisma.result.count({
|
||||||
where: {
|
where: {
|
||||||
typebotId: typebot.id,
|
typebotId: typebot.id,
|
||||||
|
isArchived: false,
|
||||||
hasStarted: true,
|
hasStarted: true,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
prisma.result.count({
|
prisma.result.count({
|
||||||
where: {
|
where: {
|
||||||
typebotId: typebot.id,
|
typebotId: typebot.id,
|
||||||
|
isArchived: false,
|
||||||
isCompleted: true,
|
isCompleted: true,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
@ -250,8 +250,8 @@ model Result {
|
|||||||
answers Answer[]
|
answers Answer[]
|
||||||
logs Log[]
|
logs Log[]
|
||||||
|
|
||||||
@@index([typebotId, hasStarted, createdAt(sort: Desc)])
|
@@index([typebotId, isArchived, hasStarted, createdAt(sort: Desc)])
|
||||||
@@index([typebotId, isCompleted])
|
@@index([typebotId, isArchived, isCompleted])
|
||||||
}
|
}
|
||||||
|
|
||||||
model Log {
|
model Log {
|
||||||
|
@ -7,15 +7,12 @@ import {
|
|||||||
VariableWithValue,
|
VariableWithValue,
|
||||||
Typebot,
|
Typebot,
|
||||||
ResultWithAnswersInput,
|
ResultWithAnswersInput,
|
||||||
ResultWithAnswers,
|
|
||||||
InputBlockType,
|
|
||||||
} from 'models'
|
} from 'models'
|
||||||
import { isInputBlock, isDefined, byId, isNotEmpty } from './utils'
|
import { isInputBlock, isDefined, byId } from './utils'
|
||||||
|
|
||||||
export const parseResultHeader = (
|
export const parseResultHeader = (
|
||||||
typebot: Pick<Typebot, 'groups' | 'variables'>,
|
typebot: Pick<Typebot, 'groups' | 'variables'>,
|
||||||
linkedTypebots: Pick<Typebot, 'groups' | 'variables'>[] | undefined,
|
linkedTypebots: Pick<Typebot, 'groups' | 'variables'>[] | undefined
|
||||||
results: ResultWithAnswers[] = []
|
|
||||||
): ResultHeaderCell[] => {
|
): ResultHeaderCell[] => {
|
||||||
const parsedGroups = [
|
const parsedGroups = [
|
||||||
...typebot.groups,
|
...typebot.groups,
|
||||||
@ -35,7 +32,6 @@ export const parseResultHeader = (
|
|||||||
{ label: 'Submitted at', id: 'date' },
|
{ label: 'Submitted at', id: 'date' },
|
||||||
...inputsResultHeader,
|
...inputsResultHeader,
|
||||||
...parseVariablesHeaders(parsedVariables, inputsResultHeader),
|
...parseVariablesHeaders(parsedVariables, inputsResultHeader),
|
||||||
...parseResultsFromPreviousBotVersions(results, inputsResultHeader),
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,32 +168,6 @@ const parseVariablesHeaders = (
|
|||||||
return [...existingHeaders, newHeaderCell]
|
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 =
|
export const parseAnswers =
|
||||||
(
|
(
|
||||||
typebot: Pick<Typebot, 'groups' | 'variables'>,
|
typebot: Pick<Typebot, 'groups' | 'variables'>,
|
||||||
|
Reference in New Issue
Block a user