Skip to content

Commit 599a005

Browse files
feat(app-shell): Setup's and the Studio's navigation editor edits an entry's search keywords (#39236)
Fixes #39147 Clause-②: yes (widening) Metadata-protocol: none ## 维护者速读 - 管理员在设置的应用编辑器和工作室的导航检查器里,可以直接为每个导航项添加、修改、删除“搜索关键词”,以前只能改源码。 - 属于“设置专题”:让管理员在改名后仍能被用户用旧名称在控制台搜索中找到入口。 - 出错时最坏是关键词没存上或搜索找不到该入口,导航本身照常显示和打开;改动可直接撤回。 - 无 ## What changes - `AppNavInspector` (the navigation editor Setup's app editor and the Studio's nav inspector share) gains a **Search keywords** list field, offered wherever `navEntryOffersField(type, 'keywords')` offers it, so never on a separator. - Each edit is judged by the spec's own declaration (`ObjectNavItemSchema.shape.keywords.safeParse`) before it is written: a refused list (a keyword over 60 characters, a 21st keyword) is not written and the spec's message is shown beside the field (`role="alert"`). Removing the last keyword removes the key; nothing writes `[]`. An unchanged list writes nothing. - `NavigationEntryItem` (`@object-ui/types`) declares the optional `keywords` member, typed by reference from the spec's nav-item base (carried N2 of PR #39163), so the editor and the served entry shape agree. - Six `engine.inspector.appNav.keywords*` strings in the Studio namespace (`en`, `zh`). - Changeset `.changeset/39147-nav-editor-keywords.md` (patch: `@object-ui/app-shell`, `@object-ui/types`, `@object-ui/i18n`). Clause-② re-declared from the diff as `yes (widening)`: the published `@object-ui/types` interface gains a member. The claim carried `no`; the diff decides. No spec shape, no authorable key, no error code changes; `nav-target.ts` is untouched (its offer table and retype already carry `keywords`). Read first, by risk: 1. `ui/packages/app-shell/src/views/metadata-admin/inspectors/AppNavInspector.tsx` — `commitKeywords` (refusal, empty-list removal, no-op on equal list) and `navKeywordsRefusal`. 2. `ui/packages/app-shell/src/views/metadata-admin/inspectors/AppNavInspector.keywords-39147.test.tsx` — the acceptance pins. 3. `ui/packages/types/src/app.ts` — the mirror member. ## Tests `AppNavInspector.keywords-39147.test.tsx`, 9 tests: - add (saved entry carries it, parses with `NavigationItemSchema`, and `paletteNavEntryHit` finds the entry by the new word; non-vacuity: not found before the edit), edit, remove (last removal drops the key), unchanged writes nothing; - 61-character keyword and 21st keyword refused with the spec's own first issue message, nothing written; CONTROL: 60 characters and a 20th pass; - a separator is offered no field; a retype to a separator drops `keywords`, a retype to `dashboard` keeps them; - a refused draft stays with its own entry: entry A (no keywords) gets `pipeline` plus a refused 61-character word; on switching to entry B (no keywords) the field is empty, shows no alert and nothing is written to B; the next edit on B writes only B's own word. The field is keyed per entry (`key={selection.id}`, as in `FlowEdgeInspector`). This is S1 of contract review on `355e2b57ac`, closed by the delta review on `d3fac7a692`. <details><summary>Local test readings at 355e2b5 (the final head; test inputs unchanged since 6ec4983)</summary> - `cd ui && pnpm exec vitest run --reporter=verbose packages/app-shell/src/views/metadata-admin/inspectors/AppNavInspector.keywords-39147.test.tsx`: `Tests 8 passed (8)`. - `cd ui && pnpm exec vitest run packages/types/ packages/i18n/ packages/app-shell/src/views/metadata-admin/inspectors/AppNav packages/app-shell/src/chrome/paletteNav`: `Test Files 507 passed (507)`, `Tests 12437 passed | 13 skipped (12450)`. - `pnpm --filter @object-ui/types --filter @object-ui/i18n --filter @object-ui/app-shell run type-check`: all three `Done`, exit 0 (after building the app-shell dependency closure: 72 of 72 tasks). - Whole `@object-ui/app-shell` suite: NOT MEASURED locally (stopped after 80 minutes on two workers); CI `Test Core` runs it. Ablation (one-off, restored, `git diff HEAD` empty after each, via `scripts/ablation-replace.mjs`): 1. `navKeywordsRefusal` made to `return null` (the spec check removed): red `refuses a 61-character keyword with the spec's message and writes nothing (CONTROL: 60 pass)` and `refuses a 21st keyword with the spec's message and writes nothing (CONTROL: a 20th passes)`; 6 others green. 2. The field's `navEntryOffersField(entryType, 'keywords')` guard made `true`: red `a separator is offered no keywords field`; 7 others green. </details> <details><summary>Fix round at d3fac7a (S1 and nit N1 of the contract review)</summary> - `cd ui && pnpm exec vitest run --maxWorkers=2 packages/app-shell/src/views/metadata-admin/inspectors/AppNavInspector.keywords-39147.test.tsx`: `Tests 9 passed (9)`. - Ablation 3: `key={selection.id}` removed: red `switching from an entry with a refused draft to another keyword-less entry shows an empty field and writes nothing to it` (A's two draft rows shown on B); 8 others green. Restored, blob equal to HEAD. - app-shell type-check NOT MEASURED locally (worktree without the built ui closure); green at 355e2b5, and the only source change since is one JSX `key` prop and a jsdoc sentence. CI `Type Check UI` is green at d3fac7a. - `dispatch-gates --ran` at d3fac7a: 38 run, 0 NOT-MEASURED. </details> ## Acceptance notes - The claim's `Clause-②: no` is re-declared `yes (widening)` from the diff (published type gains a member). - Merged `origin/main` into the branch (no conflicts), including PR #39144, which also edits `studio/en.ts` and `studio/zh.ts`; `overlap-check.mjs` reads clean at the final head. - `check:test-source-alias` first failed on the new test (it reaches a dynamic `import('@objectstack/lint')` through the condition builder). Fixed with the repo's convention: a module-top side-effect import in the test file. - The whole `@object-ui/app-shell` suite on two local workers did not finish in 80 minutes and was stopped: NOT MEASURED locally, left to CI's sharded `Test Core`. Locally measured instead: `types`, `i18n`, every `AppNavInspector*` file and the palette keyword tests. ## Verification Two-minute check: `cd ui && pnpm exec vitest run packages/app-shell/src/views/metadata-admin/inspectors/AppNavInspector.keywords-39147.test.tsx` — expect `Tests 9 passed (9)`. In a running console (not browser-verified in this run): open an app in Setup's app editor, select a page entry in its navigation, and the **Search keywords** field lists, adds and removes words; select a separator and no such field shows. <details><summary>Derived gates (dispatch-gates --commands, 38 commands) at 355e2b5 and d3fac7a</summary> - `dispatch-gates --ran`: `38 derived famil(ies) accounted for — 38 run, 0 NOT-MEASURED (a DERIVED zero — all 38 recorded an exit code and none of them is 3)`. - All 38 exit 0. `check:test-source-alias` was red on the first run and is green after the test fix; `check:query-options-erasure` hit a 300s local timeout once and passed on re-run (exit 0); `check:type-check-debt` first missed the verify lock (exit 3, NOT MEASURED) and passed on re-run. - The three lock-heavy families (`pnpm --dir ui exec vitest run scripts/`, `check:type-check-coverage`, `check:type-check-debt`) ran on 94f7cd5 / 6ec4983; the later main merge changed none of their inputs. - Also run: `pnpm check:changeset-fixed` (roster under `.changeset/`), exit 0. - CI-only families (type-check lanes, roster and wide-population families, `pnpm lint`) are left to this PR's check-runs. </details> 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01QSeKYnrQ7UMtHofKQVjcH2 <!-- signed: repo:objectstack@os-justin · os-justin · session_01QSeKYnrQ7UMtHofKQVjcH2 --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 3818f27 commit 599a005

6 files changed

Lines changed: 357 additions & 1 deletion

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
'@object-ui/types': patch
4+
'@object-ui/i18n': patch
5+
---
6+
7+
feat(console): Setup's and the Studio's navigation editor edit an entry's search keywords
8+
9+
Clause-②: yes (widening)
10+
Metadata-protocol: none
11+
12+
A navigation entry's `keywords` (the other words a person may type in the console's search to find it, such as its old name after a rename) can now be set in the navigation editor that Setup's app editor and the Studio's nav inspector share, instead of only in source.
13+
14+
- The new **Search keywords** field adds, edits and removes words on every entry type except a separator. Removing the last word removes the key; nothing writes an empty list.
15+
- Each edit is checked against the spec's own `keywords` rule before it is written: a keyword over the length limit, or one keyword too many, is not written, and the spec's message is shown beside the field.
16+
- `NavigationEntryItem` (`@object-ui/types`) declares the optional `keywords` member, typed from the spec's nav-item base, so the editor and the served entry shape agree.
17+
- New strings `engine.inspector.appNav.keywords`, `keywordsHint`, `keywordsAdd`, `keywordsItem`, `keywordsRemove` and `keywordsEmpty` in the Studio namespace (`en`, `zh`).
Lines changed: 246 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,246 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* objectstack#39147 — Setup's app editor and the Studio's nav inspector (both
5+
* `AppNavInspector`) edit an entry's search keywords.
6+
*
7+
* A navigation entry declares `keywords` (objectstack#39052) and the command
8+
* palette finds the entry by them (objectstack#39055), but no editor offered a
9+
* field for them: an admin could set them only in source.
10+
*
11+
* - an admin adds, edits and removes keywords; the saved entry carries them,
12+
* parses, and the palette's matcher finds it by the new word;
13+
* - emptying the list removes the key, never writes `[]`;
14+
* - a 61-character keyword and a 21st keyword are refused with the spec's own
15+
* message, and nothing is written (CONTROL: 60 characters and a 20th pass);
16+
* - a separator is offered no keywords field, and a retype to a separator
17+
* drops them while a retype to another entry type keeps them.
18+
*/
19+
20+
import * as React from 'react';
21+
import { describe, it, expect, vi, afterEach } from 'vitest';
22+
import { render, screen, cleanup, fireEvent } from '@testing-library/react';
23+
import { MetadataCtx } from '@object-ui/react';
24+
import { NavigationItemSchema } from '@objectstack/spec/ui';
25+
26+
// ONE client for the whole file, as the real hook hands out (see
27+
// `AppNavInspector.labelInherits-11196.test.tsx`).
28+
const client = vi.hoisted(() => ({ list: async () => [] }));
29+
30+
vi.mock('../useMetadata', async (importOriginal) => ({
31+
...(await importOriginal<Record<string, unknown>>()),
32+
useMetadataClient: () => client,
33+
}));
34+
35+
import { AppNavInspector } from './AppNavInspector';
36+
import { navEntryOffersField, retypedNavEntry } from './nav-target';
37+
import { navEntryKeywords, paletteNavEntryHit } from '../../../chrome/paletteNavKeywords';
38+
import { t } from '../i18n';
39+
// Paid at collection, not inside a clocked case (check:test-source-alias).
40+
import '@objectstack/lint';
41+
42+
afterEach(cleanup);
43+
44+
const METADATA = {
45+
apps: [],
46+
objects: [{ name: 'lead', label: 'Leads' }],
47+
dashboards: [],
48+
reports: [],
49+
pages: [],
50+
loading: false,
51+
error: null,
52+
refresh: async () => {},
53+
invalidate: () => {},
54+
ensureType: async () => [],
55+
getItem: async () => null,
56+
getItemsByType: () => [],
57+
getTypeStatus: () => 'ready' as const,
58+
};
59+
60+
type Entry = Record<string, unknown>;
61+
type NavPatch = { navigation: Entry[] };
62+
63+
const L = 'en-US';
64+
const PAGE_ENTRY: Entry = { id: 'nav_home', type: 'page', pageName: 'home', label: 'Home' };
65+
const SEPARATOR: Entry = { id: 'nav_sep', type: 'separator' };
66+
67+
function inspect(navigation: Entry[], index = 0) {
68+
const onPatch = vi.fn<(patch: NavPatch) => void>();
69+
render(
70+
<MetadataCtx.Provider value={METADATA as never}>
71+
<AppNavInspector
72+
type="app"
73+
name="crm"
74+
selection={{ kind: 'nav', id: `navigation[${index}]` }}
75+
draft={{ name: 'crm', navigation }}
76+
onPatch={onPatch as never}
77+
onClearSelection={() => {}}
78+
locale={L}
79+
readOnly={false}
80+
/>
81+
</MetadataCtx.Provider>,
82+
);
83+
return onPatch;
84+
}
85+
86+
/** What the save meets: `undefined`-valued keys erased, as JSON does. */
87+
const wire = (entry: Entry) => JSON.parse(JSON.stringify(entry)) as Entry;
88+
89+
function issuesOf(entry: Entry) {
90+
const r = NavigationItemSchema.safeParse(wire(entry));
91+
return r.success ? [] : r.error.issues;
92+
}
93+
94+
/** The keyword row inputs, in order. */
95+
const rows = () => screen.queryAllByPlaceholderText(t('engine.inspector.appNav.keywordsItem', L)) as HTMLInputElement[];
96+
97+
function typeInto(input: HTMLInputElement, value: string) {
98+
fireEvent.change(input, { target: { value } });
99+
fireEvent.blur(input);
100+
}
101+
102+
function addKeyword(value: string) {
103+
fireEvent.click(screen.getByRole('button', { name: t('engine.inspector.appNav.keywordsAdd', L) }));
104+
const all = rows();
105+
typeInto(all[all.length - 1], value);
106+
}
107+
108+
/** The palette's own matcher, against the saved entry: its label is its term. */
109+
const paletteHit = (query: string, entry: Entry) =>
110+
paletteNavEntryHit(query, [String(entry.label ?? '')], navEntryKeywords(entry), []);
111+
112+
describe('objectstack#39147 — the nav editor edits an entry\'s search keywords', () => {
113+
it('an admin adds a keyword: the saved entry carries it, parses, and the palette finds the entry by it', () => {
114+
const onPatch = inspect([PAGE_ENTRY]);
115+
expect(rows()).toEqual([]);
116+
expect(screen.getByText(t('engine.inspector.appNav.keywordsEmpty', L))).toBeInTheDocument();
117+
addKeyword('pipeline');
118+
expect(onPatch).toHaveBeenCalledTimes(1);
119+
const saved = onPatch.mock.calls[0][0].navigation[0];
120+
expect(saved).toEqual({ ...PAGE_ENTRY, keywords: ['pipeline'] });
121+
expect(issuesOf(saved)).toEqual([]);
122+
// NON-VACUITY: before the edit the palette does not find it by that word.
123+
expect(paletteHit('pipel', PAGE_ENTRY)).toEqual({ found: false });
124+
expect(paletteHit('pipel', saved)).toEqual({ found: true, keyword: 'pipeline' });
125+
});
126+
127+
it('an admin edits a keyword: the saved entry carries the new word', () => {
128+
const entry = { ...PAGE_ENTRY, keywords: ['old name', 'deals'] };
129+
const onPatch = inspect([entry]);
130+
expect(rows().map((r) => r.value)).toEqual(['old name', 'deals']);
131+
typeInto(rows()[0], 'opportunities');
132+
expect(onPatch).toHaveBeenCalledTimes(1);
133+
const saved = onPatch.mock.calls[0][0].navigation[0];
134+
expect(saved).toEqual({ ...entry, keywords: ['opportunities', 'deals'] });
135+
expect(issuesOf(saved)).toEqual([]);
136+
});
137+
138+
it('an admin removes a keyword; removing the last one removes the key, never writes []', () => {
139+
const entry = { ...PAGE_ENTRY, keywords: ['deals'] };
140+
const onPatch = inspect([entry]);
141+
fireEvent.click(screen.getByRole('button', { name: t('engine.inspector.appNav.keywordsRemove', L) }));
142+
expect(onPatch).toHaveBeenCalledTimes(1);
143+
const saved = onPatch.mock.calls[0][0].navigation[0];
144+
expect('keywords' in saved).toBe(false);
145+
expect(saved).toEqual(PAGE_ENTRY);
146+
});
147+
148+
it('leaving a keyword unchanged writes nothing', () => {
149+
const onPatch = inspect([{ ...PAGE_ENTRY, keywords: ['deals'] }]);
150+
typeInto(rows()[0], 'deals');
151+
expect(onPatch).not.toHaveBeenCalled();
152+
});
153+
154+
it('refuses a 61-character keyword with the spec\'s message and writes nothing (CONTROL: 60 pass)', () => {
155+
const tooLong = 'k'.repeat(61);
156+
const specIssues = issuesOf({ ...PAGE_ENTRY, keywords: [tooLong] });
157+
expect(specIssues.length).toBeGreaterThan(0);
158+
const onPatch = inspect([PAGE_ENTRY]);
159+
addKeyword(tooLong);
160+
expect(onPatch).not.toHaveBeenCalled();
161+
expect(screen.getByRole('alert')).toHaveTextContent(specIssues[0].message);
162+
163+
cleanup();
164+
const control = inspect([PAGE_ENTRY]);
165+
addKeyword('k'.repeat(60));
166+
expect(control).toHaveBeenCalledTimes(1);
167+
expect(issuesOf(control.mock.calls[0][0].navigation[0])).toEqual([]);
168+
expect(screen.queryByRole('alert')).toBeNull();
169+
});
170+
171+
it('refuses a 21st keyword with the spec\'s message and writes nothing (CONTROL: a 20th passes)', () => {
172+
const twenty = Array.from({ length: 20 }, (_, i) => `word${i}`);
173+
const specIssues = issuesOf({ ...PAGE_ENTRY, keywords: [...twenty, 'one more'] });
174+
expect(specIssues.length).toBeGreaterThan(0);
175+
const onPatch = inspect([{ ...PAGE_ENTRY, keywords: twenty }]);
176+
addKeyword('one more');
177+
expect(onPatch).not.toHaveBeenCalled();
178+
expect(screen.getByRole('alert')).toHaveTextContent(specIssues[0].message);
179+
180+
cleanup();
181+
const nineteen = twenty.slice(0, 19);
182+
const control = inspect([{ ...PAGE_ENTRY, keywords: nineteen }]);
183+
addKeyword('word19');
184+
expect(control).toHaveBeenCalledTimes(1);
185+
const saved = control.mock.calls[0][0].navigation[0];
186+
expect(saved.keywords).toEqual(twenty);
187+
expect(issuesOf(saved)).toEqual([]);
188+
});
189+
190+
it('a separator is offered no keywords field', () => {
191+
expect(navEntryOffersField('separator', 'keywords')).toBe(false);
192+
inspect([PAGE_ENTRY, SEPARATOR], 1);
193+
expect(screen.queryByText(t('engine.inspector.appNav.keywords', L))).toBeNull();
194+
expect(screen.queryByRole('button', { name: t('engine.inspector.appNav.keywordsAdd', L) })).toBeNull();
195+
});
196+
197+
it('a retype to a separator drops the keywords; a retype to another entry type keeps them', () => {
198+
const entry = { ...PAGE_ENTRY, keywords: ['deals'] };
199+
const separator = retypedNavEntry(entry, 'separator');
200+
expect('keywords' in separator).toBe(false);
201+
expect(issuesOf(separator)).toEqual([]);
202+
expect(retypedNavEntry(entry, 'dashboard').keywords).toEqual(['deals']);
203+
});
204+
});
205+
206+
describe('objectstack#39147 — a refused keywords draft stays with its own entry', () => {
207+
it('switching from an entry with a refused draft to another keyword-less entry shows an empty field and writes nothing to it', () => {
208+
// Both entries declare no `keywords`, so the field's `value` is
209+
// `undefined` for each: only a fresh field per entry resets its rows.
210+
const second: Entry = { id: 'nav_leads', type: 'page', pageName: 'leads', label: 'Leads' };
211+
const navigation = [PAGE_ENTRY, second];
212+
const onPatch = vi.fn<(patch: NavPatch) => void>();
213+
const view = (index: number) => (
214+
<MetadataCtx.Provider value={METADATA as never}>
215+
<AppNavInspector
216+
type="app"
217+
name="crm"
218+
selection={{ kind: 'nav', id: `navigation[${index}]` }}
219+
draft={{ name: 'crm', navigation }}
220+
onPatch={onPatch as never}
221+
onClearSelection={() => {}}
222+
locale={L}
223+
readOnly={false}
224+
/>
225+
</MetadataCtx.Provider>
226+
);
227+
const { rerender } = render(view(0));
228+
addKeyword('pipeline');
229+
addKeyword('k'.repeat(61));
230+
expect(screen.getByRole('alert')).toBeInTheDocument();
231+
const writesOnA = onPatch.mock.calls.length;
232+
233+
rerender(view(1));
234+
expect(rows()).toEqual([]);
235+
expect(screen.getByText(t('engine.inspector.appNav.keywordsEmpty', L))).toBeInTheDocument();
236+
expect(screen.queryByRole('alert')).toBeNull();
237+
expect(onPatch).toHaveBeenCalledTimes(writesOnA);
238+
239+
// The next edit on B writes B's own word, and nothing carried from A.
240+
addKeyword('leads');
241+
expect(onPatch).toHaveBeenCalledTimes(writesOnA + 1);
242+
const saved = onPatch.mock.calls[writesOnA][0].navigation[1];
243+
expect(saved).toEqual({ ...second, keywords: ['leads'] });
244+
expect(issuesOf(saved)).toEqual([]);
245+
});
246+
});

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

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,19 @@
3535
* Studio's nav inspector reads too. A separator declares neither a `label` nor
3636
* an `icon`, so it is offered neither field: a value typed there used to write
3737
* a key the save refused (`unrecognized_keys`).
38+
*
39+
* The entry's search keywords (objectstack#39147): the words a person may type
40+
* in the console's search to find the entry (`keywords`, objectstack#39052),
41+
* offered wherever `navEntryOffersField` offers them, so never on a separator.
42+
* Each edit is judged by the spec's own `keywords` declaration before it is
43+
* written: a list the schema refuses is not written, and the schema's message
44+
* says why. An empty list removes the key, never writes `[]`.
3845
*/
3946

4047
import * as React from 'react';
4148
import { resolveHref } from '@object-ui/layout';
4249
import type { NavigationItem } from '@object-ui/types';
43-
import type { I18nLabel } from '@objectstack/spec/ui';
50+
import { ObjectNavItemSchema, type I18nLabel } from '@objectstack/spec/ui';
4451
import { Label } from '@object-ui/components';
4552
import type { MetadataInspectorProps } from '../inspector-registry.js';
4653
import { t } from '../i18n.js';
@@ -65,6 +72,7 @@ import {
6572
} from './_shared.js';
6673
import { InspectorComboField } from './InspectorComboField.js';
6774
import { FiltersEditor } from './NavFiltersEditor.js';
75+
import { FlowStringListField } from './FlowStringListField.js';
6876
import { IconPickerWidget } from '../widgets.js';
6977
import {
7078
NAV_ITEM_TYPES,
@@ -214,6 +222,18 @@ function useMetadataOptions(
214222
return state;
215223
}
216224

225+
/**
226+
* Why the spec refuses `keywords` as an entry's search keywords, or `null` when
227+
* it takes them (objectstack#39147). Judged by the spec's own declaration, the
228+
* shared nav-item base member every entry but a separator spreads, so the
229+
* editor's limits and messages are the save's, never a restated copy. Read at
230+
* call time: the member is a lazy schema.
231+
*/
232+
export function navKeywordsRefusal(keywords: readonly string[]): string | null {
233+
const parsed = ObjectNavItemSchema.shape.keywords.safeParse(keywords);
234+
return parsed.success ? null : (parsed.error.issues[0]?.message ?? parsed.error.message);
235+
}
236+
217237
/** Preview template context that keeps template vars VISIBLE in the href. */
218238
const PREVIEW_CTX = {
219239
currentUserId: '{current_user_id}',
@@ -237,6 +257,9 @@ export function AppNavInspector({ selection, draft, name, onPatch, onClearSelect
237257
// The console's own resolver for what a label-less item inherits.
238258
const targetLabel = useNavTargetLabel();
239259
const iconFieldId = React.useId();
260+
// The keywords the spec refused, kept per entry so another entry's field
261+
// never shows this one's message (objectstack#39147).
262+
const [keywordsRefusal, setKeywordsRefusal] = React.useState<{ id: string; message: string } | null>(null);
240263
// Views are named `<object>.<key>` (MetadataProvider) — scope the picker
241264
// to the bound object instead of offering the whole workspace's views.
242265
const viewOptions = React.useMemo(
@@ -301,6 +324,26 @@ export function AppNavInspector({ selection, draft, name, onPatch, onClearSelect
301324
else patch({ label: next });
302325
};
303326

327+
/**
328+
* The Keywords field's edit (objectstack#39147). An empty list removes the
329+
* key, never writes `[]`; a list the spec refuses is not written, and its
330+
* message stays beside the field until an edit the spec takes. A list equal
331+
* to the stored one writes nothing. The list field trims each row and drops
332+
* blank ones before this runs, so the spec's untrimmed-word refusal never
333+
* shows in this editor.
334+
*/
335+
const commitKeywords = (list: string[] | undefined) => {
336+
const refusal = list ? navKeywordsRefusal(list) : null;
337+
if (refusal) {
338+
setKeywordsRefusal({ id: selection.id, message: refusal });
339+
return;
340+
}
341+
setKeywordsRefusal(null);
342+
if (JSON.stringify(list ?? []) === JSON.stringify(Array.isArray(node.keywords) ? node.keywords : [])) return;
343+
if (list) patch({ keywords: list });
344+
else patch({}, ['keywords']);
345+
};
346+
304347
const switchType = (nextType: NavItemType) => {
305348
const targetKey = NAV_TYPE_TARGETS[nextType].targetKey;
306349
const keep = nextType === 'object' ? OBJECT_MODE_FIELDS.default : targetKey ? [targetKey] : [];
@@ -380,6 +423,30 @@ export function AppNavInspector({ selection, draft, name, onPatch, onClearSelect
380423
/>
381424
</div>
382425
)}
426+
{navEntryOffersField(entryType, 'keywords') && (
427+
<div className="space-y-1" data-testid="nav-keywords">
428+
<FlowStringListField
429+
// A fresh field per entry: its rows are that entry's, so a refused
430+
// draft never carries over to the next entry selected.
431+
key={selection.id}
432+
label={t('engine.inspector.appNav.keywords', locale)}
433+
value={node.keywords}
434+
onCommit={commitKeywords}
435+
disabled={readOnly}
436+
addLabel={t('engine.inspector.appNav.keywordsAdd', locale)}
437+
itemLabel={t('engine.inspector.appNav.keywordsItem', locale)}
438+
removeLabel={t('engine.inspector.appNav.keywordsRemove', locale)}
439+
emptyLabel={t('engine.inspector.appNav.keywordsEmpty', locale)}
440+
/>
441+
{keywordsRefusal?.id === selection.id ? (
442+
<p role="alert" className="text-[11px] text-destructive" data-testid="nav-keywords-refusal">
443+
{keywordsRefusal.message}
444+
</p>
445+
) : (
446+
<p className="text-[11px] text-muted-foreground">{t('engine.inspector.appNav.keywordsHint', locale)}</p>
447+
)}
448+
</div>
449+
)}
383450

384451
<InspectorSelectField
385452
label={t('engine.inspector.appNav.typeField', locale)}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,14 @@ const STUDIO_EN: Record<string, string> = {
834834
'engine.inspector.appNav.orderHint': 'Entries with a lower number come first in the menu; an entry without one counts as 0.',
835835
'engine.inspector.appNav.visibleHint': 'Shows this entry only to people for whom the condition is true. Leave it empty to show it to everyone.',
836836
'engine.inspector.appNav.visibleNotSaved': 'Not saved yet: the entry keeps its previous condition until this one has no errors.',
837+
// objectstack#39147 — the nav editor's search keywords field (the entry's
838+
// `keywords`); the spec's own message explains a refused list.
839+
'engine.inspector.appNav.keywords': 'Search keywords',
840+
'engine.inspector.appNav.keywordsHint': 'Other words people may type in search to find this entry, such as its old name after a rename.',
841+
'engine.inspector.appNav.keywordsAdd': 'Add keyword',
842+
'engine.inspector.appNav.keywordsItem': 'Word or phrase',
843+
'engine.inspector.appNav.keywordsRemove': 'Remove keyword',
844+
'engine.inspector.appNav.keywordsEmpty': 'No keywords',
837845
// Page block inspector
838846
'engine.inspector.pageBlock.kind': 'Block',
839847
'engine.inspector.pageBlock.close': 'Close block',

0 commit comments

Comments
 (0)