Skip to content

feat(media): add sort by title (A to Z / Z to A) - #2016

Merged
bjoerge merged 3 commits into
sanity-io:mainfrom
trostum:feature/media-sort-by-title
Oct 27, 2026
Merged

bjoerge merged 3 commits into
sanity-io:mainfrom
trostum:feature/media-sort-by-title

Conversation

@trostum

@trostum trostum commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Description

Adds a "Title" sort group to the media library's sort order dropdown ("Title: A to Z" / "Title: Z to A"), alongside the existing "File name: A to Z" / "Z to A" options. Assets can already be given a
title via the existing "Title" search facet field; there was previously no way to sort by it — only by file name, MIME type, size, and created/updated timestamps.

Implementation is a straight extension of the existing sort-option mechanism:

  • src/config/orders.ts — added the title entry to ORDER_DICTIONARY with the two direction labels
  • src/constants.ts — added the title asc/desc entries to ORDER_OPTIONS, in their own divider-separated group after "File name"

No changes to the query/dispatch logic — the field is interpolated straight into the existing order(field direction) GROQ query, same as originalFilename, mimeType, and size already are.

What to review

  • src/config/orders.ts and src/constants.ts for the new title entries
  • The sort dropdown (OrderSelect) in the media browser — pick "Title: A to Z" / "Z to A" and confirm assets reorder by their title field

Testing

No dedicated unit tests were added, matching the existing convention: the other sort options (originalFilename, mimeType, size, timestamps) have no test coverage of their own either —
getOrderTitle/ORDER_OPTIONS aren't exercised by a test file in this package today.

Verified instead by:

  • pnpm lint and pnpm format --check on the changed files
  • pnpm turbo build --filter=sanity-plugin-media
  • Full vitest suite for the package (258 tests passing, unaffected)
  • Tested locally using pnpm link

Note

Low Risk
Additive sorting and query expression changes for title only; localized coalesce is covered by unit tests and mirrors documented fallback behavior.

Overview
Adds Title: A to Z and Title: Z to A to the media library sort dropdown (new group in ORDER_OPTIONS and labels in orders.ts).

When the plugin locales option is set, title sorting no longer orders on the raw title object: GROQ order() uses a coalesce() across configured locale keys (in array order), and in-store re-sorts use matching getOrderValue logic so server and client stay aligned. localeIds are passed from tool options through ReduxProvider into the assets slice; fetch paging builds sort with getOrderField. README documents localized title sort behavior; orders.test.ts covers labels, GROQ field building, and value resolution.

Reviewed by Cursor Bugbot for commit d0acd18. Bugbot is set up for automated code reviews on this repo. Configure here.

@trostum
trostum requested a review from a team as a code owner September 17, 2026 13:05
@trostum
trostum requested review from bjoerge and removed request for a team September 17, 2026 13:05
@changeset-bot

changeset-bot Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: fe37f9c

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

This PR includes changesets to release 1 package
Name Type
sanity-plugin-media Minor

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

@vercel

vercel Bot commented Sep 17, 2026

Copy link
Copy Markdown

@trostum is attempting to deploy a commit to the Sanity Sandbox Team on Vercel.

A member of the Team first needs to authorize it.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Localized title objects require locale-aware sorting logic before approval.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Adds title-based sorting to the media library dropdown, including ascending and descending options.

Changes:

  • Adds title sort labels and options.
  • Adds a minor changeset documenting the feature.
  • Requires locale-aware handling for localized titles.
File summaries
File Summary
plugins/sanity-plugin-media/src/constants.ts Adds title sort options.
plugins/sanity-plugin-media/src/config/orders.ts Adds title sort labels.
.changeset/media-sort-by-title.md Documents the release.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

bjoerge
bjoerge previously approved these changes Sep 21, 2026

@bjoerge bjoerge left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for this @trostum!

@bjoerge
bjoerge enabled auto-merge (squash) September 21, 2026 11:18
@vercel

vercel Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
plugins-studio Ready Ready Preview Sep 21, 2026 11:20am UTC

Request Review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit db77acb. Configure here.

auto-merge was automatically disabled October 17, 2026 11:40

Head branch was pushed to by a user without write access

@trostum
trostum force-pushed the feature/media-sort-by-title branch from d8fc3bc to d0acd18 Compare October 17, 2026 11:40
@trostum

trostum commented Oct 17, 2026

Copy link
Copy Markdown
Contributor Author

Thank you for this @trostum!

Could you take another look at this @bjoerge?
Previous approval was blocked by Cursor bugbot it seems :)

@bjoerge
bjoerge enabled auto-merge (squash) October 27, 2026 11:57
trostum and others added 3 commits October 27, 2026 12:58
Adds a new sort option group to the media library dropdown, alongside
the existing file name sort options.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
The sort reducer that runs after uploads, edits and listener updates compared
the raw localized title object, so every pair compared as equal. Resolve the
value through the configured locales, matching the GROQ coalesce() order.

Also add localeIds to the folder epic test fixtures added on main.
@bjoerge
bjoerge force-pushed the feature/media-sort-by-title branch from d0acd18 to fe37f9c Compare October 27, 2026 11:58
@bjoerge
bjoerge requested a review from a team as a code owner October 27, 2026 11:58
@bjoerge
bjoerge requested review from Jamiewarb and removed request for a team October 27, 2026 11:58
auto-merge was automatically disabled October 27, 2026 11:58

Head branch was pushed to by a user without write access

@bjoerge
bjoerge merged commit c7408b1 into sanity-io:main Oct 27, 2026
22 of 28 checks passed
@bjoerge

bjoerge commented Oct 27, 2026

Copy link
Copy Markdown
Member

Thank you so much @trostum

@squiggler-app squiggler-app Bot mentioned this pull request Oct 27, 2026
@trostum

trostum commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

Thank you so much @trostum

Glad to help :)
I have another PR i would really like for someone to take a look at.
Not sure who the right person for this is, but if you can help with that it would be great 👌🏻

#2223

pedrobonamin pushed a commit that referenced this pull request Oct 27, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## sanity-plugin-media@6.6.0

### Minor Changes

- [#2016](#2016)
[`c7408b1`](c7408b1)
Thanks [@trostum](https://github.com/trostum)! - Add "Title: A to Z" and
"Title: Z to A" sort options to the sort order dropdown. When `locales`
are configured, title sorting coalesces through the configured locales
in declared order.
## sanity-plugin-shopify-assets@2.1.0

### Minor Changes

- [#2062](#2062)
[`2c565d0`](2c565d0)
Thanks [@pedrobonamin](https://github.com/pedrobonamin)! - Add an
optional `dataset` setting on the plugin and on `shopify.asset` fields
so asset requests can use the dataset connected to Shopify. A field
value overrides the plugin value, and `dataset` and `shopifyDomain` can
be overridden independently. When neither is set, requests keep using
the active Studio dataset.
## sanity-naive-html-serializer@5.1.16

### Patch Changes

- [#2083](#2083)
[`9b7e239`](9b7e239)
Thanks [@pedrobonamin](https://github.com/pedrobonamin)! - Preserve span
mark definitions, including links without an href, when converting
portable text to HTML and back. An edited anchor href in the HTML
replaces the stored link URL.
## sanity-plugin-internationalized-array@5.3.8

### Patch Changes

- [#2063](#2063)
[`8c7098b`](8c7098b)
Thanks [@pedrobonamin](https://github.com/pedrobonamin)! - Field options
such as `accept` on an internationalized array field are passed through
to each language's underlying value field.
## sanity-plugin-studio-smartling@5.0.23

### Patch Changes

- Updated dependencies []:
  - sanity-translations-tab@6.1.26
## sanity-plugin-transifex@5.1.26

### Patch Changes

- Updated dependencies []:
  - sanity-translations-tab@6.1.26
## sanity-translations-tab@6.1.26

### Patch Changes

- Updated dependencies
[[`9b7e239`](9b7e239)]:
  - sanity-naive-html-serializer@5.1.16
## @sanity/document-internationalization@6.2.45

No changes in this release.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Low Risk**
> Version and changelog-only release automation with no runtime code
changes in this PR; risk is limited to routine npm publish coordination.
> 
> **Overview**
> This is an automated **Changesets** release PR: it bumps npm versions,
appends **CHANGELOG** entries, and removes the consumed `.changeset`
files. There is **no application source diff** here—only packaging
metadata for publishing already-merged work.
> 
> **What ships in this release:** `sanity-plugin-media@6.6.0` adds title
A→Z / Z→A sorting (locale-aware when `locales` are set).
`sanity-plugin-shopify-assets@2.1.0` adds optional `dataset` on the
plugin and `shopify.asset` fields. `sanity-naive-html-serializer@5.1.16`
improves portable text ↔ HTML round-trips for span marks and links.
`sanity-plugin-internationalized-array@5.3.8` forwards field options
(e.g. `accept`) to per-language value fields. `sanity-translations-tab`,
Smartling, and Transifex pick up the serializer bump;
`@sanity/document-internationalization@6.2.45` is a version-only release
with no listed changes.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
47d4ac1. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

Co-authored-by: squiggler-app[bot] <265501495+squiggler-app[bot]@users.noreply.github.com>
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.

3 participants