sim icon indicating copy to clipboard operation
sim copied to clipboard

fix(naming): client-side unique duplicate names for blocks

Open waleedlatif1 opened this issue 5 months ago • 1 comments

Summary

Implements client-side unique name generation for duplicated blocks, standardizing to "<Base> N" and preventing normalized collisions within a workflow. This keeps resolver/store normalization rules in sync and avoids server-side changes.

Why

  • Avoids confusing name collisions after duplicate, especially across variants that normalize equal (e.g., "My Agent" vs "myagent").
  • Ensures consistent UX across both duplicate entry points (collaborative and local store) with a single source of truth.
  • Honors product decision to rely on client-side uniqueness only; server behavior unchanged.

Changes

  • Added helper at apps/sim/lib/naming.ts:
    • normalizeBlockName(name) – lowercase + strip spaces (parity with resolver/store).
    • generateUniqueBlockDuplicateName(existingNames, sourceName) – produces "Base N"; starts at suffix+1 when source ends with whitespace+digits, otherwise 1; loops until normalized-unique.
  • hooks/use-collaborative-workflow.tscollaborativeDuplicateBlock now uses the helper with current workflow block names.
  • stores/workflows/workflow/store.tsduplicateBlock now uses the helper.
  • updateBlockName in store now imports the shared normalizeBlockName to avoid drift.
  • Tests: apps/sim/lib/naming.test.ts covering base/suffix cases, normalization collisions, gaps, whitespace-heavy names, mixed case, and empty names.

Impact

  • Client-only change; server endpoints and duplication behavior remain unchanged.
  • Rename validation continues to prevent normalized collisions; no regressions expected.

QA

  • Create blocks: "Agent", "Agent 1". Duplicate "Agent" → expect "Agent 2".
  • Create "Agent 3". Duplicate "Agent 2" → expect "Agent 4".
  • Create "agent1" (if allowed). Duplicate "Agent" → should skip to next free beyond normalized collisions.
  • Names with multiple spaces: "My Agent" duplicates to "My Agent 1"; if a normalized collision exists, increments accordingly.

Notes

  • No server behavior changed; resolver normalization remains the source of truth we mirrored.
  • Keeps naming behavior consistent whether duplication originates locally or via collaboration.

waleedlatif1 avatar Sep 06 '25 18:09 waleedlatif1

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
sim Ready Ready Preview Comment Sep 6, 2025 6:49pm
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Sep 6, 2025 6:49pm

vercel[bot] avatar Sep 06 '25 18:09 vercel[bot]