Skip to content

Commit ae7e6fa

Browse files
committed
fix(ui): judge a param's degradation by the widget it draws, and match a restated field type through the param-type fold
Contract-review should-fixes: paramDegradesWithoutTarget asks the drawn widget key, so a text param naming the lookup widget with no target degrades and warns; inheritedWidget compares the param and field types through resolveParamWidgetType, so an alias spelling still restates the type; the spec JSDoc says inherits or restates. Claude-Session: https://claude.ai/code/session_01L6bhgXcNPmrQhpwYYn7fEq Co-authored-by: Claude <noreply@anthropic.com>
1 parent 4d88bf5 commit ae7e6fa

6 files changed

Lines changed: 47 additions & 9 deletions

File tree

‎packages/spec/src/ui/action.zod.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@ export const ActionParamSchema = lazySchema(() => strictObject(
254254
* Like the field key it is an open string, not an enum: an unregistered name
255255
* is kept and the dialog draws the `type` renderer instead, so it degrades
256256
* safely. The console reads it (#30260): `resolveActionParams` carries it
257-
* onto the resolved param — a field-backed param that inherits its `type`
258-
* inherits the field's `widget` with it — and `paramToField` draws the named
257+
* onto the resolved param — a field-backed param that inherits or restates
258+
* its `type` inherits the field's `widget` with it — and `paramToField` draws the named
259259
* widget. The server still validates the submitted value by `type`.
260260
*/
261261
widget: z.string().optional().describe(

‎ui/packages/app-shell/src/utils/paramToField.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,4 +421,22 @@ describe('paramToField — an authored `widget` draws the param (#30260)', () =>
421421
warn.mockRestore();
422422
}
423423
});
424+
425+
it('a widget that names a picker with no target degrades like the picker type does, and warns', () => {
426+
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
427+
try {
428+
const param = p({ type: 'text', widget: 'lookup' });
429+
expect(paramDegradesWithoutTarget(param)).toBe(true);
430+
expect(paramToField(param).type).toBe('text');
431+
expect(warn).toHaveBeenCalledTimes(1);
432+
// CONTROL: with a target the named picker is drawn, and nothing warns.
433+
warn.mockClear();
434+
const targeted = p({ type: 'text', widget: 'lookup', referenceTo: 'accounts' });
435+
expect(paramDegradesWithoutTarget(targeted)).toBe(false);
436+
expect(paramToField(targeted).type).toBe('lookup');
437+
expect(warn).not.toHaveBeenCalled();
438+
} finally {
439+
warn.mockRestore();
440+
}
441+
});
424442
});

‎ui/packages/app-shell/src/utils/paramToField.ts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,13 @@ const LOOKUP_WIDGET_TYPES = new Set(['lookup', 'master_detail']);
8787
* for why `user` must never degrade.
8888
*/
8989
export function paramDegradesWithoutTarget(param: ActionParamDef): boolean {
90-
// A registered authored `widget` replaces the `type` widget before the
91-
// fallback is ever considered, so such a param never degrades.
92-
if (authoredWidgetKey(param) !== undefined) return false;
93-
return LOOKUP_WIDGET_TYPES.has(resolveParamWidgetType(param.type)) && !param.referenceTo;
90+
// Asked of the widget the param will actually DRAW: a registered authored
91+
// `widget` replaces the `type` widget, so `{ type: 'lookup', widget:
92+
// 'permission-ref' }` never degrades, while `{ type: 'text', widget:
93+
// 'lookup' }` with no target does — it would otherwise mount a picker that
94+
// has nothing to query.
95+
const drawn = authoredWidgetKey(param) ?? resolveParamWidgetType(param.type);
96+
return LOOKUP_WIDGET_TYPES.has(drawn) && !param.referenceTo;
9497
}
9598

9699
/**

‎ui/packages/app-shell/src/utils/resolveActionParams.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,7 @@ describe('resolveActionParams — the param `widget` reaches the resolved param
527527
fields: {
528528
permission_set: { type: 'text', label: 'Permission set', widget: 'permission-ref' } as any,
529529
plain: { type: 'text', label: 'Plain' },
530+
account: { type: 'lookup', label: 'Account', reference: 'account', widget: 'record-ref' } as any,
530531
},
531532
},
532533
],
@@ -553,6 +554,15 @@ describe('resolveActionParams — the param `widget` reaches the resolved param
553554
expect(out.widget).toBe('permission-ref');
554555
});
555556

557+
it('inherits it when the param restates the field type in an alias spelling', () => {
558+
// `reference` is the param dialect's alias of `lookup` (PARAM_TYPE_ALIASES).
559+
const [out] = resolveActionParams([{ field: 'account', type: 'reference' }], grantCtx());
560+
expect(out.widget).toBe('record-ref');
561+
// CONTROL: a genuinely different type still does not inherit it.
562+
const [other] = resolveActionParams([{ field: 'account', type: 'text' }], grantCtx());
563+
expect(other.widget).toBeUndefined();
564+
});
565+
556566
it('does NOT inherit the field widget onto a param that overrides the type', () => {
557567
const [out] = resolveActionParams([{ field: 'permission_set', type: 'textarea' }], grantCtx());
558568
expect(out.widget).toBeUndefined();

‎ui/packages/core/src/actions/ActionRunner.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ export interface ActionParamDef {
892892
* its machine name, ADR-0131 D4). `type` stays the VALUE's type.
893893
*
894894
* Set by `resolveActionParams()` — the param's own `widget`, else, for a
895-
* field-backed param that also inherits its `type`, the field's. Read by
895+
* field-backed param that also inherits or restates its `type`, the field's. Read by
896896
* app-shell's `paramToField()`, which draws the named widget when it is
897897
* registered and the `type` widget when it is not.
898898
*/

‎ui/packages/fields/src/resolveActionParams.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,8 @@ function storedRow(
593593
*
594594
* The spec resolves a field-backed param's "widget mapping from object
595595
* metadata" (`ActionParamSchema`), and the field's `widget` is that mapping.
596-
* (A param that restates the field's own `type` still inherits it.)
596+
* (A param that restates the field's own `type`, in any spelling the param-type
597+
* fold maps onto the same widget, still inherits it.)
597598
* It is a mapping FOR the field's type, though: the record form draws it over
598599
* a value of that type, and the server validates the param's value by the
599600
* param's `type` (ADR-0104 D2). A param that overrides `type` asks for a
@@ -602,7 +603,13 @@ function storedRow(
602603
*/
603604
function inheritedWidget(param: RawActionParam, field: RuntimeField): string | undefined {
604605
if (param.widget !== undefined) return param.widget;
605-
return param.type === undefined || param.type === field.type ? field.widget : undefined;
606+
// Compared through the one param-type fold, so a param that restates the
607+
// field's type in an alias spelling (`reference` on a `lookup` field) still
608+
// restates it.
609+
if (param.type === undefined) return field.widget;
610+
const restated = field.type !== undefined
611+
&& resolveParamWidgetType(param.type) === resolveParamWidgetType(field.type);
612+
return restated ? field.widget : undefined;
606613
}
607614

608615
/**

0 commit comments

Comments
 (0)