🐛 (typebotLink) Make sure to update all linked bot variable values
This commit is contained in:
@ -11,7 +11,10 @@ test('folders navigation should work', async ({ page }) => {
|
|||||||
await createFolderButton.click()
|
await createFolderButton.click()
|
||||||
await page.click('text="New folder"')
|
await page.click('text="New folder"')
|
||||||
await page.fill('input[value="New folder"]', 'My folder #1')
|
await page.fill('input[value="New folder"]', 'My folder #1')
|
||||||
await page.press('input[value="My folder #1"]', 'Enter'),
|
await Promise.all([
|
||||||
|
page.waitForResponse((resp) => resp.request().method() === 'PATCH'),
|
||||||
|
page.press('input[value="My folder #1"]', 'Enter'),
|
||||||
|
])
|
||||||
await page.click('li:has-text("My folder #1")')
|
await page.click('li:has-text("My folder #1")')
|
||||||
await expect(page.locator('h1:has-text("My folder #1")')).toBeVisible()
|
await expect(page.locator('h1:has-text("My folder #1")')).toBeVisible()
|
||||||
await createFolderButton.click()
|
await createFolderButton.click()
|
||||||
|
@ -54,7 +54,9 @@ export const AnswersProvider = ({
|
|||||||
setResultValues((resultValues) => {
|
setResultValues((resultValues) => {
|
||||||
const updatedVariables = [
|
const updatedVariables = [
|
||||||
...resultValues.variables.filter((v) =>
|
...resultValues.variables.filter((v) =>
|
||||||
serializedNewVariables.every((variable) => variable.id !== v.id)
|
serializedNewVariables.every(
|
||||||
|
(variable) => variable.id !== v.id || variable.name !== v.name
|
||||||
|
)
|
||||||
),
|
),
|
||||||
...serializedNewVariables,
|
...serializedNewVariables,
|
||||||
].filter((variable) => isDefined(variable.value)) as VariableWithValue[]
|
].filter((variable) => isDefined(variable.value)) as VariableWithValue[]
|
||||||
|
@ -3,13 +3,14 @@ import { safeStringify } from '@/features/variables'
|
|||||||
import { sendEventToParent } from '@/utils/chat'
|
import { sendEventToParent } from '@/utils/chat'
|
||||||
import { Log } from 'db'
|
import { Log } from 'db'
|
||||||
import { Edge, PublicTypebot, Typebot } from 'models'
|
import { Edge, PublicTypebot, Typebot } from 'models'
|
||||||
import React, {
|
import {
|
||||||
createContext,
|
createContext,
|
||||||
ReactNode,
|
ReactNode,
|
||||||
useContext,
|
useContext,
|
||||||
useEffect,
|
useEffect,
|
||||||
useState,
|
useState,
|
||||||
} from 'react'
|
} from 'react'
|
||||||
|
import { isDefined } from 'utils'
|
||||||
|
|
||||||
export type LinkedTypebot = Pick<
|
export type LinkedTypebot = Pick<
|
||||||
PublicTypebot | Typebot,
|
PublicTypebot | Typebot,
|
||||||
@ -78,16 +79,28 @@ export const TypebotProvider = ({
|
|||||||
sendEventToParent({
|
sendEventToParent({
|
||||||
newVariableValue: {
|
newVariableValue: {
|
||||||
name:
|
name:
|
||||||
typebot.variables.find((variable) => variable.id === variableId)
|
localTypebot.variables.find((variable) => variable.id === variableId)
|
||||||
?.name ?? '',
|
?.name ?? '',
|
||||||
value: formattedValue ?? '',
|
value: formattedValue ?? '',
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const variable = localTypebot.variables.find((v) => v.id === variableId)
|
||||||
|
const otherVariablesWithSameName = localTypebot.variables.filter(
|
||||||
|
(v) => v.name === variable?.name && v.id !== variableId
|
||||||
|
)
|
||||||
|
const variablesToUpdate = [variable, ...otherVariablesWithSameName].filter(
|
||||||
|
isDefined
|
||||||
|
)
|
||||||
|
|
||||||
setLocalTypebot((typebot) => ({
|
setLocalTypebot((typebot) => ({
|
||||||
...typebot,
|
...typebot,
|
||||||
variables: typebot.variables.map((v) =>
|
variables: typebot.variables.map((variable) =>
|
||||||
v.id === variableId ? { ...v, value: formattedValue } : v
|
variablesToUpdate.some(
|
||||||
|
(variableToUpdate) => variableToUpdate.id === variable.id
|
||||||
|
)
|
||||||
|
? { ...variable, value: formattedValue }
|
||||||
|
: variable
|
||||||
),
|
),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user