Skip to content

Commit

Permalink
🐛 (editor) Fix edge delete with undefined groupIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Nov 9, 2023
1 parent 14a3716 commit 647afdb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from '@typebot.io/schemas'
import { SetTypebot } from '../TypebotProvider'
import { produce, Draft } from 'immer'
import { cleanUpEdgeDraft, deleteEdgeDraft } from './edges'
import { deleteConnectedEdgesDraft, deleteEdgeDraft } from './edges'
import { createId } from '@paralleldrive/cuid2'
import { byId, blockHasItems } from '@typebot.io/lib'
import { duplicateItemDraft } from './items'
Expand Down Expand Up @@ -67,8 +67,8 @@ export const blocksAction = (setTypebot: SetTypebot): BlocksActions => ({
setTypebot((typebot) =>
produce(typebot, (typebot) => {
const removingBlock = typebot.groups[groupIndex].blocks[blockIndex]
deleteConnectedEdgesDraft(typebot, removingBlock.id)
removeBlockFromGroup({ groupIndex, blockIndex })(typebot)
cleanUpEdgeDraft(typebot, removingBlock.id)
removeEmptyGroups(typebot)
})
),
Expand Down Expand Up @@ -153,7 +153,7 @@ export const duplicateBlockDraft = (block: BlockV6): BlockV6 => {

export const deleteGroupDraft =
(typebot: Draft<TypebotV6>) => (groupIndex: number) => {
cleanUpEdgeDraft(typebot, typebot.groups[groupIndex].id)
deleteConnectedEdgesDraft(typebot, typebot.groups[groupIndex].id)
typebot.groups.splice(groupIndex, 1)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,14 @@ const deleteOutgoingEdgeIdProps = ({
}
const fromGroupIndex =
groupIndex ??
typebot.groups.findIndex((g) =>
g.blocks.some((b) => 'blockId' in edge.from && b.id === edge.from.blockId)
typebot.groups.findIndex(
(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(
byId(edge.from.blockId)
Expand All @@ -175,7 +181,7 @@ const deleteOutgoingEdgeIdProps = ({
undefined
}

export const cleanUpEdgeDraft = (
export const deleteConnectedEdgesDraft = (
typebot: Draft<TypebotV6>,
deletedNodeId: string
) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from '@typebot.io/schemas'
import { SetTypebot } from '../TypebotProvider'
import { Draft, produce } from 'immer'
import { cleanUpEdgeDraft } from './edges'
import { deleteConnectedEdgesDraft } from './edges'
import { byId, blockHasItems } from '@typebot.io/lib'
import { createId } from '@paralleldrive/cuid2'
import {
Expand Down Expand Up @@ -172,7 +172,7 @@ const itemsAction = (setTypebot: SetTypebot): ItemsActions => ({
] as BlockWithItems
const removingItem = block.items[itemIndex]
block.items.splice(itemIndex, 1)
cleanUpEdgeDraft(typebot, removingItem.id)
deleteConnectedEdgesDraft(typebot, removingItem.id)
})
),
})
Expand Down

2 comments on commit 647afdb

@vercel
Copy link

@vercel vercel bot commented on 647afdb Nov 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-v2 – ./apps/builder

app.typebot.io
builder-v2-git-main-typebot-io.vercel.app
builder-v2-typebot-io.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 647afdb Nov 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs – ./apps/docs

docs-git-main-typebot-io.vercel.app
docs-typebot-io.vercel.app
docs.typebot.io

Please sign in to comment.