Repository navigation
feat(@formatjs/editor): add scoped exact search and source copy controls - #7424
Merged
longlho merged 1 commit intoSep 15, 2026
Merged
Conversation
pgonsolin
force-pushed
the
psi/editor-search-and-copy-controls
branch
from
September 15, 2026 21:08
02bbeab to
a25efda
Compare
pgonsolin
marked this pull request as ready for review
September 15, 2026 22:04
Merged
4 of 5 tasks
longlho
added a commit
that referenced
this pull request
Oct 27, 2026
… editors (#7706) ## Motivation A consumer can run several independent translation workspaces (for example a web app and two mobile apps) in one editor deployment, and each workspace receives messages from several upload streams (for example a main branch and a release branch). Today `@formatjs/editor` models a single message set with optional per-message `catalogs` and a `catalog` filter, and location links have to be built by every consumer through `renderLocation`. This PR adds: 1. A **project model** so the shell can list and switch workspaces while the consumer loads that project's messages, locales, and save handler. 2. **Per-message source membership**, distinct from catalogs, with a composable filter, a context row, and row badges. 3. Enough **location metadata** plus exported helpers to build source links without consumer-side hardcoding. Default rendering stays plain text. Follows the conventions of #7403 and #7424: flat files under `packages/editor`, tests next to code, exports through `index.ts` / `ui.tsx`, CHANGELOG left to the release tooling, no consumer-specific naming. ## API additions | Area | Addition | Notes | | --- | --- | --- | | `workflow.ts` | `EditorProject {id, label, description?}` | New type | | `workflow.ts` | `TranslationEditorOptions.projects?`, `project?` (controlled), `defaultProject?`, `onProjectChange?` | All optional; the hook never loads data | | `workflow.ts` | `TranslationEditorState.projects`, `project`, `setProject(id, {discardDrafts?})` | Returns `ProjectChangeResult`: `changed` / `unchanged` / `blocked` (`unsaved-drafts` or `unknown-project`). Resets page, selection, and catalog/source filters | | `workflow.ts` | `ProjectChangeResult`, `ProjectChangeOptions` | New types | | `workflow.ts` | `EditorMessage.sources?: readonly string[]` | Upload streams, distinct from `catalogs` | | `workflow.ts` | `TranslationEditorState.sources`, `source`, `setSource` | Empty-string "all" sentinel, same as `catalog`; composes with status, catalog, and search | | `source-location.ts` | `SourceLocation.source?`, `repository?`, `revision?` | `SourceLocation` is still exported from `workflow.ts` | | `source-location.ts` | `formatSourceLocation(location)` | The `file`, `file:start`, `file:start–end` text `MessageContext` already used | | `source-location.ts` | `resolveSourceLocationHref(location, {baseUrl?, repository?, revision?, lineFragment?})`, `SourceLocationHrefOptions` | `baseUrl` is a string with optional `{repository}` / `{revision}` placeholders or a function; returns `undefined` without a base or a placeholder value | | `core.tsx` | `EditorState.clearSelection()` | Lets workflows drop an explicit selection | | `message-context.tsx` | "Sources" row, `copySources`, labels `sources` / `sourceCopy` | Hidden when the message has no sources | | `design-system.tsx` | `ProjectPicker`, `SourceFilter`, `SourceBadge` adapters and their props types | Optional additions to `EditorToolComponents`; native `<select>` / `<select>` / `<span>` implementations | | `ui.tsx` | `TranslationEditorViewProps.projects?`, `sourceFilter?`; `EditorProjectSelection`, `EditorSourceSelection` | Picker renders when more than one project exists, filter when any source exists | | `ui.tsx` | `EditorMessageRenderState.sources`, `EditorViewMessage.sources?` | Default rows render `SourceBadge`s; custom `renderMessage` receives `state.sources` | | `ui.tsx` | Labels `project`, `sources`, `sourceFilter`, `allSources`, `sourceBadge(source)` | Overridable through `labels` | The spec called for `ProjectPicker` and `SourceBadge`; a third `SourceFilter` adapter was added so the composed view can render the source filter through the design system instead of a raw `<select>`. ## Compatibility - Every option, prop, message field, and label is optional; `projects` defaults to an empty list and `project` to `undefined`. - Existing design-system registries keep type-checking: the new adapters sit in `EditorToolComponents`, which is already `Partial` in `EditorComponents`, and fall back to the native implementations. - `TranslationEditorView` passes `filters` through unchanged when no project or source data is supplied. - `SourceLocation` keeps its shape and export path; `MessageContext` default location text is unchanged. - All 57 existing editor tests pass unchanged; 16 tests were added (73 total). ## Test plan Run in this environment (no Bazel available on the machine): - [x] `tsc` over `packages/editor/*.ts(x)` with the root `tsconfig.json` (`isolatedDeclarations`, `strict`) and the `#packages/*` path mapping – clean - [x] `vitest run` for all 7 editor test files with happy-dom – 73 passed (57 on `main`) - [x] `oxfmt --check packages/editor/` and `oxlint packages/editor/` – clean - [x] `codescythe` dead-export check – clean - [ ] `bazel test //packages/editor/...` – not run locally; relies on CI New tests: - `workflow.test.tsx`: source filter composing with status, catalog, and search; uncontrolled switching resets page/selection/filters and reports `unchanged` / `unknown-project`; `unsaved-drafts` blocks until reset or `discardDrafts`; controlled projects wait for the consumer. - `source-location.test.ts`: file-only, `file:start`, `file:start–end`, placeholders with repository/revision present and absent, fallbacks, path encoding, resolver and fragment overrides, no link without a base. - `tools.test.tsx`: `MessageContext` sources row with copy controls and omission without sources; text-only default locations with resolver-built links via `renderLocation`; native `ProjectPicker` (keyboard-focusable `<select>`, labelled options, disabled), `SourceFilter`, and `SourceBadge`. - `ui.test.tsx`: view renders the picker only with more than one project and the filter only with sources, badges only on rows with sources; custom registries without the new adapters still work and `renderMessage` receives `state.sources`. The demo under `packages/editor/demo` and the VRT gallery were left unchanged: wiring new controls into the StyleX demo is not cheap enough to include here, and nothing new renders without project or source data, so existing visual baselines are unaffected. ## Consumer binding This package only models projects, sources, and location metadata. Loading a project's messages, confirming draft discards, and mapping `repository` / `revision` to a specific hosting URL live in the consuming application, outside this package. --------- Co-authored-by: pgonsolin <[email protected]> Co-authored-by: Long Ho <[email protected]>
longlho
added a commit
that referenced
this pull request
Oct 28, 2026
… editors (#7706) ## Motivation A consumer can run several independent translation workspaces (for example a web app and two mobile apps) in one editor deployment, and each workspace receives messages from several upload streams (for example a main branch and a release branch). Today `@formatjs/editor` models a single message set with optional per-message `catalogs` and a `catalog` filter, and location links have to be built by every consumer through `renderLocation`. This PR adds: 1. A **project model** so the shell can list and switch workspaces while the consumer loads that project's messages, locales, and save handler. 2. **Per-message source membership**, distinct from catalogs, with a composable filter, a context row, and row badges. 3. Enough **location metadata** plus exported helpers to build source links without consumer-side hardcoding. Default rendering stays plain text. Follows the conventions of #7403 and #7424: flat files under `packages/editor`, tests next to code, exports through `index.ts` / `ui.tsx`, CHANGELOG left to the release tooling, no consumer-specific naming. ## API additions | Area | Addition | Notes | | --- | --- | --- | | `workflow.ts` | `EditorProject {id, label, description?}` | New type | | `workflow.ts` | `TranslationEditorOptions.projects?`, `project?` (controlled), `defaultProject?`, `onProjectChange?` | All optional; the hook never loads data | | `workflow.ts` | `TranslationEditorState.projects`, `project`, `setProject(id, {discardDrafts?})` | Returns `ProjectChangeResult`: `changed` / `unchanged` / `blocked` (`unsaved-drafts` or `unknown-project`). Resets page, selection, and catalog/source filters | | `workflow.ts` | `ProjectChangeResult`, `ProjectChangeOptions` | New types | | `workflow.ts` | `EditorMessage.sources?: readonly string[]` | Upload streams, distinct from `catalogs` | | `workflow.ts` | `TranslationEditorState.sources`, `source`, `setSource` | Empty-string "all" sentinel, same as `catalog`; composes with status, catalog, and search | | `source-location.ts` | `SourceLocation.source?`, `repository?`, `revision?` | `SourceLocation` is still exported from `workflow.ts` | | `source-location.ts` | `formatSourceLocation(location)` | The `file`, `file:start`, `file:start–end` text `MessageContext` already used | | `source-location.ts` | `resolveSourceLocationHref(location, {baseUrl?, repository?, revision?, lineFragment?})`, `SourceLocationHrefOptions` | `baseUrl` is a string with optional `{repository}` / `{revision}` placeholders or a function; returns `undefined` without a base or a placeholder value | | `core.tsx` | `EditorState.clearSelection()` | Lets workflows drop an explicit selection | | `message-context.tsx` | "Sources" row, `copySources`, labels `sources` / `sourceCopy` | Hidden when the message has no sources | | `design-system.tsx` | `ProjectPicker`, `SourceFilter`, `SourceBadge` adapters and their props types | Optional additions to `EditorToolComponents`; native `<select>` / `<select>` / `<span>` implementations | | `ui.tsx` | `TranslationEditorViewProps.projects?`, `sourceFilter?`; `EditorProjectSelection`, `EditorSourceSelection` | Picker renders when more than one project exists, filter when any source exists | | `ui.tsx` | `EditorMessageRenderState.sources`, `EditorViewMessage.sources?` | Default rows render `SourceBadge`s; custom `renderMessage` receives `state.sources` | | `ui.tsx` | Labels `project`, `sources`, `sourceFilter`, `allSources`, `sourceBadge(source)` | Overridable through `labels` | The spec called for `ProjectPicker` and `SourceBadge`; a third `SourceFilter` adapter was added so the composed view can render the source filter through the design system instead of a raw `<select>`. ## Compatibility - Every option, prop, message field, and label is optional; `projects` defaults to an empty list and `project` to `undefined`. - Existing design-system registries keep type-checking: the new adapters sit in `EditorToolComponents`, which is already `Partial` in `EditorComponents`, and fall back to the native implementations. - `TranslationEditorView` passes `filters` through unchanged when no project or source data is supplied. - `SourceLocation` keeps its shape and export path; `MessageContext` default location text is unchanged. - All 57 existing editor tests pass unchanged; 16 tests were added (73 total). ## Test plan Run in this environment (no Bazel available on the machine): - [x] `tsc` over `packages/editor/*.ts(x)` with the root `tsconfig.json` (`isolatedDeclarations`, `strict`) and the `#packages/*` path mapping – clean - [x] `vitest run` for all 7 editor test files with happy-dom – 73 passed (57 on `main`) - [x] `oxfmt --check packages/editor/` and `oxlint packages/editor/` – clean - [x] `codescythe` dead-export check – clean - [ ] `bazel test //packages/editor/...` – not run locally; relies on CI New tests: - `workflow.test.tsx`: source filter composing with status, catalog, and search; uncontrolled switching resets page/selection/filters and reports `unchanged` / `unknown-project`; `unsaved-drafts` blocks until reset or `discardDrafts`; controlled projects wait for the consumer. - `source-location.test.ts`: file-only, `file:start`, `file:start–end`, placeholders with repository/revision present and absent, fallbacks, path encoding, resolver and fragment overrides, no link without a base. - `tools.test.tsx`: `MessageContext` sources row with copy controls and omission without sources; text-only default locations with resolver-built links via `renderLocation`; native `ProjectPicker` (keyboard-focusable `<select>`, labelled options, disabled), `SourceFilter`, and `SourceBadge`. - `ui.test.tsx`: view renders the picker only with more than one project and the filter only with sources, badges only on rows with sources; custom registries without the new adapters still work and `renderMessage` receives `state.sources`. The demo under `packages/editor/demo` and the VRT gallery were left unchanged: wiring new controls into the StyleX demo is not cheap enough to include here, and nothing new renders without project or source data, so existing visual baselines are unaffected. ## Consumer binding This package only models projects, sources, and location metadata. Loading a project's messages, confirming draft discards, and mapping `repository` / `revision` to a specific hosting URL live in the consuming application, outside this package. --------- Co-authored-by: pgonsolin <[email protected]> Co-authored-by: Long Ho <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Localization editors need predictable full-catalog search controls and unambiguous copy actions without each host reimplementing those behaviors. Multi-word description queries should match all terms in one description regardless of order, while exact text search should distinguish
OpenfromOpen windowand respect whether the user selected source text, translations, or both.This is the reusable editor portion of the next AGI localization-editor iteration. Product-specific fetching, locale selection, and design-system presentation remain in the host application.
What changed
Opento match an unrelated ID. Optional metadata is partial in partial mode and whole-value in exact mode.SourceMessage/TranslationEditorView. Each copies its exact raw value; absent descriptions render no description action.Verification
//packages/editor:unit_test: 57 tests pass, including token order/all-term behavior, partial versus exact matching, all scopes, ID lookup, pagination resets, controlled UI callbacks, and exact multiline source/description clipboard payloads.//packages/editor:typecheck,:unit_test_typecheck, and:pkgbuild successfully.The new controls are adapter-driven and disabled by default, so existing consumers have no visual change until they opt in.