Skip to content

Commit 87fe1d0

Browse files
committed
fix(fields): the notification faces read only the host fetch; declare their labelling and sweep rows
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibzyvUbUU6pC3x3Amrx
1 parent 1d4eda2 commit 87fe1d0

7 files changed

Lines changed: 50 additions & 11 deletions

File tree

‎ui/packages/fields/src/__tests__/widget-aria-invalid-registry-e2e.test.tsx‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,12 @@ import { QRCodeField } from '../widgets/QRCodeField';
134134
import { ObjectRefField } from '../widgets/ObjectRefField';
135135
import { FilterConditionField } from '../widgets/FilterConditionField';
136136
import { RecipientPickerField } from '../widgets/RecipientPickerField';
137-
import { PositionRefField, PermissionRefField } from '../widgets/RegistryRefField';
137+
import {
138+
PositionRefField,
139+
PermissionRefField,
140+
NotificationTopicField,
141+
NotificationChannelField,
142+
} from '../widgets/RegistryRefField';
138143

139144
/** Same widget map as the #3291 sweep, so the parity check covers the registry. */
140145
const WIDGETS: Record<string, ComponentType<any>> = {
@@ -188,6 +193,8 @@ const WIDGETS: Record<string, ComponentType<any>> = {
188193
'recipient-picker': RecipientPickerField,
189194
'position-ref': PositionRefField,
190195
'permission-ref': PermissionRefField,
196+
'notification-topic': NotificationTopicField,
197+
'notification-channel': NotificationChannelField,
191198
};
192199

193200
/**

‎ui/packages/fields/src/__tests__/widget-dom-leak-e2e.test.tsx‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,12 @@ import { QRCodeField } from '../widgets/QRCodeField';
144144
import { ObjectRefField } from '../widgets/ObjectRefField';
145145
import { FilterConditionField } from '../widgets/FilterConditionField';
146146
import { RecipientPickerField } from '../widgets/RecipientPickerField';
147-
import { PositionRefField, PermissionRefField } from '../widgets/RegistryRefField';
147+
import {
148+
PositionRefField,
149+
PermissionRefField,
150+
NotificationTopicField,
151+
NotificationChannelField,
152+
} from '../widgets/RegistryRefField';
148153

149154
/* ════════════════════════════════════════════════════════════════════════════
150155
* Every registered field widget, both hosts
@@ -207,6 +212,8 @@ const WIDGETS: Record<string, ComponentType<any>> = {
207212
'recipient-picker': RecipientPickerField,
208213
'position-ref': PositionRefField,
209214
'permission-ref': PermissionRefField,
215+
'notification-topic': NotificationTopicField,
216+
'notification-channel': NotificationChannelField,
210217
};
211218

212219
/** Option widgets render an "unfillable" placeholder unless offered a list. */

‎ui/packages/fields/src/index.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5230,6 +5230,8 @@ export const FIELD_WIDGET_LABELLING: Record<
52305230
'recipient-picker': 'control',
52315231
'position-ref': 'control',
52325232
'permission-ref': 'control',
5233+
'notification-topic': 'control',
5234+
'notification-channel': 'control',
52335235
};
52345236

52355237
export function registerField(fieldType: string): void {

‎ui/packages/fields/src/widgets/RegistryRefField.tsx‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ import { useFieldTranslation } from './useFieldTranslation.js';
9393
* (`./preferenceOptions.ts`), through the host's authenticated fetch — and
9494
* differs from the registry arm in exactly what an open list needs:
9595
*
96-
* - FAILED, IDLE or an empty list: the plain text box, with no notice;
96+
* - FAILED, IDLE (no host fetch on `SchemaRendererContext`) or an empty
97+
* list: the plain text box, with no notice;
9798
* - LOADED: a picker that lists the served values in the door's order (`*`
9899
* first) and ALSO commits whatever the person types, verbatim;
99100
* - a stored or typed value the list does not hold is kept, marked "not in
@@ -407,8 +408,9 @@ export function PreferenceOptionField({
407408
}: PreferenceOptionFieldProps) {
408409
const ctx = React.useContext(SchemaRendererContext);
409410
const { t } = useFieldTranslation();
410-
const doFetch: ApiFetch | undefined = ctx?.apiFetch ?? (typeof fetch === 'function' ? fetch : undefined);
411-
const catalog = useCatalog(PREFERENCE_READER, doFetch, preferenceList);
411+
// The host's authenticated fetch only: a surface with none (a preview, a
412+
// test that drives the widget bare) has no list to offer and is IDLE.
413+
const catalog = useCatalog(PREFERENCE_READER, ctx?.apiFetch, preferenceList);
412414
const [open, setOpen] = React.useState(false);
413415
const [search, setSearch] = React.useState('');
414416
const current = typeof value === 'string' ? value : '';

‎ui/packages/fields/src/widgets/__tests__/RegistryRefField.preferenceOptions-31062.test.tsx‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,21 @@ describe('notification-topic — the plain text box when there is no list (#3020
180180
expect(screen.queryByRole('status')).toBeNull();
181181
});
182182

183+
it('no host fetch gives the same text box, and nothing is read', async () => {
184+
const globalFetch = vi.spyOn(globalThis, 'fetch');
185+
const onChange = vi.fn();
186+
render(
187+
<SchemaRendererProvider dataSource={null}>
188+
<NotificationTopicField value="*" onChange={onChange} field={{ name: 'topic' } as any} />
189+
</SchemaRendererProvider>,
190+
);
191+
const box = screen.getByRole('textbox');
192+
expect(box).toBeEnabled();
193+
expect(box).toHaveValue('*');
194+
expect(globalFetch).not.toHaveBeenCalled();
195+
globalFetch.mockRestore();
196+
});
197+
183198
it('an empty list gives the same text box', async () => {
184199
const apiFetch = door(ok({ success: true, data: { topics: [], channels: [] } }));
185200
mount(NotificationTopicField, { apiFetch });

‎ui/packages/fields/src/widgets/preferenceOptions.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
* list of `{ value, wildcard, … }` with the `'*'` entry first; a channel also
1515
* says whether the deployment can send on it (`configured`).
1616
*
17-
* The read rides the host's AUTHENTICATED fetch, `SchemaRendererContext.apiFetch`
18-
* (the global fetch only where no host supplies one), the way every renderer
19-
* read of the host's own API does. One request per fetch function for the page
17+
* The read rides the host's AUTHENTICATED fetch, `SchemaRendererContext.apiFetch`,
18+
* and only that: a surface whose host supplies none offers no list, and the
19+
* face is the plain text box. One request per fetch function for the page
2020
* session, shared by every field that draws from it (a preference form holds a
2121
* topic and a channel); a failed read is not kept, so the next field that
2222
* mounts asks again.

‎ui/packages/i18n/src/__tests__/de-quote-pairing-3876.test.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,11 @@ describe('objectui#3876 — de pack closes „ with “ and not with a straight
401401
// 108 once objectstack-ai/objectstack#30894 added
402402
// `connectAgent.access.revokeTitle`, the confirm that names the API key
403403
// being revoked („{{name}}“) — one interpolated span, runtime data.
404-
expect(okSpans, 'correctly paired spans').toBe(108);
404+
// 109 once objectstack-ai/objectstack#31062 added
405+
// `fields.preferenceOption.useTyped`, the picker row that commits the typed
406+
// topic or channel („{{value}}“ verwenden) — one interpolated span, runtime
407+
// data.
408+
expect(okSpans, 'correctly paired spans').toBe(109);
405409
});
406410

407411
it('keeps the count identity that replaces the card’s count(„) === count(“)', () => {
@@ -490,8 +494,10 @@ describe('objectui#3876 — de pack closes „ with “ and not with a straight
490494
// 107 / 107 / 0 after objectstack-ai/objectstack#30206 added
491495
// `console.firstRunChecklist.organizationName.todo` and `.timezone.todo`,
492496
// one matched pair each. 108 / 108 / 0 after objectstack-ai/objectstack#30894
493-
// added `connectAgent.access.revokeTitle`, one more matched pair.
494-
expect({ open, close, rdq }).toEqual({ open: 108, close: 108, rdq: 0 });
497+
// added `connectAgent.access.revokeTitle`, one more matched pair. 109 / 109 / 0
498+
// after objectstack-ai/objectstack#31062 added
499+
// `fields.preferenceOption.useTyped`, one more matched pair.
500+
expect({ open, close, rdq }).toEqual({ open: 109, close: 109, rdq: 0 });
495501
// The durable shape: every „ closed by a “, every surplus “ an English
496502
// opener answered by a ”. Survived translating the two English values.
497503
expect(close).toBe(open + rdq);

0 commit comments

Comments
 (0)