🐛 (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 { authenticatedProcedure } from '@/utils/server/trpc'
|
||||||
import { TRPCError } from '@trpc/server'
|
import { TRPCError } from '@trpc/server'
|
||||||
import { ResultWithAnswers, resultWithAnswersSchema } from 'models'
|
import { ResultWithAnswers, resultWithAnswersSchema } from 'models'
|
||||||
|
import { isDefined } from 'utils'
|
||||||
import { z } from 'zod'
|
import { z } from 'zod'
|
||||||
|
|
||||||
const maxLimit = 200
|
const maxLimit = 200
|
||||||
@ -57,5 +58,12 @@ export const getResultsProcedure = authenticatedProcedure
|
|||||||
nextCursor = nextResult?.id
|
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"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"value": {
|
"value": {
|
||||||
"type": "string",
|
"type": "string"
|
||||||
"nullable": true
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
import { safeStringify } from '@/features/variables'
|
import { safeStringify } from '@/features/variables'
|
||||||
import {
|
import {
|
||||||
Answer,
|
|
||||||
AnswerInput,
|
AnswerInput,
|
||||||
ResultValues,
|
ResultValues,
|
||||||
VariableWithUnknowValue,
|
VariableWithUnknowValue,
|
||||||
VariableWithValue,
|
VariableWithValue,
|
||||||
} from 'models'
|
} from 'models'
|
||||||
import { createContext, ReactNode, useContext, useState } from 'react'
|
import { createContext, ReactNode, useContext, useState } from 'react'
|
||||||
|
import { isDefined } from 'utils'
|
||||||
|
|
||||||
const answersContext = createContext<{
|
const answersContext = createContext<{
|
||||||
resultId?: string
|
resultId?: string
|
||||||
@ -49,7 +49,7 @@ export const AnswersProvider = ({
|
|||||||
const serializedNewVariables = newVariables.map((variable) => ({
|
const serializedNewVariables = newVariables.map((variable) => ({
|
||||||
...variable,
|
...variable,
|
||||||
value: safeStringify(variable.value),
|
value: safeStringify(variable.value),
|
||||||
})) as VariableWithValue[]
|
}))
|
||||||
|
|
||||||
setResultValues((resultValues) => {
|
setResultValues((resultValues) => {
|
||||||
const updatedVariables = [
|
const updatedVariables = [
|
||||||
@ -57,7 +57,7 @@ export const AnswersProvider = ({
|
|||||||
serializedNewVariables.every((variable) => variable.id !== v.id)
|
serializedNewVariables.every((variable) => variable.id !== v.id)
|
||||||
),
|
),
|
||||||
...serializedNewVariables,
|
...serializedNewVariables,
|
||||||
]
|
].filter((variable) => isDefined(variable.value)) as VariableWithValue[]
|
||||||
if (onVariablesUpdated) onVariablesUpdated(updatedVariables)
|
if (onVariablesUpdated) onVariablesUpdated(updatedVariables)
|
||||||
return {
|
return {
|
||||||
...resultValues,
|
...resultValues,
|
||||||
|
@ -12,7 +12,7 @@ export const variableSchema = z.object({
|
|||||||
export const variableWithValueSchema = z.object({
|
export const variableWithValueSchema = z.object({
|
||||||
id: z.string(),
|
id: z.string(),
|
||||||
name: z.string(),
|
name: z.string(),
|
||||||
value: z.string().nullable(),
|
value: z.string(),
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user