Skip to content

feat(@formatjs/editor): refine localization workflows - #7403

Merged
longlho merged 5 commits into
formatjs:mainfrom
pgonsolin:psi/editor-workflow-refinements
Sep 15, 2026
Merged

longlho merged 5 commits into
formatjs:mainfrom
pgonsolin:psi/editor-workflow-refinements

Conversation

@pgonsolin

@pgonsolin pgonsolin commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Why

Consumers of @formatjs/editor currently have to duplicate controlled editor behavior when they need a description-only search, richly rendered locale labels, exact metadata copy controls, compact autosizing translation fields, a remembered grid/list preference, multi-locale status semantics, or parser-backed preview eligibility. That makes product integrations own behavior that belongs at the reusable editor seam.

This was found while simplifying ppl-ai/agi#215483, whose host application should retain locale policy and design-system bindings without parallel editor implementations.

What changed

  • Adds case-insensitive descriptionQuery state to the headless editor and a separately controlled descriptionSearch field to the composed view. Description and general searches are conjunctive; workflow pagination resets for either query.
  • Adds renderLocaleLabel(locale, label) while preserving plain accessible label text and the picker's existing controlled selection, Select All, and contiguous column ordering.
  • Adds opt-in exact catalog and source-location copy controls to MessageContext, sharing CopyTextButton feedback and host clipboard adapters.
  • Extends the textarea adapter contract with one-to-ten-row defaults. The native adapter grows and shrinks with controlled content, then scrolls at the maximum.
  • Adds guarded useTranslationLayout, defaulting to grid and persisting valid grid/list preferences through browser storage or a supplied adapter.
  • Exposes hasTranslationForEveryLocale / matchesMessageStatus for the all-selected translated and any-selected missing contract.
  • Exposes hasMeaningfulIcuStructure, which accepts only valid parser output containing non-literal ICU elements; plain literals, escaped braces, and invalid drafts are not previewable.

Consumer-owned locale naming, design-system presentation, fetching/debouncing/cancellation, server persistence, and product-specific status help remain outside the package.

Verification

  • //packages/editor:unit_test: 47 tests pass, including the new workflow utility and adapter regressions.
  • //packages/editor:pkg, :typecheck, and :unit_test_typecheck build.
  • The isolated browser component and E2E suites pass. The three intentional visual changes (search placeholder plus desktop/mobile workflow states) were regenerated in the repository's pinned actiond environment and inspected before committing their baselines.
  • Repository Oxfmt, Oxlint, ast-grep, Codescythe, Gazelle, buildifier, lockfile regeneration, generated package registry, and commitlint hooks pass.

@pgonsolin
pgonsolin marked this pull request as ready for review September 14, 2026 19:45
@longlho
longlho enabled auto-merge (squash) September 14, 2026 19:58
@longlho
longlho force-pushed the psi/editor-workflow-refinements branch from 062e292 to f69241c Compare September 14, 2026 20:21
longlho added a commit that referenced this pull request Sep 14, 2026
Fork PR tests fall back to local Bazel execution while main uses RBE, so
their action keys differ. The old `disk-Test-` restore prefix also
matches examples caches: #7403 restored a 51 MiB examples cache before
running roughly 50,000 actions locally.

Give the GHA test job a dedicated Ubuntu 24.04 disk cache and run the
same local configuration on main and PRs. Main saves a fresh snapshot
per run, including completed actions when later tests fail; PRs only
restore. The prefix includes architecture and Bazel version and cannot
match examples or release caches. BuildBuddy workflows and release jobs
retain their existing remote execution setup.

Validation: actionlint 1.7.12 and repository commit hooks. End-to-end
cache reuse requires a main run to seed the new namespace after merge,
followed by a PR restore; no speedup is claimed yet. The initial main
run and later cache misses execute locally, so cold runs can still be
slow. This changes neither #7403 nor its running workflows.
@longlho
longlho force-pushed the psi/editor-workflow-refinements branch 2 times, most recently from f89a1f3 to 1543734 Compare September 15, 2026 01:34
@longlho
longlho force-pushed the psi/editor-workflow-refinements branch 2 times, most recently from 90ab837 to 9291af0 Compare September 15, 2026 02:20
@longlho
longlho merged commit be8d268 into formatjs:main Sep 15, 2026
16 of 18 checks passed
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]>
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