Ghost icon indicating copy to clipboard operation
Ghost copied to clipboard

๐ŸŽจ Add SelectWithOther component for publication language settings

Open betschki opened this issue 5 months ago โ€ข 3 comments

  • Implement SelectWithOther component with dropdown + custom text input support
  • Add comprehensive BCP 47 locale validation with grandfathered tags support
  • Add searchable dropdown with 70+ predefined language options
  • Move locale data to i18n package with TypeScript definitions
  • Add comprehensive test coverage for component and validation logic
  • Improve UX with validation messages and smooth dropdown/input transitions
  • Fix duplicate variable calculation as identified in code review

This is a clean new branch based on the feedback from https://github.com/TryGhost/Ghost/pull/24290


[!NOTE] Adds a SelectWithOther component and updates Publication Language to a searchable select with custom entry, powered by i18n LOCALE_DATA and BCP 47 validation, with tests and build config updates.

  • Settings (General > Publication Language):
    • Replace TextField with SelectWithOther for locale selection; supports search and custom values.
    • Load options from @tryghost/i18n LOCALE_DATA; default to en.
    • Add validation via validateLocale (BCP 47 incl. grandfathered tags).
    • Add acceptance tests covering predefined/custom locales, validation, and mode switching.
  • Design System:
    • Add global/form/SelectWithOther component with toggle between select and text input, validation, and stories.
    • Export SelectWithOther and types from src/index.ts.
  • i18n Package:
    • Expose LOCALE_DATA (code/label pairs) alongside SUPPORTED_LOCALES; add index.d.ts typings and update package.json types path.
  • Validation Utilities:
    • New apps/admin-x-settings/src/utils/localeValidation.ts with comprehensive BCP 47 checks; add unit tests.
  • Build/Config:
    • Include ghost/i18n in Vite commonjsOptions/optimizeDeps in Admin and Settings.
    • Dockerfile: copy ghost/i18n into relevant build stages.
    • Add @tryghost/i18n dependency to admin-x-settings.

Written by Cursor Bugbot for commit af9942d49503c4ed572837210baf39cf67831197. This will update automatically on new commits. Configure here.

betschki avatar Aug 14 '25 19:08 betschki

[!NOTE]

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Adds a new SelectWithOther React component and Storybook stories to the admin design system and re-exports them from the design-system index. Replaces the PublicationLanguage TextField with SelectWithOther and builds locale options from i18n.LOCALE_DATA. Introduces a validateLocale utility with unit tests and updates acceptance tests for publication language to cover predefined and custom locales. Adds TypeScript declarations and LOCALE_DATA export to ghost/i18n, updates its package types/files, adds an @tryghost/i18n dependency, and adjusts Vite and Docker build configs to include i18n assets.

Estimated code review effort

๐ŸŽฏ 4 (Complex) | โฑ๏ธ ~60 minutes

  • Mixed changes across UI component library, application settings, validation logic, tests, build configuration, and package metadata.
  • Areas needing extra attention:
    • apps/admin-x-settings/src/utils/localeValidation.ts (detailed BCP 47-like parsing and heuristics).
    • Unit tests: apps/admin-x-settings/test/unit/utils/localeValidation.test.ts (coverage and edge cases).
    • SelectWithOther component and stories: apps/admin-x-design-system/src/global/form/SelectWithOther.tsx and .stories.tsx (state transitions, validation, accessibility).
    • PublicationLanguage integration and acceptance tests: apps/admin-x-settings/src/components/settings/general/PublicationLanguage.tsx and apps/admin-x-settings/test/acceptance/general/publicationLanguage.test.ts.
    • ghost/i18n exports and type declarations (ghost/i18n/lib/i18n.js, ghost/i18n/index.d.ts, ghost/i18n/package.json) and build config updates (vite.config.*, Dockerfile).

Possibly related PRs

  • TryGhost/Ghost#25375 โ€” touches admin settings integration and Vite build/commonjs options; likely related to the Vite/build config and settings-area changes.

Suggested reviewers

  • kevinansfield
  • rob-ghost
  • peterzimon

Pre-merge checks and finishing touches

โŒ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage โš ๏ธ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
โœ… Passed checks (2 passed)
Check name Status Explanation
Title check โœ… Passed The PR title clearly and concisely describes the main change: adding a SelectWithOther component for publication language settings, which is the primary focus of the changeset.
Description check โœ… Passed The PR description is detailed and directly related to the changeset, covering the SelectWithOther component implementation, locale validation, i18n integration, tests, and configuration updates.
โœจ Finishing touches
  • [ ] ๐Ÿ“ Generate docstrings
๐Ÿงช Generate unit tests (beta)
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment

๐Ÿ“œ Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

๐Ÿ“ฅ Commits

Reviewing files that changed from the base of the PR and between 376014e4cff28b805215819c28b82f51fe1acb86 and af9942d49503c4ed572837210baf39cf67831197.

๐Ÿ“’ Files selected for processing (1)
  • apps/admin/vite.config.ts (1 hunks)
๐Ÿšง Files skipped from review as they are similar to previous changes (1)
  • apps/admin/vite.config.ts
โฐ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: Legacy tests (Node 22.13.1, mysql8)
  • GitHub Check: Acceptance tests (Node 22.13.1, mysql8)
  • GitHub Check: Legacy tests (Node 22.13.1, sqlite3)
  • GitHub Check: Acceptance tests (Node 22.13.1, sqlite3)
  • GitHub Check: Ghost-CLI tests
  • GitHub Check: Unit tests (Node 22.13.1)
  • GitHub Check: Admin-X Settings tests
  • GitHub Check: Lint
  • GitHub Check: Cursor Bugbot
  • GitHub Check: Build & Push

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

โค๏ธ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Aug 14 '25 19:08 coderabbitai[bot]

@betschki unfortunately this branch still has conflicts, I would help get it cleaned up but the permissions on your fork means I can't push anything. Once the branch is in a mergeable state I'm happy to get these changes in ๐Ÿ™‚

kevinansfield avatar Aug 18 '25 08:08 kevinansfield

@kevinansfield thank you for all your help! This should now be mergeable :)

betschki avatar Aug 19 '25 21:08 betschki