Skip to content
Merged
8 changes: 8 additions & 0 deletions .changeset/39210-menu-clear-label-keeps-keywords.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@object-ui/app-shell": patch
---

Clause-②: no
Metadata-protocol: none

Clearing an entry's translated name in the design mode's menu now keeps that entry's translated search keywords in the language's menu translation. Before, the save deleted the entry's whole translation node, so the keywords written for that language went with the name. A node left with no keywords is still deleted (objectstack#39210).
19 changes: 19 additions & 0 deletions .changeset/39210-nav-keywords-never-empty.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
'@objectstack/spec': minor
'@object-ui/types': patch
---

feat(spec)!: a navigation `keywords` list is never empty, on the nav item and on the translation node

Clause-②: yes (narrowing)
Metadata-protocol: narrowed

<!-- adr-0087: registered nav-keywords-empty-list-refused -->

**BREAKING** for metadata that writes an empty list: `keywords: []` on a navigation item, or on a translation bundle's navigation node `apps.APP.navigation.ID`, is now refused at every door where 19.0.0-next.4 accepted it. Fix: leave the key out. An empty list never matched a search and never translated anything, and no writer in the platform produces one: the nav editor and the design-mode menu omit the key instead.

Narrowed: each `keywords` array now takes at least 1 and at most 20 words, at the nav item and at the translation node, with a message that says to leave the key out. A translation node carrying only `keywords: []` was accepted as a node that has keywords; it is now refused like a node with neither `label` nor `keywords`.

The same node shape is also part of `PlatformTranslationData` and of `ServedTranslationData`, the body of `GET /i18n/translations/:locale`. Both took the 19.0.0-next.4 widening (a node may carry `keywords` without `label`) and now take this narrowing too.

`@object-ui/types` mirrors the rule on its navigation item schema, so `objectui validate` refuses what the platform's save door refuses.
90 changes: 45 additions & 45 deletions content/docs/references/ui/app.mdx

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

import type { SemanticMigration } from '../../types.js';

// [#39210] A narrowing of one value, not of a key: an empty `keywords` list on
// a navigation item, or on a translation bundle's navigation node, is refused
// where 19.0.0-next.4 accepted it. The key stays; only `[]` goes. No stored
// row has a meaning to carry over (an empty list matched no search and
// translated nothing), so no D2 conversion: the fix is to drop the key.
export const entry: SemanticMigration = {
id: 'nav-keywords-empty-list-refused',
surface:
'An empty keywords list (keywords: []) on a navigation item in an app\'s navigation, or on a translation '
+ 'bundle\'s navigation node apps.APP.navigation.ID (the file bundle, a registered translation item, the '
+ 'platform translations and the served GET /i18n/translations/:locale body). Each keywords array now takes '
+ 'at least 1 and at most 20 words',
replacement:
'Leave the keywords key out. A translation node whose only key was keywords: [] translates nothing: delete '
+ 'the node, or give it its translated label.',
reason:
'An empty list matched no search and translated nothing, yet a translation node carrying only keywords: [] '
+ 'passed the rule that a node owes a label or keywords. Refusing it keeps that rule true and keeps the nav '
+ 'item and the translation node to one accept set. No writer in the platform produces an empty list.',
acceptanceCriteria:
'AppSchema refuses a navigation item with keywords: [] and TranslationDataSchema refuses '
+ 'apps.APP.navigation.ID with keywords: [], each with a message that says to leave the key out; the same '
+ 'documents without the key, or with one keyword, parse.',
relevantWhen: { kind: 'stack-declares', keys: ['apps', 'translations'] },
};
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ const SITES: ReadonlyArray<{ site: string; stack: Record<string, unknown>; entri
entries: ['action-locations-page-parts-retired', 'object-grid-single-click-edit-retired', 'ui-action-type-ask-ai-retired', 'view-bulk-actions-declared-on-the-action', 'cel-list-equality-refused'],
},
{ site: 'dashboards[] (a header action)', stack: { dashboards: [{ name: 'd' }] }, entries: ['ui-action-type-ask-ai-retired', 'publish-refuses-views-and-dashboards-that-save-and-do-not-work'] },
{ site: 'apps[]', stack: { apps: [{ name: 'a' }] }, entries: ['publish-refuses-views-and-dashboards-that-save-and-do-not-work'] },
{ site: 'apps[]', stack: { apps: [{ name: 'a' }] }, entries: ['nav-keywords-empty-list-refused', 'publish-refuses-views-and-dashboards-that-save-and-do-not-work'] },
{
site: 'hooks[]',
stack: { hooks: [{ name: 'h' }] },
Expand Down Expand Up @@ -418,7 +418,7 @@ const SITES: ReadonlyArray<{ site: string; stack: Record<string, unknown>; entri
{
site: 'translations[]',
stack: { translations: [{ en: {} }] },
entries: ['translation-form-tails-move-to-forms', 'translation-related-list-key-under-arrangement-refused', 'validation-rule-message-template-holes'],
entries: ['nav-keywords-empty-list-refused', 'translation-form-tails-move-to-forms', 'translation-related-list-key-under-arrangement-refused', 'validation-rule-message-template-holes'],
},
{ site: 'mappings[]', stack: { mappings: [{ name: 'm' }] }, entries: ['incremental-source-delete-policy-stated'] },
{ site: 'books[]', stack: { books: [{ name: 'b' }] }, entries: ['book-audience-two-gates-and-catch-all-claim-refused'] },
Expand Down
1 change: 1 addition & 0 deletions packages/spec/src/migrations/semantic-relevance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ const EXPECTED_RELEVANCE: Readonly<Record<string, readonly string[]>> = {
'19:lookup-filter-record-path-structured-refused': ['objects', 'objectExtensions'],
'19:lowered-hook-and-action-bodies-capabilities-judged': ['hooks', 'actions', 'objects'],
'19:master-detail-related-list-tab-by-default': ['objects', 'objectExtensions'],
'19:nav-keywords-empty-list-refused': ['apps', 'translations'],
'19:navigation-mode-record-open-deprecated': ['views', 'viewItems', 'objects'],
'19:object-extension-place-and-cross-package-lists': ['objects', 'objectExtensions'],
'19:object-grid-single-click-edit-retired': ['pages'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
* (this file is compiled by the package's test type-check);
* - `defineStack` (strict) accepts the module stack carrying it;
* - the bare schema parse — the `os validate` door's — accepts it;
* - CONTROL: a navigation entry still owes its own `label`, at both layers;
* - CONTROL: a navigation entry with neither `label` nor `keywords` is refused
* at the schema (the type takes it, since #39146 made `label` optional so a
* node may carry only this locale's `keywords`);
* - CONTROL: an app entry that does author `label` keeps it.
*
* The `os validate` exit-code pin lives in
Expand Down
9 changes: 6 additions & 3 deletions packages/spec/src/system/translation.zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1391,7 +1391,7 @@ const appTranslationDataShape = () => ({
* half of the nav item's `keywords`, keyed by the same entry id as
* `label`. The accept set is the nav item's (ui/app.zod.ts
* `navKeywordsSchema`: each trimmed, non-empty, at most 60 characters,
* at most 20), restated here because this module does not import the
* at least 1 and at most 20), restated here because this module does not import the
* app schema; `app-nav-keywords.test.ts` holds both doors to the same
* verdicts.
*
Expand All @@ -1413,11 +1413,14 @@ const appTranslationDataShape = () => ({
+ 'leading or trailing whitespace, no line break. The schema refuses rather than trims it, so what is '
+ 'stored is what was written.',
}),
).max(20, { error: () => 'an entry takes at most 20 keywords — keep the words people actually use for it.' })
).min(1, {
error: () => 'a navigation entry\'s `keywords` list is never empty — give at least one word a person would '
+ 'type to find the entry in this locale, or leave the key out.',
}).max(20, { error: () => 'an entry takes at most 20 keywords — keep the words people actually use for it.' })
.optional().describe(
'Search aliases for this navigation entry in this locale: the words a person '
+ 'may type to find it, such as its old name after a rename. Each trimmed, non-empty, at most 60 '
+ 'characters; at most 20. They add to the entry\'s own keywords, never replace them; the command '
+ 'characters; at least 1, at most 20. They add to the entry\'s own keywords, never replace them; the command '
+ 'palette matches both.',
),
}).refine(requiredOneOf(['label', 'keywords']), {
Expand Down
4 changes: 2 additions & 2 deletions packages/spec/src/ui/app-nav-keywords.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ const BRANCHES: Array<[string, Branch, Record<string, unknown>]> = [
const BASE = { id: 'nav_position_members', label: 'Position Members' };
const KEYWORDS = ['Position Holders', 'Assignments'];

/** Refused at both doors: blank, untrimmed, a line break, over 60 characters, over 20 entries, not strings. */
/** Refused at both doors: an empty list (#39210), blank, untrimmed, a line break, over 60 characters, over 20 entries, not strings. */
const REFUSED_KEYWORDS: unknown[] = [
[''], ['ok', ''], [' '], [' Holders'], ['Holders '], ['Position\nHolders'], ['x'.repeat(61)],
[], [''], ['ok', ''], [' '], [' Holders'], ['Holders '], ['Position\nHolders'], ['x'.repeat(61)],
Array.from({ length: 21 }, (_, i) => `word ${i}`), [42], 'Position Holders',
];
/** Accepted at both doors: an inner space, CJK, and the two bounds exactly. */
Expand Down
9 changes: 6 additions & 3 deletions packages/spec/src/ui/app.zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ const NAV_GROUP_ALIASES_GUIDANCE =
/**
* The accept set of one search alias, shared by a nav item's `keywords` and a
* translation bundle node's `keywords` (`system/translation.zod.ts` restates
* the same three numbers and rule; `app-nav-keywords.test.ts` holds the two
* the same numbers and rule; `app-nav-keywords.test.ts` holds the two
* doors to the same verdicts). The rule is the dataset synonym's (ADR-0149 D1),
* the repo's precedent for match-input words: one word or short phrase as a
* person types it, refused rather than trimmed, so what is stored is what was
Expand All @@ -205,14 +205,17 @@ const NAV_KEYWORD_NOT_TRIMMED =
'a navigation keyword is one word or phrase as a person types it in search: not empty, no leading or '
+ 'trailing whitespace, no line break. The schema refuses rather than trims it, so what is stored is '
+ 'what was written.';
const NAV_KEYWORDS_EMPTY =
'a navigation entry\'s `keywords` list is never empty — give at least one word a person would type to '
+ 'find the entry, or leave the key out.';
const navKeywordsSchema = () => z.array(
z.string()
.max(NAV_KEYWORD_MAX_LENGTH, {
error: () => `a navigation keyword is at most ${NAV_KEYWORD_MAX_LENGTH} characters — one word or short `
+ 'phrase a person would type to find the entry.',
})
.regex(/^\S(?:.*\S)?$/u, { error: () => NAV_KEYWORD_NOT_TRIMMED }),
).max(NAV_KEYWORDS_MAX, {
).min(1, { error: () => NAV_KEYWORDS_EMPTY }).max(NAV_KEYWORDS_MAX, {
error: () => `an entry takes at most ${NAV_KEYWORDS_MAX} keywords — keep the words people actually use for it.`,
});

Expand Down Expand Up @@ -434,7 +437,7 @@ const BaseNavItemSchema = z.object({
+ 'name after a rename. Source-language strings as authored; another locale\'s aliases come from the '
+ "translation bundle entry `apps.<app>.navigation.<id>.keywords`, keyed by this entry's `id`. Search only: "
+ 'never shown as the entry\'s text, never a route, never a gate. Each trimmed, non-empty, at most 60 '
+ 'characters; at most 20. The command palette reads it on the eight leaf kinds, object, dashboard, '
+ 'characters; at least 1, at most 20. The command palette reads it on the eight leaf kinds, object, dashboard, '
+ 'page, report, component, url, doc and action entries (an action hit is drawn apart and runs the action), '
+ 'and on a group, whose keywords find the entries under it.',
),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

/**
* Clearing an entry's translated label in the design mode's menu keeps that
* entry's translated keywords (objectstack#39210, review N4 of #39207).
*
* A navigation translation node may carry only this locale's `keywords`
* (#39146). The menu save used to delete the whole node when a label was
* cleared, so the locale's search words went with it. Now a cleared label
* drops `label` only; a node left with no keywords translates nothing and is
* still deleted.
*/

import { describe, expect, it, vi } from 'vitest';

vi.mock('../../assistant/assistantBus', async (importOriginal) => ({
...(await importOriginal<Record<string, unknown>>()),
emitMetadataRefresh: vi.fn(),
}));

import { menuTranslationName, writeAppMenu, type AppMenuSaveDoors } from '../designModeMenuSave';

const TEXTS = { pendingDraft: 'pending draft' };
const PKG = 'com.acme.crm';
const TRANSLATION = menuTranslationName('crm', 'zh-CN');

/** Write `labels` over the stored translation item `stored`; answers the body saved. */
async function saveOver(stored: Record<string, unknown>, labels: Record<string, string | null>) {
const saved: unknown[] = [];
const doors: Pick<AppMenuSaveDoors, 'client'> = {
client: {
layered: async () => ({ code: stored, effective: stored, overlayVersion: 'v1' }),
save: async (_type, _name, body) => {
saved.push(body);
return {};
},
publish: async () => ({}),
reset: async () => ({}),
},
};
await writeAppMenu(
{
appName: 'crm',
target: PKG,
body: {},
publishPin: { ifMatch: 'v1' },
writesMenu: false,
translation: { name: TRANSLATION, locale: 'zh-CN', labels },
},
TEXTS,
doors,
);
return saved[0] as { apps: { crm: { navigation: Record<string, unknown> } } };
}

const storedWith = (navigation: Record<string, unknown>) => ({
name: TRANSLATION,
locale: 'zh-CN',
apps: { crm: { navigation } },
});

describe('a cleared translated label keeps the entry\'s keywords (objectstack#39210)', () => {
it('a node with keywords loses only its label', async () => {
const body = await saveOver(storedWith({ leads: { label: '线索', keywords: ['潜客', '商机'] } }), { leads: null });
expect(body.apps.crm.navigation).toEqual({ leads: { keywords: ['潜客', '商机'] } });
});

it('CONTROL: a node with a label only is deleted', async () => {
const body = await saveOver(storedWith({ leads: { label: '线索' }, cases: { label: '工单' } }), { leads: null });
expect(body.apps.crm.navigation).toEqual({ cases: { label: '工单' } });
});

it('CONTROL: a node whose keywords are an empty list is deleted, since it translates nothing', async () => {
const body = await saveOver(storedWith({ leads: { label: '线索', keywords: [] } }), { leads: null });
expect(body.apps.crm.navigation).toEqual({});
});

it('CONTROL: a set label keeps the node\'s keywords', async () => {
const body = await saveOver(storedWith({ leads: { label: '线索', keywords: ['潜客'] } }), { leads: '潜在客户' });
expect(body.apps.crm.navigation).toEqual({ leads: { label: '潜在客户', keywords: ['潜客'] } });
});
});
17 changes: 13 additions & 4 deletions ui/packages/app-shell/src/layout/designModeMenuSave.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,9 @@ export function menuTranslationName(appName: string, locale: string): string {
* Write the menu labels `write` as the translation of the app `appName` in
* `target` (objectstack#36504), and publish it: the item as stored, its other
* keys kept, with `apps.APP.navigation.ID.label` set (or dropped, for
* `null`) for each label. Translations of app navigation are read by entry
* id at those keys (`translateApp`), the pair's own first on a customized
* `null`, keeping the node's `keywords` when it has any) for each label.
* Translations of app navigation are read by entry id at those keys
* (`translateApp`), the pair's own first on a customized
* installed app (ADR-0146 D2), so the reader's language reads the new name
* and every other language keeps its own.
*
Expand All @@ -429,8 +430,16 @@ async function writeMenuTranslation(
const app = isRecord(apps[appName]) ? apps[appName] : {};
const navigation: Record<string, unknown> = { ...(isRecord(app.navigation) ? app.navigation : {}) };
for (const [id, label] of Object.entries(write.labels)) {
if (label === null) delete navigation[id];
else navigation[id] = { ...(isRecord(navigation[id]) ? navigation[id] : {}), label };
const node = isRecord(navigation[id]) ? navigation[id] : {};
if (label !== null) navigation[id] = { ...node, label };
else {
// objectstack#39210 — a cleared label drops the label, not the node: a
// node may carry only this locale's `keywords` (#39146), and those stay.
// A node left with no keywords translates nothing and is deleted.
const { label: _cleared, ...rest } = node;
if (Array.isArray(rest.keywords) && rest.keywords.length > 0) navigation[id] = rest;
else delete navigation[id];
}
}
const body = { ...stored, name: write.name, locale: write.locale, apps: { ...apps, [appName]: { ...app, navigation } } };
const pin = publishPinAt(layers);
Expand Down
4 changes: 2 additions & 2 deletions ui/packages/types/src/zod/app.zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,9 @@ const NavigationItemObject = z.looseObject({
// clean here and been thrown away. Spec: the nav base's `keywords`
// (objectstack#39052), read by the command palette (objectstack#39055);
// nothing in objectui reads it yet. The spec's accept set, restated (each
// trimmed, non-empty, at most 60 characters; at most 20), so `objectui
// trimmed, non-empty, at most 60 characters; at least 1 and at most 20), so `objectui
// validate` refuses what the platform's save door refuses.
keywords: z.array(z.string().max(60).regex(/^\S(?:.*\S)?$/u)).max(20).optional().describe('Search aliases: other words a person may type to find this entry, such as its old name after a rename (spec field name)'),
keywords: z.array(z.string().max(60).regex(/^\S(?:.*\S)?$/u)).min(1).max(20).optional().describe('Search aliases: other words a person may type to find this entry, such as its old name after a rename (spec field name)'),

// Type-specific target fields
objectName: z.string().optional().describe('Target object name (type: object)'),
Expand Down
Loading