Fix start block numbering (#1909)

This commit is contained in:
Siddharth Ganesan
2025-11-11 17:52:04 -08:00
committed by GitHub
parent 679c3418d6
commit 769555676e
4 changed files with 39 additions and 22 deletions

View File

@@ -55,6 +55,8 @@ export const ActionBar = memo(
const userPermissions = useUserPermissionsContext()
const isStarterBlock = blockType === 'starter'
// Check for start_trigger (unified start block) - prevent duplication but allow deletion
const isStartBlock = blockType === 'starter' || blockType === 'start_trigger'
/**
* Get appropriate tooltip message based on disabled state
@@ -103,7 +105,7 @@ export const ActionBar = memo(
</Tooltip.Content>
</Tooltip.Root>
{!isStarterBlock && (
{!isStartBlock && (
<Tooltip.Root>
<Tooltip.Trigger asChild>
<Button
@@ -124,7 +126,7 @@ export const ActionBar = memo(
</Tooltip.Root>
)}
{!isStarterBlock && parentId && (parentType === 'loop' || parentType === 'parallel') && (
{!isStartBlock && parentId && (parentType === 'loop' || parentType === 'parallel') && (
<Tooltip.Root>
<Tooltip.Trigger asChild>
<Button
@@ -174,26 +176,24 @@ export const ActionBar = memo(
</Tooltip.Content>
</Tooltip.Root>
{!isStarterBlock && (
<Tooltip.Root>
<Tooltip.Trigger asChild>
<Button
variant='ghost'
onClick={(e) => {
e.stopPropagation()
if (!disabled) {
collaborativeRemoveBlock(blockId)
}
}}
className='h-[30px] w-[30px] rounded-[8px] bg-[#363636] p-0 text-[#868686] hover:bg-[#33B4FF] hover:text-[#1B1B1B] dark:text-[#868686] dark:hover:bg-[#33B4FF] dark:hover:text-[#1B1B1B]'
disabled={disabled}
>
<Trash2 className='h-[14px] w-[14px]' />
</Button>
</Tooltip.Trigger>
<Tooltip.Content side='right'>{getTooltipMessage('Delete Block')}</Tooltip.Content>
</Tooltip.Root>
)}
<Tooltip.Root>
<Tooltip.Trigger asChild>
<Button
variant='ghost'
onClick={(e) => {
e.stopPropagation()
if (!disabled) {
collaborativeRemoveBlock(blockId)
}
}}
className='h-[30px] w-[30px] rounded-[8px] bg-[#363636] p-0 text-[#868686] hover:bg-[#33B4FF] hover:text-[#1B1B1B] dark:text-[#868686] dark:hover:bg-[#33B4FF] dark:hover:text-[#1B1B1B]'
disabled={disabled}
>
<Trash2 className='h-[14px] w-[14px]' />
</Button>
</Tooltip.Trigger>
<Tooltip.Content side='right'>{getTooltipMessage('Delete Block')}</Tooltip.Content>
</Tooltip.Root>
</div>
)
},

View File

@@ -1193,6 +1193,15 @@ export function useCollaborativeWorkflow() {
const sourceBlock = workflowStore.blocks[sourceId]
if (!sourceBlock) return
// Prevent duplication of start blocks (both legacy starter and unified start_trigger)
if (sourceBlock.type === 'starter' || sourceBlock.type === 'start_trigger') {
logger.warn('Cannot duplicate start block - only one start block allowed per workflow', {
blockId: sourceId,
blockType: sourceBlock.type,
})
return
}
// Generate new ID and calculate position
const newId = crypto.randomUUID()
const offsetPosition = {

View File

@@ -59,6 +59,7 @@ const START_CONFLICT_TYPES: TriggerType[] = [
TRIGGER_TYPES.INPUT,
TRIGGER_TYPES.MANUAL,
TRIGGER_TYPES.CHAT,
TRIGGER_TYPES.STARTER, // Legacy starter also conflicts with start_trigger
]
type BlockWithType = { type: string; subBlocks?: Record<string, unknown> | undefined }

View File

@@ -18,6 +18,13 @@ export function normalizeBlockName(name: string): string {
* @returns A unique block name with an appropriate number suffix
*/
export function getUniqueBlockName(baseName: string, existingBlocks: Record<string, any>): string {
// Special case: Start blocks should always be named "Start" without numbers
// This applies to both "Start" and "Starter" base names
const normalizedBaseName = normalizeBlockName(baseName)
if (normalizedBaseName === 'start' || normalizedBaseName === 'starter') {
return 'Start'
}
const baseNameMatch = baseName.match(/^(.*?)(\s+\d+)?$/)
const namePrefix = baseNameMatch ? baseNameMatch[1].trim() : baseName