Skip to content

Commit 26afcd4

Browse files
committed
feat(app-shell): edit a Studio translation item as a source-to-translation table
The table lists a row per string the package declares (the lint walk over the package's declared documents, plus the platform objects it points at), the source text beside the translation, grouped by item, with an untranslated count and filter. Each cell writes the item's JSON at its key, so the saved item and where it is saved are unchanged. The JSON stays as an advanced view. The item list labels a .custom pair's item customer-written. Claude-Session: https://claude.ai/code/session_01WGufzfqCqBH59yrHmuqXH3 Co-authored-by: Claude <noreply@anthropic.com>
1 parent f7afab8 commit 26afcd4

10 files changed

Lines changed: 1253 additions & 6 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
'@object-ui/i18n': patch
4+
---
5+
6+
feat(app-shell): Studio edits a translation item as a source-to-translation table with its gaps counted
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
A `translation` item in Studio now opens on a table for its language: a row per string the package declares (objects, fields, options, apps, navigation, views, actions, dashboards and the rest), the source text beside the translation, grouped by item, with a count such as "37 of 120 untranslated" and an "Untranslated only" filter. The rows come from `collectExpectedEntries` in `@objectstack/lint`, the walk `os i18n extract` and `os lint` use, over the package's declared documents. The platform objects the package points at (for example the user object behind an owner lookup) are included, because their labels ship in a few languages only. A row also counts as translated when another bundle already serves the language at its key.
12+
13+
- Saving writes the same `translation` item to the same place as before (the `.custom` pair on a read-only package): each cell writes the item's JSON at its key. The item's label, language and description stay in the form above the table, and its JSON stays available as an advanced view for what the table does not list (messages, settings UI, metadata forms).
14+
- The "no custom renderer, editing as JSON" notice no longer appears on this page.
15+
- The metadata item list labels an item in a code package's `.custom` pair as customer-written, not as shipped in a code package.
16+
- Labels in English and Chinese.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* objectstack#30285 — the item list's source label. A translation written into
5+
* a code package's `.custom` pair (ADR-0146 D2) is what a customer wrote, not
6+
* what the code package shipped.
7+
*/
8+
9+
import { describe, expect, it } from 'vitest';
10+
import { classifyProvenance } from './ResourceListPage';
11+
12+
describe('classifyProvenance', () => {
13+
it("labels an item in a code package's .custom pair customer-written", () => {
14+
expect(classifyProvenance({ _packageId: 'com.example.crm.custom' })).toBe('runtime');
15+
});
16+
17+
it('keeps an item of the code package itself labelled as shipped in code', () => {
18+
expect(classifyProvenance({ _packageId: 'com.example.crm', _provenance: 'package' })).toBe('artifact');
19+
});
20+
21+
it('reads only a real pair id as a pair: a doubled or bare suffix is not one', () => {
22+
expect(classifyProvenance({ _packageId: 'com.example.crm.custom.custom' })).toBe('artifact');
23+
expect(classifyProvenance({ _packageId: '.custom' })).toBe('artifact');
24+
});
25+
26+
it("keeps the server's own classification first", () => {
27+
expect(classifyProvenance({ _packageId: 'com.example.crm.custom' }, 'code')).toBe('artifact');
28+
expect(classifyProvenance({ _packageId: 'com.example.crm' }, 'overlay')).toBe('runtime');
29+
});
30+
});

‎ui/packages/app-shell/src/views/metadata-admin/ResourceListPage.tsx‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ import { t, tFormat, translateMetadataType, useMetadataLocale } from './i18n.js'
6161
import { buildPackageScopeOptions } from './package-scope.js';
6262
import { ENVIRONMENT_SCOPE_QUERY, isEnvironmentScope, useWalledCatalogReadOnly } from './catalog-scope.js';
6363
import { useMetadataAreaHost } from './metadataAreaHost.js';
64-
import { customizationPackageId } from '@objectstack/spec/kernel';
64+
import { customizationPackageId, isCustomizationPackage } from '@objectstack/spec/kernel';
6565
import { CustomizationMark, usePackageCustomizations } from '../studio-design/CustomizationMark.js';
6666
import {
6767
customizationBaseOfRow,
@@ -131,11 +131,14 @@ type ItemRow = {
131131
* tags objects with the synthetic packageId 'sys_metadata' (see
132132
* framework protocol.ts:3092); treat that sentinel as runtime-authored.
133133
*/
134-
function classifyProvenance(item: Record<string, unknown>, rawSource?: string): 'artifact' | 'runtime' {
134+
export function classifyProvenance(item: Record<string, unknown>, rawSource?: string): 'artifact' | 'runtime' {
135135
if (rawSource === 'overlay' || rawSource === 'runtime') return 'runtime';
136136
if (rawSource === 'code' || rawSource === 'artifact') return 'artifact';
137137
const pkg = item._packageId as string | undefined;
138138
if (!pkg || pkg === 'sys_metadata') return 'runtime';
139+
// objectstack#30285 — a code package's `.custom` pair (ADR-0146 D2) holds
140+
// what the customer wrote over the package, never what shipped in code.
141+
if (isCustomizationPackage(pkg)) return 'runtime';
139142
return 'artifact';
140143
}
141144

‎ui/packages/app-shell/src/views/studio-design/StudioBundleItemEditor.tsx‎

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,24 @@ import {
7777
type CustomizeBlock,
7878
} from './StudioCustomizeControls.js';
7979
import type { StudioBaseCustomization } from './StudioDesignSurface.js';
80+
import { StudioTranslationTable } from './StudioTranslationTable.js';
81+
82+
/**
83+
* objectstack#30285 — what the form still offers for a translation item: its
84+
* identity and language. Its translation groups are the table's, below it.
85+
*/
86+
const TRANSLATION_FORM_KEYS = new Set(['label', 'locale', 'description']);
8087

8188
/** The keys the form never offers: the identity, and the declaration Customize writes. */
82-
function hiddenFieldsOf(type: string): string[] {
89+
function hiddenFieldsOf(type: string, schema?: Record<string, unknown>): string[] {
8390
// An email template's locale is its member: an edit of it would write another member.
84-
return type === 'email_template' ? ['name', 'locale', 'overrides'] : ['name', 'overrides'];
91+
if (type === 'email_template') return ['name', 'locale', 'overrides'];
92+
if (type === 'translation') {
93+
const properties = schema?.properties;
94+
const keys = properties && typeof properties === 'object' ? Object.keys(properties) : [];
95+
return ['name', 'overrides', ...keys.filter((key) => key !== 'name' && key !== 'overrides' && !TRANSLATION_FORM_KEYS.has(key))];
96+
}
97+
return ['name', 'overrides'];
8598
}
8699

87100
/** `doc` without its top-level `_` keys: the read's decorations are not the item's. */
@@ -246,7 +259,10 @@ export function StudioBundleItemEditor({
246259
const schema =
247260
(entry?.schema as Record<string, unknown> | undefined) ??
248261
(config.defaultSchema as Record<string, unknown> | undefined);
249-
const Preview = useRegisteredMetadataPreview(type);
262+
// objectstack#30285 — a translation's table shows its source text and gaps itself.
263+
const isTranslation = type === 'translation';
264+
const RegisteredPreview = useRegisteredMetadataPreview(type);
265+
const Preview = isTranslation ? null : RegisteredPreview;
250266
// objectstack#30064 — a type with a designer of its own (a dataset) is edited in it, not in the form.
251267
const Designer = useRegisteredMetadataDefaultInspector(type);
252268
// What the designer reports as blocking (a dimension with no field): held, never sent.
@@ -639,11 +655,22 @@ export function StudioBundleItemEditor({
639655
form={entry?.form}
640656
value={draft}
641657
onChange={onChange}
642-
hiddenFields={hiddenFieldsOf(type)}
658+
hiddenFields={hiddenFieldsOf(type, schema)}
643659
fieldOrder={config.fieldOrder}
644660
readOnly={!editable}
645661
/>
646662
)}
663+
{isTranslation && (
664+
<div className="mt-4">
665+
<StudioTranslationTable
666+
packageId={packageId}
667+
draft={draft}
668+
onChange={onChange}
669+
readOnly={!editable}
670+
locale={locale}
671+
/>
672+
</div>
673+
)}
647674
</div>
648675
{Preview && (
649676
<div className="min-w-0 border-t lg:overflow-auto lg:border-l lg:border-t-0" data-testid="studio-bundle-editor-preview">
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* objectstack#30285 — Studio's translation table, mounted over a package read
5+
* through the metadata client and the language served through the SDK.
6+
*
7+
* Pinned:
8+
* - a row per declared string, grouped by item, with its source text, the
9+
* platform object the package points at (`sys_user`) included;
10+
* - the count of what is untranslated, and the filter that shows only that;
11+
* - what the language serves from another bundle counts as translated, and
12+
* an answer in another (fallback) language does not;
13+
* - typing a translation hands the item back with the value at the row's key;
14+
* - no "no custom renderer, editing as JSON" notice: JSON is the advanced view.
15+
*/
16+
17+
import * as React from 'react';
18+
import { describe, expect, it, vi, beforeEach } from 'vitest';
19+
import { fireEvent, render, screen, waitFor, within } from '@testing-library/react';
20+
21+
const DECLARED: Record<string, Array<Record<string, unknown>>> = {
22+
object: [
23+
{
24+
name: 'crm_account',
25+
label: 'Account',
26+
fields: {
27+
tier: { type: 'select', label: 'Tier', options: [{ value: 'gold', label: 'Gold' }] },
28+
owner: { type: 'lookup', label: 'Owner', reference: 'sys_user' },
29+
},
30+
},
31+
],
32+
app: [{ name: 'crm', label: 'CRM', navigation: [] }],
33+
};
34+
const PLATFORM: Record<string, Record<string, unknown>> = { sys_user: { name: 'sys_user', label: 'User', fields: {} } };
35+
36+
const mockClient = {
37+
list: vi.fn(async (type: string) => DECLARED[type] ?? []),
38+
layered: vi.fn(async (type: string, name: string, options?: { packageId?: string }) => {
39+
const doc = options?.packageId ? (DECLARED[type] ?? []).find((d) => d.name === name) : PLATFORM[name];
40+
return { code: doc ?? null, effective: doc ?? null };
41+
}),
42+
};
43+
let servedAnswer: { locale: string; translations: Record<string, unknown> } = { locale: 'vi-VN', translations: {} };
44+
const getTranslations = vi.fn(async () => servedAnswer);
45+
46+
vi.mock('../metadata-admin/useMetadata', async (importOriginal) => {
47+
const mod = await importOriginal<typeof import('../metadata-admin/useMetadata')>();
48+
return { ...mod, useMetadataClient: () => mockClient };
49+
});
50+
vi.mock('@object-ui/react', async (importOriginal) => {
51+
const mod = await importOriginal<typeof import('@object-ui/react')>();
52+
const adapter = { getClient: () => ({ i18n: { getTranslations } }) };
53+
return { ...mod, useAdapter: () => adapter };
54+
});
55+
56+
import { StudioTranslationTable } from './StudioTranslationTable';
57+
58+
function Harness({ initial, onSeen }: { initial: Record<string, unknown>; onSeen?: (d: Record<string, unknown>) => void }) {
59+
const [draft, setDraft] = React.useState(initial);
60+
return (
61+
<StudioTranslationTable
62+
packageId="com.example.crm"
63+
draft={draft}
64+
onChange={(next) => {
65+
onSeen?.(next);
66+
setDraft(next);
67+
}}
68+
readOnly={false}
69+
locale="en"
70+
/>
71+
);
72+
}
73+
74+
const rowFor = (key: string) => document.querySelector(`[data-testid="studio-translation-row"][data-key="${key}"]`) as HTMLElement;
75+
76+
beforeEach(() => {
77+
servedAnswer = { locale: 'vi-VN', translations: {} };
78+
mockClient.list.mockClear();
79+
mockClient.layered.mockClear();
80+
});
81+
82+
describe('StudioTranslationTable', () => {
83+
it('lists the declared strings by item, the platform object pointed at included, with the untranslated count', async () => {
84+
render(<Harness initial={{ name: 'crm_vi', locale: 'vi-VN', objects: { crm_account: { label: 'Tài khoản' } } }} />);
85+
const count = await screen.findByTestId('studio-translation-count');
86+
const groups = screen.getAllByTestId('studio-translation-group').map((g) => g.getAttribute('data-group'));
87+
expect(groups).toEqual(expect.arrayContaining(['objects.crm_account', 'objects.sys_user', 'apps.crm']));
88+
expect(within(rowFor('objects.sys_user.label')).getByText('User')).toBeTruthy();
89+
expect(within(rowFor('objects.crm_account.fields.tier.options.gold')).getByText('Gold')).toBeTruthy();
90+
expect(rowFor('objects.crm_account.label').getAttribute('data-state')).toBe('here');
91+
const total = Number(count.getAttribute('data-total'));
92+
expect(Number(count.getAttribute('data-untranslated'))).toBe(total - 1);
93+
expect(count.textContent).toBe(`${total - 1} of ${total} untranslated`);
94+
expect(document.body.textContent).not.toMatch(/custom renderer|JSON editing/i);
95+
});
96+
97+
it('shows only the untranslated rows when filtered', async () => {
98+
render(<Harness initial={{ name: 'crm_vi', locale: 'vi-VN', objects: { crm_account: { label: 'Tài khoản' } } }} />);
99+
await screen.findByTestId('studio-translation-count');
100+
fireEvent.click(screen.getByTestId('studio-translation-only-missing'));
101+
const states = screen.getAllByTestId('studio-translation-row').map((r) => r.getAttribute('data-state'));
102+
expect(states.length).toBeGreaterThan(0);
103+
expect(new Set(states)).toEqual(new Set(['missing']));
104+
expect(rowFor('objects.crm_account.label')).toBeNull();
105+
});
106+
107+
it('counts what the language serves from another bundle as translated, but not a fallback language', async () => {
108+
servedAnswer = { locale: 'vi-VN', translations: { objects: { sys_user: { label: 'Người dùng' } } } };
109+
const { unmount } = render(<Harness initial={{ name: 'crm_vi', locale: 'vi-VN' }} />);
110+
await waitFor(() => expect(rowFor('objects.sys_user.label')?.getAttribute('data-state')).toBe('elsewhere'));
111+
unmount();
112+
113+
servedAnswer = { locale: 'en', translations: { objects: { sys_user: { label: 'User' } } } };
114+
render(<Harness initial={{ name: 'crm_vi', locale: 'vi-VN' }} />);
115+
await screen.findByTestId('studio-translation-count');
116+
await waitFor(() => expect(getTranslations).toHaveBeenCalledWith('vi-VN'));
117+
expect(rowFor('objects.sys_user.label').getAttribute('data-state')).toBe('missing');
118+
});
119+
120+
it("hands the item back with the typed translation at the row's key", async () => {
121+
const seen = vi.fn();
122+
render(<Harness initial={{ name: 'crm_vi', label: 'Tiếng Việt', locale: 'vi-VN' }} onSeen={seen} />);
123+
await screen.findByTestId('studio-translation-count');
124+
fireEvent.change(within(rowFor('objects.sys_user.label')).getByTestId('studio-translation-input'), {
125+
target: { value: 'Người dùng' },
126+
});
127+
expect(seen).toHaveBeenLastCalledWith({
128+
name: 'crm_vi',
129+
label: 'Tiếng Việt',
130+
locale: 'vi-VN',
131+
objects: { sys_user: { label: 'Người dùng' } },
132+
});
133+
expect(rowFor('objects.sys_user.label').getAttribute('data-state')).toBe('here');
134+
});
135+
136+
it('keeps the JSON as an advanced view of the translation groups', async () => {
137+
render(<Harness initial={{ name: 'crm_vi', locale: 'vi-VN', messages: { hello: 'Xin chào' } }} />);
138+
await screen.findByTestId('studio-translation-count');
139+
const json = screen.getByTestId('studio-translation-json-input') as HTMLTextAreaElement;
140+
expect(JSON.parse(json.value)).toEqual({ messages: { hello: 'Xin chào' } });
141+
});
142+
});

0 commit comments

Comments
 (0)