Skip to content

Reorganize globals into project-based folder structure with translations UI - #188

Merged
Ardnived merged 7 commits into
mainfrom
refactor/globals-folder-structure
Jan 28, 2026
Merged

Ardnived merged 7 commits into
mainfrom
refactor/globals-folder-structure

Conversation

@Ardnived

Copy link
Copy Markdown
Contributor

Summary

This PR refactors the globals structure and adds a new translations management UI:

  • Reorganize globals into project-based folder structure - Moved from flat files to organized folders with separate config and translations files
  • Add JSON Schema validation for translations - Each project has a translationsSchema.json defining translation keys with descriptions
  • Add TranslationsTable field component - Custom admin UI for editing translations with English reference values

New Folder Structure

src/globals/
├── wemeditate-web/
│   ├── config.ts (slug: wm-web-config)
│   └── translations.ts (slug: wm-web-translations)
├── wemeditate-app/
│   ├── config.ts (slug: wm-app-config)
│   └── translations.ts (slug: wm-app-translations)
└── sahaj-atlas/
    ├── config.ts (slug: sy-atlas-config)
    └── translations.ts (slug: sy-atlas-translations)

TranslationsTable Features

  • Table-based UI with key/English value in left column, editable input in right
  • Tooltip showing key description on focus
  • Fetches English translations as reference when editing other locales
  • JSON Schema validation for translation values

Test Results

  • Integration tests: 379 passed
  • Build: ✓ Success

Note: 2 pre-existing test failures in videos.int.spec.ts and storage-utils.int.spec.ts (exist on main branch)

🤖 Generated with Claude Code

Ardnived and others added 7 commits January 27, 2026 20:55
- Move globals into project folders: wemeditate-web/, wemeditate-app/, sahaj-atlas/
- Rename *Settings.ts to config.ts with shorter slugs (e.g., wm-web-config)
- Add translations.ts globals for each project
- Update seed script to use new global slugs
- Update projects.ts with new global slug references

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Create TranslationsTable pure UI component with table layout
- Create TranslationsTableField wrapper with PayloadCMS integration
- Display translation key in first column, input in second column
- Show English translation value instead of key when in non-English locale
- Add tooltip on input focus showing description from JSON schema
- Update all three translation globals to use the new component
- Pass schema entries via admin.custom for key/description access

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Update api-explorer tests to expect sy-atlas-config and sy-atlas-translations
- Update project-visibility tests to use wm-web-config instead of we-meditate-web-settings
- Add collection: 'managers' to mock users (required for bypass function to recognize admin users)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Update globals.md reference to reflect project-based structure
- Add mock user pattern for visibility tests (collection: 'managers' requirement)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Fix type imports: use type-only imports for JSONSchema4
- Fix import order: json-schema before payload (alphabetical)
- Fix infoPages description: change "up to 3" to "up to 5" to match maxRows
- Add clarifying comment for empty fields array in WeMeditateAppConfig

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Update the globals documentation reference to reflect the new
project-based folder structure with config and translations.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@Ardnived
Ardnived merged commit eadef8e into main Jan 28, 2026
@Ardnived
Ardnived deleted the refactor/globals-folder-structure branch January 28, 2026 12:44
Ardnived pushed a commit that referenced this pull request May 25, 2026
…S validate (Workers-safe) (#407)

Writes to wm-app-translations JSON fields fail on prod (Cloudflare
Workers) with:

  ValidationError: The following field is invalid: Navigation > Navigation
  → "Code generation from strings disallowed for this context"
    at beforeChange (worker.js)

Root cause: the JSON-field `jsonSchema` option compiles to an Ajv
validator (`new Ajv() + ajv.validate`) in payload's beforeChange field
validation. Ajv uses `new Function()` for performance, which Cloudflare
Workers' V8 isolate blocks with the CSP-style error above. The bug has
existed since the global was first introduced (#188 / #190) but was
latent because nothing ever wrote to these JSON fields on prod — the
admin UI showed empty fields and translators hadn't yet started. The
#393 seed import is the first thing to hit it.

Fix: drop `jsonSchema` from `createStringsJsonField` and reimplement the
same validation contract (required keys, additionalProperties,
per-key string-type checks) as a pure-JS `validate` function. No more
Ajv compilation, no more dynamic code generation. The admin UX is
unaffected because these JSON fields are rendered by the custom
TranslationsTable component (key/value rows), not Monaco, so the loss
of Monaco's schema hints costs nothing.

Generated types: `pnpm generate:types` produces a more generic shape
for the JSON fields (no inner-key types) since Payload was deriving
those from the jsonSchema. TranslationsTable + the seed converter both
work on the runtime data shape, not the generated TS types, so this is
purely a type-permissiveness regression with no runtime impact.

Wire-up: also adds 'wm-app-translations' to seeds/run.ts's local CLI
registry (ScriptName, VALID_SCRIPTS, SCRIPT_RUN_ORDER, SCRIPT_DESCRIPTIONS,
usage text). This was missed in #404 — the API route already knew about
the seed but the CLI rejected it as Unknown script. Note that the CLI's
cookie-forwarding auth is known-fragile against prod's Workers runtime
(per .claude session-handoff notes); the JWT-header path via direct
fetch to the API endpoint is the verified production-safe import path.

Tests:
- tests/int/translations-field.int.spec.ts — replace the 5 jsonSchema-
  assertion tests with 8 pure-JS validate tests covering: null/undefined
  passes, non-object rejection, missing-required-key rejection,
  unknown-key rejection (when additionalProperties is not true),
  unknown-key acceptance (when additionalProperties is true),
  non-string-value rejection for declared keys, well-formed object
  acceptance.
- tests/int/translations-globals.int.spec.ts — replace the 2 jsonSchema-
  assertion tests with assertions that jsonSchema is undefined and
  validate is a function on every JSON field of all three translation
  globals (wm-web-translations, wm-app-translations, sy-atlas-translations).
- All 728 integration tests + 26 unit tests pass; lint clean; typecheck
  clean for changed files. The 33 "errors" reported by vitest are
  pre-existing unhandled rejections from a payload package-version
  mismatch (@payloadcms/[email protected] vs [email protected]),
  not caused by this change.

Co-authored-by: Claude Opus 4.7 (1M context) <[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.

1 participant