Skip to content

Commit

Permalink
🐛 Fix edge dropping on condition block when all conditions ar…
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Mar 29, 2024
1 parent 37204f5 commit 1566f01
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Draft, produce } from 'immer'
import { byId, isDefined } from '@typebot.io/lib'
import { blockHasItems } from '@typebot.io/schemas/helpers'
import { createId } from '@paralleldrive/cuid2'
import { InputBlockType } from '@typebot.io/schemas/features/blocks/inputs/constants'

export type EdgesActions = {
createEdge: (edge: Omit<Edge, 'id'>) => void
Expand Down Expand Up @@ -67,7 +68,11 @@ export const edgesAction = (setTypebot: SetTypebot): EdgesActions => ({
const areAllItemsConnected = (block as BlockWithItems).items.every(
(item) => isDefined(item.outgoingEdgeId)
)
if (areAllItemsConnected) {
if (
areAllItemsConnected &&
(block.type === InputBlockType.CHOICE ||
block.type === InputBlockType.PICTURE_CHOICE)
) {
deleteEdgeDraft({
typebot,
edgeId: block.outgoingEdgeId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ConnectingIds } from '../../types'
import { useEventsCoordinates } from '../../providers/EventsCoordinateProvider'
import { eventWidth, groupWidth } from '../../constants'
import { useGroupsStore } from '../../hooks/useGroupsStore'
import { omit } from '@typebot.io/lib'

type Props = {
connectingIds: ConnectingIds
Expand Down Expand Up @@ -113,7 +114,13 @@ export const DrawingEdge = ({ connectingIds }: Props) => {

const createNewEdge = (connectingIds: ConnectingIds) => {
assert(connectingIds.target)
createEdge({ from: connectingIds.source, to: connectingIds.target })
createEdge({
from:
'groupId' in connectingIds.source
? omit(connectingIds.source, 'groupId')
: connectingIds.source,
to: connectingIds.target,
})
}

if (mousePosition && mousePosition.x === 0 && mousePosition.y === 0)
Expand Down

0 comments on commit 1566f01

Please sign in to comment.