Skip to content

Comments

fix: auto-convert project name in settings & consolidate code#4436

Open
elias-ba wants to merge 6 commits intomainfrom
fix/project-settings-name-conversion
Open

fix: auto-convert project name in settings & consolidate code#4436
elias-ba wants to merge 6 commits intomainfrom
fix/project-settings-name-conversion

Conversation

@elias-ba
Copy link
Contributor

@elias-ba elias-ba commented Feb 18, 2026

Description

Fixes the project settings form to auto-convert project names to URL-safe format (lowercase, hyphens, digits), matching the behavior of the project creation form. Previously, entering a name like "DEP-burundi-datafi" in settings would fail validation since the form submitted the raw input directly.

This PR also consolidates all duplicate coerce_raw_name_to_safe_name functions into Project.form_changeset/2 and Project.form_with_users_changeset/2, using a virtual :raw_name schema field. This follows the pattern already established by Collection.form_changeset.

Along the way, a pre-existing bug was fixed in the dashboard creation modal where the save error path assigned to :project_changeset instead of :changeset, meaning validation errors from failed project creation were silently swallowed. Additionally, the @name assign is now initialized in update/2 (previously it only got set after the first validation event), and whitespace inside the name preview badge <span> tags was cleaned up to remove a trailing space.

Closes #4437

Validation steps

Project settings

  1. Edit the project name with uppercase/spaces (e.g. "My Cool Project")
  2. Verify the preview badge shows my-cool-project
  3. Save and confirm it persists the slug name
  4. Clear the name and verify a single "can't be blank" error (not duplicated)
  5. Change retention settings and verify the name does not break

Create New Project

  1. Type "Hello World!" and verify badge shows hello-world
  2. Clear the name and verify submit disables and a single error shows
  3. Submit and verify the project is created with the slug name

Create / Edit Sandboxes

  1. Create with "My Sandbox" and verify badge shows my-sandbox
  2. Create another with the same name and verify "Sandbox name already exists" error
  3. Edit a sandbox and rename it

Create / Edit Collections

  1. Create with spaces/uppercase and verify slug preview
  2. Edit an existing collection and verify name displays correctly

Create / Edit Projects (superuser interface)

  1. Edit name to uppercase and verify preview updates
  2. Save and verify slug persists

AI Usage

  • I have used Claude Code
  • I have used another model
  • I have not used AI

Pre-submission checklist

  • I have performed an AI review of my code (we recommend using /review with Claude Code)
  • I have implemented and tested all related authorization policies. (e.g., :owner, :admin, :editor, :viewer)
  • I have updated the changelog.
  • I have ticked a box in "AI usage" in this PR

The project creation form auto-converts uppercase and spaces to the
lowercase-hyphens-digits format, but the settings form did not, causing
users to get a validation error when entering names like "DEP-burundi-datafi".

Aligns the settings form with the creation form by using a raw_name input
that gets converted via Helpers.url_safe_name/1 before saving.
@github-project-automation github-project-automation bot moved this to New Issues in v2 Feb 18, 2026
The project name input was changed from `name` to `raw_name` for the
url-safe conversion feature, but two test assertions still referenced
the old field name.
@codecov
Copy link

codecov bot commented Feb 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.43%. Comparing base (32f1001) to head (eb71080).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4436      +/-   ##
==========================================
+ Coverage   89.33%   89.43%   +0.10%     
==========================================
  Files         425      425              
  Lines       20133    20147      +14     
==========================================
+ Hits        17985    18018      +33     
+ Misses       2148     2129      -19     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@stuartc stuartc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some issues, mostly around the validation not being tested - and errors not shown probably (raw_name doesn't have a schema so I can't see it getting errors?).

Also there is a smell around the copy pasting of coerce_raw_name_to_safe_name, not just in this PR, in other places. There are 5 different files with an almost copy paste of this kind of function. I first thought we should put the transform into the schema, but then thought that might cause rendering weirdness with the schema changing the input - Collection has a form_changeset function that handles the :raw_name and the model has that as a virtual field. Keeping the logic a model concern and not a view concern.

@github-project-automation github-project-automation bot moved this from New Issues to In review in v2 Feb 20, 2026
Replace 5 duplicate `coerce_raw_name_to_safe_name` functions with
`Project.form_changeset/2` and `form_with_users_changeset/2` that use
a virtual `:raw_name` field to derive the URL-safe `:name` automatically.

- Add `Helpers.derive_name_param/1` so all save handlers derive the
  name server-side instead of relying on hidden-field timing
- Fix duplicate "can't be blank" error by moving `validate_required([:name])`
  out of shared `validate/1` into callers that cast `:name` directly
- Fix dashboard creation modal error path assigning to wrong key
  (`:project_changeset` → `:changeset`)
- Extract shared `<.name_badge>` component in Pills for the name
  preview badge used across all 5 forms
@elias-ba elias-ba changed the title fix: auto-convert project name in settings form refactor: consolidate raw_name coercion into Project schema Feb 21, 2026
@elias-ba elias-ba changed the title refactor: consolidate raw_name coercion into Project schema refactor: consolidate raw_name coercion into project schema Feb 21, 2026
@elias-ba elias-ba changed the title refactor: consolidate raw_name coercion into project schema fix: auto-convert project name in settings & consolidate raw_name coercion Feb 21, 2026
@elias-ba elias-ba changed the title fix: auto-convert project name in settings & consolidate raw_name coercion fix: auto-convert project name in settings Feb 21, 2026
@elias-ba elias-ba changed the title fix: auto-convert project name in settings fix: auto-convert project name in settings & consolidate raw_name coercion Feb 21, 2026
@elias-ba elias-ba changed the title fix: auto-convert project name in settings & consolidate raw_name coercion fix: auto-convert project name in settings & consolidate code Feb 21, 2026
Add tests for previously untested code paths:
- settings cancel-retention-change handler resets form
- settings/dashboard/admin save error paths with copy_error
- sandbox edit save error path with copy_error
- fix broken changeset construction in sandbox edit stub
Copy link
Contributor Author

@elias-ba elias-ba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @stuartc, great catch on all fronts. I've reworked the PR following your suggestion to use the Collection pattern. Project now has a virtual :raw_name field and a form_changeset/2 that handles the derivation at the schema level, so all copies of coerce_raw_name_to_safe_name are gone. Errors on :name get copied back to :raw_name so they show up on the visible input. Also extracted a shared <.name_badge> component since the preview badge was duplicated across all the forms. I think this now looks way better, thanks a lot again. Would you mind having another look ?

@elias-ba elias-ba requested a review from stuartc February 21, 2026 23:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

bug: project settings form does not auto-convert project name to url safe names

2 participants