Repository navigation
fix(media): search localized alt text, title, description and credit line - #2061
Conversation
|
Cursor Agent can help with this pull request. Just |
🦋 Changeset detectedLatest commit: ce727c1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
✅ E2E Tests🟢 46 passed • view full report • view run Studio: https://plugins-e2e-test-studio-qni8qb9xm.sanity.dev Datasets: |
Coverage Report
File Coverage
|
||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Facet matching can incorrectly combine search terms across different translations.
Review effort: Balanced
Findings: 1
What changed in this PR
Adds locale-aware media search to address issue #1699.
Changes:
- Searches localized metadata fields in main search and facets.
- Threads locale IDs through Redux query generation.
- Adds regression tests and a patch changeset.
| File | Description |
|---|---|
.changeset/media-localized-search.md |
Documents the localized-search fix. |
components/Browser/index.tsx |
Passes configured locale IDs to Redux. |
components/ReduxProvider/index.tsx |
Stores locale IDs in initial state. |
modules/assets/index.ts |
Uses locale IDs for asset queries. |
modules/assets/fetchEpic.test.ts |
Tests locale-aware page fetching. |
modules/folders/epics.test.ts |
Updates test state fixtures. |
modules/uploads/index.ts |
Uses locale IDs in upload checks. |
utils/constructFilter.ts |
Builds locale-aware GROQ filters. |
utils/constructFilter.test.ts |
Tests localized search and facets. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
3b763d0 to
3243a2e
Compare
|
@pedrobonamin this makes sense, did we wanna solve the conflicts/comment above and get it in? |
GROQ match does not look inside objects, so those fields missed every result once locales stored them as per-locale maps. Search now targets each configured locale key and still matches plain strings. Co-authored-by: Pedro Bonamin <pedrobonamin@users.noreply.github.com>
3243a2e to
ce727c1
Compare
|
@georgedoescode rebased onto current |
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/color-input@6.1.9 ### Patch Changes - [#2273](#2273) [`4651c2d`](4651c2d) Thanks [@pedrobonamin](https://github.com/pedrobonamin)! - Keep field group tabs in place when a color field first loads. The color input now shows its own loading state instead of suspending the document form. ## sanity-plugin-media@6.6.1 ### Patch Changes - [#2061](#2061) [`078ac51`](078ac51) Thanks [@pedrobonamin](https://github.com/pedrobonamin)! - Search alt text, title, description, and credit line when those fields are stored per locale - [#2276](#2276) [`e5b5459`](e5b5459) Thanks [@coreyward](https://github.com/coreyward)! - Update dependencies `zod` to ^4.6.7 and `@hookform/resolvers` to ^6.0.2 <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Release bookkeeping only; functional changes were merged separately and this PR mainly versions and publishes documented patches. > > **Overview** > This is a **Changesets release** PR: it removes the consumed changeset files and bumps two packages for npm publish. > > **`@sanity/color-input@6.1.9`** — documents a patch fix so field group tabs stay visible while a color field loads; the input shows its own loading state instead of suspending the whole document form. > > **`sanity-plugin-media@6.6.1`** — documents Media browser search over per-locale alt text, title, description, and credit line, plus dependency updates to **`zod` ^4.6.7** and **`@hookform/resolvers` ^6.0.2** (reflected in `package.json` for media). > > There is **no application source diff** here—only version numbers, changelogs, and changeset cleanup. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 60474d7. 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>

Fixes #1699
Problem
When the
localesoption is set,sanity-plugin-mediastoresaltText,title,descriptionandcreditLineas per-locale objects (altText: {en: "brass faucet", "zh-CN": "黄铜龙头"}). Search still queried the bare field (altText match '*faucet*'), and GROQmatchnever matches an object, so both the main search box and the "Alt text" / "Title" / "Description" / "Credit" facets returned nothing for localized values.Reproduced with groq-js 2.0.0 against the filter
constructFilterbuilds:altText)["legacy"]— the localized asset is missing["localized", "legacy"]["localized", "legacy"]zh-CNvalue龙头["localized"]Fix
constructFiltertakes the configuredlocaleIds. For the four localized fields, the main search and theincludes/doesNotIncludefacets matchfield["<localeId>"]for each locale alongside the bare field, so assets not yet migrated from a plain string keep matching.altText.zh-CNparses as subtraction in GROQ. Locale ids are JSON-quoted, deduplicated, and blank ids are skipped.groqWildcardMatch(from fix(media): keep apostrophes in Media search queries #2082), so an apostrophe in a localized query stays inside one GROQ string.empty/notEmptyfacets check the locale keys too, so a localized field counts as empty only when no configured locale has a value.state.assets.localeIds, which title sort (feat(media): add sort by title (A to Z / Z to A) #2016) already fills fromToolOptionsContext→Browser→ReduxProvider. Fields that are never localized (e.g.originalFilename) are untouched.Tests
constructFilter.test.ts: localized main search,includes/doesNotInclude/empty/notEmptyfacets, non-localized facets stay plain, locale id quoting, blank/duplicate ids, and an apostrophe inside a localized search literal.fetchEpic.test.ts:assetsFetchPageIndexEpicsends a query containingaltText["en"]andaltText["zh-CN"]when locales are configured.Changeset:
sanity-plugin-mediapatch.Rebased onto current
main. The conflict with #2016 was the sharedlocaleIdswiring; search now reads the same ids title sort already stores.