Skip to content

fix: add filename search and type filtering to the media library#1227

Draft
scottbuscemi wants to merge 1 commit into
mainfrom
fix/1221-media-search
Draft

fix: add filename search and type filtering to the media library#1227
scottbuscemi wants to merge 1 commit into
mainfrom
fix/1221-media-search

Conversation

@scottbuscemi
Copy link
Copy Markdown
Contributor

@scottbuscemi scottbuscemi commented May 29, 2026

Closes #1221.

Problem

Media items couldn't be searched or filtered — on the Media Library page (/_emdash/admin/media) or in the content-editor media picker. With large libraries this made finding an asset impractical. The issue asked for search by file type, extension, and filename.

Fix

Backend (emdash)

  • mediaListQuery gains an optional q (trimmed, 1–200 chars).
  • MediaRepository.findMany applies a case-insensitive lower(filename) LIKE %q% filter (SQLite/Postgres parity), with LIKE wildcards (% _ \) in the term escaped via ESCAPE '\'. A filename substring covers both filename and extension (e.g. .png). The existing mimeType filter already covers file type.
  • Threaded through handleMediaList, the runtime, and the GET /_emdash/api/media route.

Admin (@emdash-cms/admin)

  • fetchMediaList sends q.
  • Media Library page: a filename search box (debounced 300ms) + a type filter Select (All / Images / Video / Audio / Documents → mapped to mimeType). MediaLibrary reports both upward; the route feeds them into the infinite query key + fetch.
  • Media picker (MediaPickerModal): its existing search box now also shows for the local library and drives a debounced q against fetchMediaList.

Testing

  • New packages/core/tests/integration/database/media-filename-search.test.ts (describeEachDialect): substring + case-insensitive, extension match, combined with mimeType, and wildcard-escape ("100%" matches only the literal). Passing on SQLite locally; Postgres in CI.
  • New MediaLibrary tests: reports the debounced query upward; reports a MIME filter when a type is chosen.
  • Full core suite green (3485 tests); pnpm lint:json clean; emdash + @emdash-cms/admin typecheck pass. Admin browser tests run in CI (no local browser available here).

Manual verification

  1. Media page with many assets → type part of a filename (or an extension like .png); list filters. Change the type filter; list narrows by kind.
  2. In a content entity, open the media picker → search the local library by filename.

Try this PR

Open a fresh playground →

A full working EmDash site, deployed from this branch. Each visit gets its own session-scoped sandbox: no login needed and no shared state. Try the admin, edit content, hit the public site.

Tracks fix/1221-media-search. Updated automatically when the playground redeploys.

The Media Library page and the content-editor media picker had no way to
search or filter local media, making large libraries hard to use. Add a
`q` filename substring filter (case-insensitive, matches extensions, LIKE
wildcards escaped) to the media list endpoint alongside the existing
mimeType filter, and wire both surfaces: the Media page gets a search box
plus a type filter (images/video/audio/documents) and the picker searches
the local library by filename. Closes #1221.
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 29, 2026

🦋 Changeset detected

Latest commit: 6982051

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

This PR includes changesets to release 14 packages
Name Type
emdash Patch
@emdash-cms/admin Patch
@emdash-cms/cloudflare Patch
@emdash-cms/sandbox-workerd Patch
@emdash-cms/fixture-perf-site Patch
@emdash-cms/perf-demo-site Patch
@emdash-cms/cache-demo-site Patch
@emdash-cms/auth Patch
@emdash-cms/blocks Patch
@emdash-cms/gutenberg-to-portable-text Patch
@emdash-cms/x402 Patch
create-emdash Patch
@emdash-cms/auth-atproto Patch
@emdash-cms/plugin-embeds 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

@github-actions
Copy link
Copy Markdown
Contributor

PR template validation failed

Please fix the following issues by editing your PR description:

  • This PR does not use the required PR template. Please edit the description to use the PR template. Copy it into your PR description and fill out all sections.

See CONTRIBUTING.md for the full contribution policy.

@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
docs 6982051 May 29 2026, 11:11 PM

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 29, 2026

Open in StackBlitz

@emdash-cms/admin

npm i https://pkg.pr.new/@emdash-cms/admin@1227

@emdash-cms/auth

npm i https://pkg.pr.new/@emdash-cms/auth@1227

@emdash-cms/blocks

npm i https://pkg.pr.new/@emdash-cms/blocks@1227

@emdash-cms/cloudflare

npm i https://pkg.pr.new/@emdash-cms/cloudflare@1227

emdash

npm i https://pkg.pr.new/emdash@1227

create-emdash

npm i https://pkg.pr.new/create-emdash@1227

@emdash-cms/gutenberg-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/gutenberg-to-portable-text@1227

@emdash-cms/x402

npm i https://pkg.pr.new/@emdash-cms/x402@1227

@emdash-cms/plugin-ai-moderation

npm i https://pkg.pr.new/@emdash-cms/plugin-ai-moderation@1227

@emdash-cms/plugin-atproto

npm i https://pkg.pr.new/@emdash-cms/plugin-atproto@1227

@emdash-cms/plugin-audit-log

npm i https://pkg.pr.new/@emdash-cms/plugin-audit-log@1227

@emdash-cms/plugin-color

npm i https://pkg.pr.new/@emdash-cms/plugin-color@1227

@emdash-cms/plugin-embeds

npm i https://pkg.pr.new/@emdash-cms/plugin-embeds@1227

@emdash-cms/plugin-forms

npm i https://pkg.pr.new/@emdash-cms/plugin-forms@1227

@emdash-cms/plugin-webhook-notifier

npm i https://pkg.pr.new/@emdash-cms/plugin-webhook-notifier@1227

commit: 6982051

@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-demo-cache 6982051 May 29 2026, 11:12 PM

@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-playground 6982051 May 29 2026, 11:12 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug - Media - Searchability and Filtering (in Media Library and from Content Entity)

1 participant