Skip to content

fix(ui): give feedback when the project name slugifies to empty - #31

Open
CatJuly wants to merge 1 commit into
HKUDS:mainfrom
CatJuly:fix/project-create-name-feedback
Open

fix(ui): give feedback when the project name slugifies to empty#31
CatJuly wants to merge 1 commit into
HKUDS:mainfrom
CatJuly:fix/project-create-name-feedback

Conversation

@CatJuly

@CatJuly CatJuly commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Clicking + to create a project silently does nothing when the typed name contains no ASCII word characters — for example a fully Chinese name like 知识工程.

Repro: Workspace top bar → + → type 知识工程 → press Enter or click +. Nothing happens: no project, no error, no visual change.

Root cause

handleCreate in ProjectSelector.tsx slugifies the input before submitting:

const id = newName.trim().toLowerCase().replace(/[^a-z0-9_-]+/g, '-').replace(/^-|-$/g, '')
if (!id) return   // ← fully non-ASCII names strip to "" and the click is swallowed here

The slug restriction itself is correct — the backend rejects anything outside [a-z0-9_-] (is_safe_project_id). The bug is purely that the constraint is invisible: the click is dropped with no feedback, which reads as a dead button.

Fix

Derive the slug live while typing (same regex, extracted to toProjectSlug). When the name is non-empty but the slug is empty:

  • the input gets a red outline, aria-invalid, and a tooltip
  • a small hint appears anchored below the input (absolutely positioned, so the top bar layout does not shift): "Use letters, numbers, hyphens or underscores" / "仅支持字母、数字、连字符和下划线"
  • the submit button is disabled

Valid input behaves exactly as before — My App still creates my-app, plain ASCII names are unaffected.

Testing

  • npm run typecheck — clean
  • npm run build — clean; rebuilt frontend_dist bundle included
  • Manual: Chinese-only input shows the invalid state and cannot submit; My App creates my-app; demo-2 creates unchanged; Escape still closes the form

Scope

Frontend only (ProjectSelector.tsx, two i18n keys, rebuilt dist). No backend or validation-rule changes.

Creating a project does nothing when the typed name contains no ASCII
word characters — for example a fully Chinese name like "知识工程".
handleCreate slugifies the input through [^a-z0-9_-] before submitting,
and when everything is stripped it bails out with a bare `return`, so
the "+" click appears dead with no hint about what went wrong.

Derive the slug live while typing. When the name is non-empty but the
slug is empty, mark the input invalid (red outline, tooltip, and a
small anchored hint that does not shift the topbar layout) and disable
the submit button, so the constraint is visible before the click
instead of being swallowed after it.

Verified with `npm run typecheck` and `npm run build`; manually checked
that Chinese-only input shows the invalid state with the hint, that
mixed input like "My App" still creates as "my-app", and that plain
ASCII names are unaffected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant