🐛 (results) Fix results display when variable has undefined value
This commit is contained in:
@ -3,6 +3,7 @@ import { canReadTypebot } from '@/utils/api/dbRules'
|
||||
import { authenticatedProcedure } from '@/utils/server/trpc'
|
||||
import { TRPCError } from '@trpc/server'
|
||||
import { ResultWithAnswers, resultWithAnswersSchema } from 'models'
|
||||
import { isDefined } from 'utils'
|
||||
import { z } from 'zod'
|
||||
|
||||
const maxLimit = 200
|
||||
@ -57,5 +58,12 @@ export const getResultsProcedure = authenticatedProcedure
|
||||
nextCursor = nextResult?.id
|
||||
}
|
||||
|
||||
return { results, nextCursor }
|
||||
return { results: parseResults(results), nextCursor }
|
||||
})
|
||||
|
||||
// TODO: remove once DB entries are fixed
|
||||
const parseResults = (results: ResultWithAnswers[]): ResultWithAnswers[] =>
|
||||
results.map((result) => ({
|
||||
...result,
|
||||
variables: result.variables.filter((variable) => isDefined(variable.value)),
|
||||
}))
|
||||
|
@ -90,8 +90,7 @@
|
||||
"type": "string"
|
||||
},
|
||||
"value": {
|
||||
"type": "string",
|
||||
"nullable": true
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
@ -1,12 +1,12 @@
|
||||
import { safeStringify } from '@/features/variables'
|
||||
import {
|
||||
Answer,
|
||||
AnswerInput,
|
||||
ResultValues,
|
||||
VariableWithUnknowValue,
|
||||
VariableWithValue,
|
||||
} from 'models'
|
||||
import { createContext, ReactNode, useContext, useState } from 'react'
|
||||
import { isDefined } from 'utils'
|
||||
|
||||
const answersContext = createContext<{
|
||||
resultId?: string
|
||||
@ -49,7 +49,7 @@ export const AnswersProvider = ({
|
||||
const serializedNewVariables = newVariables.map((variable) => ({
|
||||
...variable,
|
||||
value: safeStringify(variable.value),
|
||||
})) as VariableWithValue[]
|
||||
}))
|
||||
|
||||
setResultValues((resultValues) => {
|
||||
const updatedVariables = [
|
||||
@ -57,7 +57,7 @@ export const AnswersProvider = ({
|
||||
serializedNewVariables.every((variable) => variable.id !== v.id)
|
||||
),
|
||||
...serializedNewVariables,
|
||||
]
|
||||
].filter((variable) => isDefined(variable.value)) as VariableWithValue[]
|
||||
if (onVariablesUpdated) onVariablesUpdated(updatedVariables)
|
||||
return {
|
||||
...resultValues,
|
||||
|
@ -12,7 +12,7 @@ export const variableSchema = z.object({
|
||||
export const variableWithValueSchema = z.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
value: z.string().nullable(),
|
||||
value: z.string(),
|
||||
})
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user