♻️ Use at function instead of dangerous direct lookup array index
This commit is contained in:
@@ -58,6 +58,10 @@ export const PictureChoiceItemNode = ({
|
|||||||
}
|
}
|
||||||
useEventListener('wheel', handleMouseWheel, ref.current)
|
useEventListener('wheel', handleMouseWheel, ref.current)
|
||||||
|
|
||||||
|
const blockId = typebot
|
||||||
|
? typebot.groups.at(indices.groupIndex)?.blocks?.at(indices.blockIndex)?.id
|
||||||
|
: undefined
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Popover
|
<Popover
|
||||||
placement="right"
|
placement="right"
|
||||||
@@ -132,15 +136,12 @@ export const PictureChoiceItemNode = ({
|
|||||||
shadow="lg"
|
shadow="lg"
|
||||||
ref={ref}
|
ref={ref}
|
||||||
>
|
>
|
||||||
{typebot && (
|
{typebot && blockId && (
|
||||||
<PictureChoiceItemSettings
|
<PictureChoiceItemSettings
|
||||||
workspaceId={typebot.workspaceId}
|
workspaceId={typebot.workspaceId}
|
||||||
typebotId={typebot.id}
|
typebotId={typebot.id}
|
||||||
item={item}
|
item={item}
|
||||||
blockId={
|
blockId={blockId}
|
||||||
typebot.groups[indices.groupIndex].blocks[indices.blockIndex]
|
|
||||||
.id
|
|
||||||
}
|
|
||||||
onItemChange={handleItemChange}
|
onItemChange={handleItemChange}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ export const BlockNode = ({
|
|||||||
previewingEdge?.to.blockId === block.id ||
|
previewingEdge?.to.blockId === block.id ||
|
||||||
previewingBlock?.id === block.id
|
previewingBlock?.id === block.id
|
||||||
|
|
||||||
const groupId = typebot?.groups[indices.groupIndex].id
|
const groupId = typebot?.groups.at(indices.groupIndex)?.id
|
||||||
|
|
||||||
const isDraggingGraph = useGroupsStore((state) => state.isDraggingGraph)
|
const isDraggingGraph = useGroupsStore((state) => state.isDraggingGraph)
|
||||||
|
|
||||||
@@ -240,11 +240,13 @@ export const BlockNode = ({
|
|||||||
transition="border-color 0.2s"
|
transition="border-color 0.2s"
|
||||||
>
|
>
|
||||||
<BlockIcon type={block.type} mt=".25rem" />
|
<BlockIcon type={block.type} mt=".25rem" />
|
||||||
{typebot?.groups[indices.groupIndex].id && (
|
{typebot?.groups.at(indices.groupIndex)?.id && (
|
||||||
<BlockNodeContent
|
<BlockNodeContent
|
||||||
block={block}
|
block={block}
|
||||||
indices={indices}
|
indices={indices}
|
||||||
groupId={typebot.groups[indices.groupIndex].id}
|
groupId={
|
||||||
|
typebot.groups.at(indices.groupIndex)?.id as string
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{(hasIcomingEdge || isDefined(connectingIds)) && (
|
{(hasIcomingEdge || isDefined(connectingIds)) && (
|
||||||
|
|||||||
@@ -70,6 +70,8 @@ export const ItemNode = ({
|
|||||||
const handleMouseEnter = () => setIsMouseOver(true)
|
const handleMouseEnter = () => setIsMouseOver(true)
|
||||||
const handleMouseLeave = () => setIsMouseOver(false)
|
const handleMouseLeave = () => setIsMouseOver(false)
|
||||||
|
|
||||||
|
const groupId = typebot?.groups.at(indices.groupIndex)?.id
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ContextMenu<HTMLDivElement>
|
<ContextMenu<HTMLDivElement>
|
||||||
renderMenu={() => <ItemNodeContextMenu indices={indices} />}
|
renderMenu={() => <ItemNodeContextMenu indices={indices} />}
|
||||||
@@ -114,20 +116,22 @@ export const ItemNode = ({
|
|||||||
isMouseOver={isMouseOver}
|
isMouseOver={isMouseOver}
|
||||||
indices={indices}
|
indices={indices}
|
||||||
/>
|
/>
|
||||||
{typebot && (isConnectable || pathname.endsWith('analytics')) && (
|
{typebot &&
|
||||||
<BlockSourceEndpoint
|
(isConnectable || pathname.endsWith('analytics')) &&
|
||||||
source={{
|
groupId && (
|
||||||
blockId: block.id,
|
<BlockSourceEndpoint
|
||||||
itemId: item.id,
|
source={{
|
||||||
}}
|
blockId: block.id,
|
||||||
groupId={typebot.groups[indices.groupIndex].id}
|
itemId: item.id,
|
||||||
pos="absolute"
|
}}
|
||||||
right="-49px"
|
groupId={groupId}
|
||||||
bottom="9px"
|
pos="absolute"
|
||||||
pointerEvents="all"
|
right="-49px"
|
||||||
isHidden={!isConnectable}
|
bottom="9px"
|
||||||
/>
|
pointerEvents="all"
|
||||||
)}
|
isHidden={!isConnectable}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</Flex>
|
</Flex>
|
||||||
</Stack>
|
</Stack>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ export const ItemNodesList = ({
|
|||||||
|
|
||||||
const isLastBlock =
|
const isLastBlock =
|
||||||
isDefined(typebot) &&
|
isDefined(typebot) &&
|
||||||
typebot.groups[groupIndex]?.blocks?.[blockIndex + 1] === undefined
|
typebot.groups.at(groupIndex)?.blocks?.at(blockIndex + 1) === undefined
|
||||||
|
|
||||||
const someChoiceItemsAreNotConnected =
|
const someChoiceItemsAreNotConnected =
|
||||||
block.type === InputBlockType.CHOICE ||
|
block.type === InputBlockType.CHOICE ||
|
||||||
@@ -131,6 +131,8 @@ export const ItemNodesList = ({
|
|||||||
elem && (placeholderRefs.current[idx] = elem)
|
elem && (placeholderRefs.current[idx] = elem)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const groupId = typebot?.groups.at(groupIndex)?.id
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack flex={1} spacing={1} maxW="full" onClick={stopPropagating}>
|
<Stack flex={1} spacing={1} maxW="full" onClick={stopPropagating}>
|
||||||
<PlaceholderNode
|
<PlaceholderNode
|
||||||
@@ -153,11 +155,8 @@ export const ItemNodesList = ({
|
|||||||
/>
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
))}
|
))}
|
||||||
{isLastBlock && someChoiceItemsAreNotConnected && (
|
{isLastBlock && someChoiceItemsAreNotConnected && groupId && (
|
||||||
<DefaultItemNode
|
<DefaultItemNode block={block} groupId={groupId} />
|
||||||
block={block}
|
|
||||||
groupId={typebot.groups[groupIndex].id}
|
|
||||||
/>
|
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{draggedItem && draggedItem.blockId === block.id && (
|
{draggedItem && draggedItem.blockId === block.id && (
|
||||||
|
|||||||
@@ -19,5 +19,5 @@ export const getFirstEdgeId = ({
|
|||||||
return event.outgoingEdgeId
|
return event.outgoingEdgeId
|
||||||
}
|
}
|
||||||
if (typebot.version === '6') return typebot.events[0].outgoingEdgeId
|
if (typebot.version === '6') return typebot.events[0].outgoingEdgeId
|
||||||
return typebot.groups[0].blocks[0].outgoingEdgeId
|
return typebot.groups.at(0)?.blocks.at(0)?.outgoingEdgeId
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,10 +7,10 @@ export const getBlockById = (
|
|||||||
for (let groupIndex = 0; groupIndex < groups.length; groupIndex++) {
|
for (let groupIndex = 0; groupIndex < groups.length; groupIndex++) {
|
||||||
for (
|
for (
|
||||||
let blockIndex = 0;
|
let blockIndex = 0;
|
||||||
blockIndex < groups[groupIndex].blocks.length;
|
blockIndex < (groups.at(groupIndex)?.blocks?.length ?? 0);
|
||||||
blockIndex++
|
blockIndex++
|
||||||
) {
|
) {
|
||||||
if (groups[groupIndex].blocks[blockIndex].id === blockId) {
|
if (groups.at(groupIndex)?.blocks?.at(blockIndex)?.id === blockId) {
|
||||||
return {
|
return {
|
||||||
block: groups[groupIndex].blocks[blockIndex],
|
block: groups[groupIndex].blocks[blockIndex],
|
||||||
group: groups[groupIndex],
|
group: groups[groupIndex],
|
||||||
|
|||||||
Reference in New Issue
Block a user