Skip to content

YPE-2777 - feat(hooks): sort Bible versions alphabetically in Version picker#256

Merged
Dustin-Kelley merged 4 commits into
mainfrom
feat/sort-bible-versions-alphabetically
Jun 4, 2026
Merged

YPE-2777 - feat(hooks): sort Bible versions alphabetically in Version picker#256
Dustin-Kelley merged 4 commits into
mainfrom
feat/sort-bible-versions-alphabetically

Conversation

@Dustin-Kelley
Copy link
Copy Markdown
Collaborator

@Dustin-Kelley Dustin-Kelley commented Jun 4, 2026

Summary

  • Sort the BibleVersionPicker "All Versions" list alphabetically after language, search, and recent-version filters are applied.
  • Use localized_title with fallback to title, case-insensitive localeCompare, and id as a stable tiebreaker.
  • Keep the "Recently Used" section in recency order (unchanged in the picker).

Test plan

  • pnpm --filter @youversion/platform-react-hooks vitest run src/useFilteredVersions.test.tsx
  • Open BibleVersionPicker and confirm "All Versions" is A–Z
  • Confirm search results stay alphabetically sorted
image

Made with Cursor

Greptile Summary

This PR adds alphabetical sorting to the "All Versions" list in useFilteredVersions, applied after language, search, and recent-version filters. Sorting uses localized_title with a fallback to title, the 'en' locale for cross-environment consistency, sensitivity: 'base' for case/diacritic-insensitive collation, and id as a stable tiebreaker.

  • useFilteredVersions.ts: Two pure helper functions (getVersionSortTitle, compareVersionsAlphabetically) plus a single result.sort() call inserted after all filter steps — clean and minimal.
  • useFilteredVersions.test.tsx: Pre-computed sortedMockVersions/shuffledMockVersions fixtures and a new alphabetical sorting describe block cover all key scenarios (localized title priority, fallback, post-filter order, search order).
  • .changeset/…: Correctly tagged as a patch with an accurate description.

Confidence Score: 5/5

Safe to merge — the change is additive, operates on a local array copy inside useMemo, and is covered by a thorough test suite.

The sorting logic is straightforward and well-tested. It mutates only a local copy of the array, the 'en' locale is hardcoded for consistency, and the tiebreaker by id ensures a stable result. The one inconsistency (test helper using undefined locale vs the implementation's 'en') does not affect correctness in practice.

No files require special attention.

Important Files Changed

Filename Overview
packages/hooks/src/useFilteredVersions.ts Adds alphabetical sort after all filters using 'en' locale, sensitivity: 'base', and id as a stable tiebreaker. Implementation is clean and correct.
packages/hooks/src/useFilteredVersions.test.tsx Adds comprehensive sorting tests with pre-computed sorted/shuffled fixtures. Minor inconsistency: expectAlphabeticalOrder helper uses undefined locale instead of 'en' to mirror the implementation.
.changeset/sort-bible-versions-alphabetically.md Patch-level changeset entry; description accurately reflects the change.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[versions input] --> B[Clone array]
    B --> C{selectedLanguage not wildcard?}
    C -- Yes --> D[Filter by language_tag]
    C -- No --> E{searchTerm has content?}
    D --> E
    E -- Yes --> F[Filter by title / abbreviation / ISO]
    E -- No --> G{recentVersions defined?}
    F --> G
    G -- Yes --> H[Exclude recent version IDs]
    G -- No --> I[sort via compareVersionsAlphabetically]
    H --> I
    I --> J{titles equal after base collation?}
    J -- No --> K[Order by localeCompare en base]
    J -- Yes --> L[Order by id ascending]
    K --> M[return sorted result]
    L --> M
Loading

Fix All in Claude Code Fix All in Cursor Fix All in Codex

Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
packages/hooks/src/useFilteredVersions.test.tsx:95-101
**Test helper locale doesn't match implementation**

`expectAlphabeticalOrder` calls `localeCompare` with `undefined` as the locale, which uses the runtime default, while `compareVersionsAlphabetically` in the implementation explicitly uses `'en'`. The helper was added specifically to assert the ordering guarantee introduced by this PR, so it should use the same locale to be a meaningful check. In a CI environment whose system locale differs from `'en'`, the helper could silently validate the wrong sort order.

Reviews (4): Last reviewed commit: "Merge branch 'main' into feat/sort-bible..." | Re-trigger Greptile

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jun 4, 2026

🦋 Changeset detected

Latest commit: 42f45c2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@youversion/platform-react-hooks Patch
@youversion/platform-react-ui Patch
vite-react Patch
@youversion/platform-core Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Dustin-Kelley Dustin-Kelley changed the title feat(hooks): sort Bible versions alphabetically in Version picker YPE-2777 - feat(hooks): sort Bible versions alphabetically in Version picker Jun 4, 2026
@Dustin-Kelley Dustin-Kelley marked this pull request as ready for review June 4, 2026 16:48
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 75e269ce35

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/hooks/src/useFilteredVersions.ts
Comment thread packages/hooks/src/useFilteredVersions.ts Outdated
Copy link
Copy Markdown
Collaborator

@cameronapak cameronapak left a comment

Choose a reason for hiding this comment

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

LGTM

Comment thread packages/hooks/src/useFilteredVersions.ts
@Dustin-Kelley Dustin-Kelley merged commit 97b9b6b into main Jun 4, 2026
5 checks passed
@Dustin-Kelley Dustin-Kelley deleted the feat/sort-bible-versions-alphabetically branch June 4, 2026 17:12
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.

2 participants