Skip to content

Improve event slug generation: include date, number duplicates#1123

Merged
rchlfryn merged 7 commits into
mainfrom
feat/improve-slug-field
Jun 19, 2026
Merged

Improve event slug generation: include date, number duplicates#1123
rchlfryn merged 7 commits into
mainfrom
feat/improve-slug-field

Conversation

@rchlfryn

@rchlfryn rchlfryn commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator

Description

Improves auto-generated slugs for collections with many same-named documents (notably events — ~150 share the title "Avalanche Awareness Class"). Slugs now reliably include the start date and resolve duplicates with a numbered suffix, and the admin UI's regenerate button matches the server behavior. Also fixes a bug where the date never made it into the slug if an editor touched the slug field.

Related Issues

Key Changes

  • Regenerate button now mirrors the server hook (SlugComponent): it composes title + -YYYY-MM-DD instead of title-only. Previously the date logic only ran when the slug was left blank, so clicking ↻ (or otherwise populating the field) silently dropped the date.
  • formatDateForSlug moved to formatSlug.ts so the client component and server hook share one definition.
  • Duplicates use numbers, not -copy for auto-generating fields: on the Payload "Duplicate" action the slug copies verbatim and ensureUniqueSlug bumps it to -2, -3, … (matching the field description). Manual-slug collections keep -copy.
  • Clearer, concise field descriptions explaining how the slug is generated.
  • Tests for formatSlug / formatDateForSlug and the ensureUniqueSlug hook (auto-generation, numbered suffixes, collision errors, current-doc + tenant scoping).

How to test

  1. Create an event with a title and start date; leave the slug blank and save → slug is …-YYYY-MM-DD.
  2. Edit the same event, clear the slug, click the ↻ refresh icon → it regenerates with the date.
  3. Duplicate an event → new slug ends in -2 (not -copy).
  4. pnpm test, pnpm tsc, pnpm lint all pass.

Screenshots / Demo video

Kapture 2026-06-18 at 18 24 25

Migration Explanation

No schema change — slug generation is hook/UI logic only. No migration required.

Future enhancements / Questions

  • Manual-slug collections still append -copy on duplicate; happy to extend numbered suffixes to them too if preferred.
  • A future option could fold a "host" field into the slug (e.g. rei-…) if event titles stay generic.

rchlfryn and others added 5 commits June 18, 2026 13:30
Cover formatSlug/formatDateForSlug helpers and the ensureUniqueSlug hook:
auto-generation from title + date, numbered duplicate suffixes, collision
errors, and current-doc/tenant scoping of the uniqueness check.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

Preview deployment: https://featximprove-slug-field.preview.avy-fx.org

Custom Field components replace Payload's default rendering, so admin.description
was never shown — render it via FieldDescription. Add an Events collection e2e
test asserting the description renders and the regenerate button builds the slug
from title + start date in the real admin, plus a unit test pinning the
description strings slugField() produces.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@rchlfryn rchlfryn added this pull request to the merge queue Jun 19, 2026
Merged via the queue into main with commit e677dca Jun 19, 2026
9 checks passed
@rchlfryn rchlfryn deleted the feat/improve-slug-field branch June 19, 2026 02:21
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.

Research & improve slug naming convention

1 participant