Skip to content

Commit eec2bc3

Browse files
fix(app-shell): object picker refusal says the current object is kept when it is (#38617)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9JeHmqv6CKCkW8ewrPBLekk)_ Fixes #37926 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:Studio 字段设置里,查找字段的“关联对象”或汇总字段的“子对象”已选好时,输错对象名,提示从“未选择对象”改为“不是对象,已保留当前对象”;空字段时提示不变。 - 为什么做:这是上一轮“输错不再清掉已选对象”修复的收尾,替搭建应用的人消除提示与实际结果相矛盾的情况。 - 出错会怎样:只影响一行提示文字,保存下来的元数据不受影响,可直接撤回。 - 要你做什么:无。 ## What changes - `ObjectPicker` (objects-only mode): when typed text names no object and the field already has a stored target, the refusal line now renders the new studio key `engine.inspector.objectPicker.notAnObjectKept` instead of `notChosen`. The choice is made at render time from `value` (non-empty = the target `commitTyped` just restored), so the line can never claim a kept target when there is none. - `@object-ui/i18n` studio namespace: one new key in `en.ts` and `zh.ts`, next to `notChosen` (whose text is unchanged): - en: "“{text}” is not an object; the current object is kept." - zh: 「“{text}”不是对象,已保留当前对象。」 - Patch changeset for `@object-ui/app-shell` and `@object-ui/i18n`. **Read first (by risk):** 1. `ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectPicker.tsx`, the refusal notice hunk (the key choice). 2. `ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectPicker.test.tsx`, the objectsOnly describe block (pins per case and locale). **Two-minute check:** from `ui/`, `pnpm exec vitest run packages/app-shell/src/views/metadata-admin/inspectors/ObjectPicker.test.tsx`. You should see 18 tests pass, four of them named `[en-US]` / `[zh-CN]`. ## Tests The two existing objectsOnly refusal cases now run once per locale (`en-US`, `zh-CN`) and assert the rendered line: - empty field + refused prefix: the `notChosen` line; - stored target + refused name (Enter and blur): the `notAnObjectKept` line, and not the `notChosen` line. For zh, each pin also asserts the line is not the en text, so an en fallback cannot pass for zh. That assertion caught a real ordering issue: the studio zh table loads lazily, so the file now awaits `loadStudioCatalogue('zh')` at the top, as sibling tests do. <details><summary>Run on HEAD (5 picker-related files + studio namespace parity)</summary> ``` Test Files 5 passed (5) Tests 54 passed (54) os-verify-lock: VERDICT command-exit 0 ``` </details> <details><summary>Ablation: kept-case branch reverted to notChosen on disk</summary> ``` × [en-US] a typed name that is no object keeps the chosen one and says it is kept, on Enter and on blur alike × [zh-CN] a typed name that is no object keeps the chosen one and says it is kept, on Enter and on blur alike Tests 2 failed | 16 passed (18) os-verify-lock: VERDICT command-exit 1 ``` Restored with `git checkout HEAD --`; `git status --porcelain` empty afterwards. </details> ## Acceptance notes - The line does not name the kept object; the box already shows it, as the card allows. - Not checked in a browser; the reach is the component test with the real studio catalogue. ## Verification All readings at head `afaa2ba2`. - `node scripts/pm/dispatch-gates.mjs --commands` derived 38 local commands; each ran with its exit code captured before any pipe; all 38 exit 0 (plus `pnpm check:changeset-fixed`, exit 0, for the roster under `.changeset`). `--ran` reconciliation: "38 derived, 38 run, 0 NOT-MEASURED, 0 UNRUN" (a derived zero, every line carrying its exit code). - `pnpm --dir ui exec vitest run scripts/`: 172 files passed, 2 skipped; 5159 tests passed. - `pnpm --filter @object-ui/i18n run type-check` and `pnpm --filter @object-ui/app-shell run type-check` (both `tsc --noEmit` and the `tsconfig.test.json` program): exit 0. - `node scripts/pm/overlap-check.mjs --branch=HEAD`: merges cleanly with `origin/main` and the four open PRs sharing the studio `en.ts` / `zh.ts`. - Not run locally, left to CI: the type-check lanes, the repo-wide `pnpm lint` and the full UI test run. --- _Generated by [Claude Code](https://claude.ai/code/session_01ADHkmSwS4mQyXWrddL4r6B)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01ADHkmSwS4mQyXWrddL4r6B <!-- signed: repo:objectstack#3 · os-steve · session_01ADHkmSwS4mQyXWrddL4r6B --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 7213177 commit eec2bc3

5 files changed

Lines changed: 70 additions & 32 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
'@object-ui/i18n': patch
4+
---
5+
6+
fix(app-shell): the object picker's refusal says the current object is kept when it is
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
In Studio's field inspector, a Lookup's *Related object* or a roll-up's *Child object* that already has a target keeps it when the typed text names no object, but the refusal line still read "No object chosen". The line now reads "“{text}” is not an object; the current object is kept." (zh: 「“{text}”不是对象,已保留当前对象。」) whenever a stored target was kept; an empty field keeps the "No object chosen" line. `@object-ui/i18n` adds the `engine.inspector.objectPicker.notAnObjectKept` studio string in en and zh.

‎ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectPicker.test.tsx‎

Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ vi.mock('../useMetadata', () => ({ useMetadataClient: () => h.client }));
4343

4444
import { ObjectPicker, type ObjectPickerProps } from './ObjectPicker';
4545
import { t } from '../i18n';
46+
import { loadStudioCatalogue } from '@object-ui/i18n/namespaces/studio';
47+
48+
// The refusal-line pins read the zh table, which the namespace loads lazily.
49+
await loadStudioCatalogue('zh');
4650

4751
// objectstack#28240 — editing a package, the picker reads `GET /api/v1/packages`
4852
// for the package's closure. No package is listed here, so nothing is narrowed
@@ -204,38 +208,50 @@ describe('ObjectPicker — objectsOnly: a door that takes no expression (objects
204208
expect(refusal()).toBeNull();
205209
});
206210

207-
it('Enter on a prefix that leaves several matches commits no object and says none is chosen', async () => {
208-
const { input, onCommit } = renderPicker({ objectsOnly: true });
209-
await openList(input);
210-
await userEvent.type(input, 'repairs');
211-
expect(offered()).toHaveLength(2);
212-
await userEvent.keyboard('{Enter}');
213-
// The value was empty and stays empty: nothing to commit.
214-
expect(onCommit).not.toHaveBeenCalled();
215-
expect(refusal()).toHaveTextContent(
216-
t('engine.inspector.objectPicker.notChosen', 'en-US').replace('{text}', 'repairs'),
217-
);
218-
});
211+
/** The refusal line `key` renders for `text` in `locale`. */
212+
const line = (key: string, locale: 'en-US' | 'zh-CN', text: string) =>
213+
t(`engine.inspector.objectPicker.${key}`, locale).replace('{text}', text);
219214

220-
it('a typed name that is no object keeps the chosen one and says it was refused, on Enter and on blur alike', async () => {
221-
const enter = renderPicker({ objectsOnly: true, value: 'showcase_account' });
222-
await openList(enter.input);
223-
await userEvent.clear(enter.input);
224-
await userEvent.type(enter.input, 'crm_custom_eval');
225-
await userEvent.keyboard('{Enter}');
226-
expect(enter.onCommit).not.toHaveBeenCalled();
227-
expect(enter.input).toHaveValue('showcase_account');
228-
expect(refusal()).not.toBeNull();
229-
cleanup();
215+
/** The refusal reads `key` in `locale`, and a zh line is its own text, not the en fallback. */
216+
const expectRefusal = (key: string, locale: 'en-US' | 'zh-CN', text: string) => {
217+
expect(refusal()).toHaveTextContent(line(key, locale, text));
218+
if (locale !== 'en-US') expect(refusal()).not.toHaveTextContent(line(key, 'en-US', text));
219+
};
230220

231-
const blur = renderPicker({ objectsOnly: true, value: 'showcase_account' });
232-
await openList(blur.input);
233-
await userEvent.clear(blur.input);
234-
await userEvent.type(blur.input, 'crm_custom_eval');
235-
await userEvent.tab();
236-
expect(blur.onCommit).not.toHaveBeenCalled();
237-
expect(refusal()).not.toBeNull();
238-
});
221+
for (const locale of ['en-US', 'zh-CN'] as const) {
222+
it(`[${locale}] Enter on a prefix that leaves several matches commits no object and says none is chosen`, async () => {
223+
const { input, onCommit } = renderPicker({ objectsOnly: true, locale });
224+
await openList(input);
225+
await userEvent.type(input, 'repairs');
226+
expect(offered()).toHaveLength(2);
227+
await userEvent.keyboard('{Enter}');
228+
// The value was empty and stays empty: nothing to commit.
229+
expect(onCommit).not.toHaveBeenCalled();
230+
expectRefusal('notChosen', locale, 'repairs');
231+
});
232+
233+
it(`[${locale}] a typed name that is no object keeps the chosen one and says it is kept, on Enter and on blur alike`, async () => {
234+
const enter = renderPicker({ objectsOnly: true, value: 'showcase_account', locale });
235+
await openList(enter.input);
236+
await userEvent.clear(enter.input);
237+
await userEvent.type(enter.input, 'crm_custom_eval');
238+
await userEvent.keyboard('{Enter}');
239+
expect(enter.onCommit).not.toHaveBeenCalled();
240+
expect(enter.input).toHaveValue('showcase_account');
241+
// The stored target stays, so the line says so -- never "no object chosen".
242+
expectRefusal('notAnObjectKept', locale, 'crm_custom_eval');
243+
expect(refusal()).not.toHaveTextContent(line('notChosen', locale, 'crm_custom_eval'));
244+
cleanup();
245+
246+
const blur = renderPicker({ objectsOnly: true, value: 'showcase_account', locale });
247+
await openList(blur.input);
248+
await userEvent.clear(blur.input);
249+
await userEvent.type(blur.input, 'crm_custom_eval');
250+
await userEvent.tab();
251+
expect(blur.onCommit).not.toHaveBeenCalled();
252+
expectRefusal('notAnObjectKept', locale, 'crm_custom_eval');
253+
});
254+
}
239255

240256
it('an input cleared on purpose still commits no object', async () => {
241257
const { input, onCommit } = renderPicker({ objectsOnly: true, value: 'showcase_account' });

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,8 @@ export function ObjectPicker({
324324
const [systemOpen, setSystemOpen] = React.useState(false);
325325
const [outsideOpen, setOutsideOpen] = React.useState(false);
326326
const [declaring, setDeclaring] = React.useState(false);
327-
// objectsOnly — the text last refused, so the picker can say no object is chosen.
327+
// objectsOnly — the text last refused, so the picker can say it is no object:
328+
// either no object is chosen, or the stored one is kept.
328329
const [refused, setRefused] = React.useState<string | null>(null);
329330

330331
const entries = catalog.status === 'loaded' ? catalog.data : NO_ENTRIES;
@@ -718,7 +719,15 @@ export function ObjectPicker({
718719
)}
719720
{refused !== null && (
720721
<p role="alert" data-object-refused="" className="text-[11px] leading-snug text-amber-600 dark:text-amber-300">
721-
{tFormat('engine.inspector.objectPicker.notChosen', locale, { text: refused })}
722+
{tFormat(
723+
// A stored target is kept (`commitTyped` restores it), so the line
724+
// must not say none is chosen; only an empty field has none.
725+
value
726+
? 'engine.inspector.objectPicker.notAnObjectKept'
727+
: 'engine.inspector.objectPicker.notChosen',
728+
locale,
729+
{ text: refused },
730+
)}
722731
</p>
723732
)}
724733
{declaring && closure && (

‎ui/packages/i18n/src/namespaces/studio/en.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,6 +1667,7 @@ const STUDIO_EN: Record<string, string> = {
16671667
// A picker that takes objects only (the new-automation trigger object).
16681668
'engine.inspector.objectPicker.noMatchObjectsOnly': 'No object matches. Choose one from the list.',
16691669
'engine.inspector.objectPicker.notChosen': 'No object chosen: \u201c{text}\u201d is not an object. Choose one from the list.',
1670+
'engine.inspector.objectPicker.notAnObjectKept': '\u201c{text}\u201d is not an object; the current object is kept.',
16701671
// objectstack#28240 — objects outside the edited package's closure.
16711672
'engine.inspector.objectPicker.groupOutside': 'Outside this package\u2019s dependencies',
16721673
'engine.inspector.objectPicker.showOutside': 'Show objects outside this package\u2019s dependencies ({count})',

‎ui/packages/i18n/src/namespaces/studio/zh.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,6 +1495,7 @@ const STUDIO_ZH: Record<string, string> = {
14951495
// 只接受对象的选择器(新建自动化的触发对象)。
14961496
'engine.inspector.objectPicker.noMatchObjectsOnly': '没有匹配的对象。请从列表中选择一个。',
14971497
'engine.inspector.objectPicker.notChosen': '未选择对象:\u201c{text}\u201d不是对象。请从列表中选择一个。',
1498+
'engine.inspector.objectPicker.notAnObjectKept': '\u201c{text}\u201d不是对象,已保留当前对象。',
14981499
// objectstack#28240 — objects outside the edited package's closure.
14991500
'engine.inspector.objectPicker.groupOutside': '不在本软件包的依赖范围内',
15001501
'engine.inspector.objectPicker.showOutside': '显示不在本软件包依赖范围内的对象({count})',

0 commit comments

Comments
 (0)