🐛 (editor) Fix edge delete with undefined groupIndex
This commit is contained in:
@ -8,7 +8,7 @@ import {
|
|||||||
} from '@typebot.io/schemas'
|
} from '@typebot.io/schemas'
|
||||||
import { SetTypebot } from '../TypebotProvider'
|
import { SetTypebot } from '../TypebotProvider'
|
||||||
import { produce, Draft } from 'immer'
|
import { produce, Draft } from 'immer'
|
||||||
import { cleanUpEdgeDraft, deleteEdgeDraft } from './edges'
|
import { deleteConnectedEdgesDraft, deleteEdgeDraft } from './edges'
|
||||||
import { createId } from '@paralleldrive/cuid2'
|
import { createId } from '@paralleldrive/cuid2'
|
||||||
import { byId, blockHasItems } from '@typebot.io/lib'
|
import { byId, blockHasItems } from '@typebot.io/lib'
|
||||||
import { duplicateItemDraft } from './items'
|
import { duplicateItemDraft } from './items'
|
||||||
@ -67,8 +67,8 @@ export const blocksAction = (setTypebot: SetTypebot): BlocksActions => ({
|
|||||||
setTypebot((typebot) =>
|
setTypebot((typebot) =>
|
||||||
produce(typebot, (typebot) => {
|
produce(typebot, (typebot) => {
|
||||||
const removingBlock = typebot.groups[groupIndex].blocks[blockIndex]
|
const removingBlock = typebot.groups[groupIndex].blocks[blockIndex]
|
||||||
|
deleteConnectedEdgesDraft(typebot, removingBlock.id)
|
||||||
removeBlockFromGroup({ groupIndex, blockIndex })(typebot)
|
removeBlockFromGroup({ groupIndex, blockIndex })(typebot)
|
||||||
cleanUpEdgeDraft(typebot, removingBlock.id)
|
|
||||||
removeEmptyGroups(typebot)
|
removeEmptyGroups(typebot)
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
@ -153,7 +153,7 @@ export const duplicateBlockDraft = (block: BlockV6): BlockV6 => {
|
|||||||
|
|
||||||
export const deleteGroupDraft =
|
export const deleteGroupDraft =
|
||||||
(typebot: Draft<TypebotV6>) => (groupIndex: number) => {
|
(typebot: Draft<TypebotV6>) => (groupIndex: number) => {
|
||||||
cleanUpEdgeDraft(typebot, typebot.groups[groupIndex].id)
|
deleteConnectedEdgesDraft(typebot, typebot.groups[groupIndex].id)
|
||||||
typebot.groups.splice(groupIndex, 1)
|
typebot.groups.splice(groupIndex, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,8 +152,14 @@ const deleteOutgoingEdgeIdProps = ({
|
|||||||
}
|
}
|
||||||
const fromGroupIndex =
|
const fromGroupIndex =
|
||||||
groupIndex ??
|
groupIndex ??
|
||||||
typebot.groups.findIndex((g) =>
|
typebot.groups.findIndex(
|
||||||
g.blocks.some((b) => 'blockId' in edge.from && b.id === edge.from.blockId)
|
(g) =>
|
||||||
|
edge.to.groupId === g.id ||
|
||||||
|
g.blocks.some(
|
||||||
|
(b) =>
|
||||||
|
'blockId' in edge.from &&
|
||||||
|
(b.id === edge.from.blockId || b.id === edge.to.blockId)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
const fromBlockIndex = typebot.groups[fromGroupIndex].blocks.findIndex(
|
const fromBlockIndex = typebot.groups[fromGroupIndex].blocks.findIndex(
|
||||||
byId(edge.from.blockId)
|
byId(edge.from.blockId)
|
||||||
@ -175,7 +181,7 @@ const deleteOutgoingEdgeIdProps = ({
|
|||||||
undefined
|
undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
export const cleanUpEdgeDraft = (
|
export const deleteConnectedEdgesDraft = (
|
||||||
typebot: Draft<TypebotV6>,
|
typebot: Draft<TypebotV6>,
|
||||||
deletedNodeId: string
|
deletedNodeId: string
|
||||||
) => {
|
) => {
|
||||||
|
@ -8,7 +8,7 @@ import {
|
|||||||
} from '@typebot.io/schemas'
|
} from '@typebot.io/schemas'
|
||||||
import { SetTypebot } from '../TypebotProvider'
|
import { SetTypebot } from '../TypebotProvider'
|
||||||
import { Draft, produce } from 'immer'
|
import { Draft, produce } from 'immer'
|
||||||
import { cleanUpEdgeDraft } from './edges'
|
import { deleteConnectedEdgesDraft } from './edges'
|
||||||
import { byId, blockHasItems } from '@typebot.io/lib'
|
import { byId, blockHasItems } from '@typebot.io/lib'
|
||||||
import { createId } from '@paralleldrive/cuid2'
|
import { createId } from '@paralleldrive/cuid2'
|
||||||
import {
|
import {
|
||||||
@ -172,7 +172,7 @@ const itemsAction = (setTypebot: SetTypebot): ItemsActions => ({
|
|||||||
] as BlockWithItems
|
] as BlockWithItems
|
||||||
const removingItem = block.items[itemIndex]
|
const removingItem = block.items[itemIndex]
|
||||||
block.items.splice(itemIndex, 1)
|
block.items.splice(itemIndex, 1)
|
||||||
cleanUpEdgeDraft(typebot, removingItem.id)
|
deleteConnectedEdgesDraft(typebot, removingItem.id)
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user