@nocobase/client-v2 2.2.0-alpha.2 → 2.2.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/es/RouteRepository.d.ts +8 -0
  2. package/es/authRedirect.d.ts +1 -0
  3. package/es/components/form/TypedVariableInput.d.ts +9 -1
  4. package/es/components/form/filter/CollectionFilter.d.ts +2 -0
  5. package/es/components/form/filter/CollectionFilterPanel.d.ts +2 -0
  6. package/es/components/form/filter/useFilterActionProps.d.ts +2 -0
  7. package/es/flow/models/blocks/form/value-runtime/runtime.d.ts +9 -0
  8. package/es/flow/models/blocks/js-block/JSBlock.d.ts +1 -0
  9. package/es/index.d.ts +2 -0
  10. package/es/index.mjs +148 -116
  11. package/es/utils/getRouteRuntimeVersion.d.ts +23 -0
  12. package/es/utils/index.d.ts +1 -0
  13. package/lib/index.js +149 -117
  14. package/package.json +7 -7
  15. package/src/RouteRepository.ts +25 -0
  16. package/src/__tests__/RouteRepository.test.ts +23 -0
  17. package/src/__tests__/authRedirect.test.ts +17 -0
  18. package/src/__tests__/getRouteRuntimeVersion.test.ts +68 -0
  19. package/src/authRedirect.ts +38 -0
  20. package/src/components/form/JsonTextArea.tsx +4 -0
  21. package/src/components/form/TypedVariableInput.tsx +58 -34
  22. package/src/components/form/__tests__/TypedVariableInput.test.tsx +54 -0
  23. package/src/components/form/filter/CollectionFilter.tsx +4 -0
  24. package/src/components/form/filter/CollectionFilterPanel.tsx +4 -0
  25. package/src/components/form/filter/__tests__/useFilterActionProps.test.tsx +95 -0
  26. package/src/components/form/filter/useFilterActionProps.ts +37 -6
  27. package/src/flow/actions/dateTimeFormat.tsx +2 -2
  28. package/src/flow/admin-shell/BaseLayoutModel.tsx +13 -0
  29. package/src/flow/admin-shell/admin-layout/AdminLayoutEntryGuard.test.tsx +177 -1
  30. package/src/flow/admin-shell/admin-layout/AdminLayoutEntryGuard.tsx +20 -0
  31. package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutModel.test.tsx +77 -0
  32. package/src/flow/models/base/ActionModelCore.tsx +6 -4
  33. package/src/flow/models/base/__tests__/ActionModelCore.render.test.tsx +37 -0
  34. package/src/flow/models/blocks/form/value-runtime/__tests__/runtime.test.ts +87 -0
  35. package/src/flow/models/blocks/form/value-runtime/runtime.ts +91 -0
  36. package/src/flow/models/blocks/js-block/JSBlock.tsx +223 -2
  37. package/src/flow/models/blocks/js-block/__tests__/JSBlockModel.test.tsx +150 -0
  38. package/src/flow/models/blocks/table/TableColumnModel.tsx +6 -2
  39. package/src/flow/models/blocks/table/__tests__/TableColumnModel.test.tsx +51 -0
  40. package/src/flow/models/fields/AssociationFieldModel/RecordSelectFieldModel.tsx +45 -13
  41. package/src/flow/utils/__tests__/dateTimeFormat.test.ts +42 -0
  42. package/src/index.ts +2 -0
  43. package/src/utils/getRouteRuntimeVersion.ts +185 -0
  44. package/src/utils/index.tsx +1 -0
@@ -43,6 +43,14 @@ const isCondition = (item: FilterGroupItem): item is CollectionFilterItemValue =
43
43
  typeof (item as CollectionFilterItemValue).path === 'string' &&
44
44
  Object.prototype.hasOwnProperty.call(item, 'operator');
45
45
 
46
+ const cloneFilterGroupItem = (item: FilterGroupItem): FilterGroupItem =>
47
+ isGroup(item) ? { logic: item.logic, items: item.items.map((child) => cloneFilterGroupItem(child)) } : { ...item };
48
+
49
+ const cloneFilterGroup = (group: FilterGroupValue): FilterGroupValue => ({
50
+ logic: group.logic,
51
+ items: group.items.map((item) => cloneFilterGroupItem(item)),
52
+ });
53
+
46
54
  /**
47
55
  * `true` when the rhs of a condition is "no real value yet" — covers `undefined` / `null` / empty string / empty array / empty plain object. Mirrors v1's `removeNullCondition` `isEmpty` predicate so half-filled rows ("Locked time → is → (no date picked yet)") get dropped on Submit instead of being sent to the server as `{lockedTs:{}}` and triggering a 500.
48
56
  */
@@ -164,6 +172,8 @@ export interface UseFilterActionPropsArgs extends UseFilterOptionsArgs {
164
172
  collection: Collection | undefined;
165
173
  /** Previously compiled filter param used to seed the editable filter group. */
166
174
  initialValue?: CompiledFilter;
175
+ /** Default compiled filter used both for initial empty state and Reset. */
176
+ defaultValue?: CompiledFilter;
167
177
  /**
168
178
  * Called when the user submits or resets the filter popover. Receives the compiled filter param (`undefined` when cleared) and which footer button triggered the call. Typical implementation: `(filter, action) => { listRequest.run(filter); if (action === 'submit') closePopover(); }`.
169
179
  */
@@ -216,12 +226,23 @@ export interface UseFilterActionPropsResult {
216
226
  * ```
217
227
  */
218
228
  export function useFilterActionProps(args: UseFilterActionPropsArgs): UseFilterActionPropsResult {
219
- const { collection, initialValue, onApply, filterableFieldNames, nonfilterableFieldNames, noIgnore, t } = args;
229
+ const {
230
+ collection,
231
+ initialValue,
232
+ defaultValue,
233
+ onApply,
234
+ filterableFieldNames,
235
+ nonfilterableFieldNames,
236
+ noIgnore,
237
+ t,
238
+ } = args;
239
+ const seedValue = initialValue ?? defaultValue;
240
+ const defaultGroup = decompileFilterGroup(defaultValue) || createEmptyGroup();
220
241
 
221
242
  // Held in a ref so the group object identity is stable for the lifetime of the host component — `<FilterContent>` mutates this object directly (push/splice on `items`, swap `logic`), and a fresh observable on every render would reset that internal state.
222
243
  const valueRef = useRef<FilterGroupValue>();
223
244
  if (!valueRef.current) {
224
- valueRef.current = observable(decompileFilterGroup(initialValue) || createEmptyGroup()) as FilterGroupValue;
245
+ valueRef.current = observable(decompileFilterGroup(seedValue) || createEmptyGroup()) as FilterGroupValue;
225
246
  }
226
247
  const value = valueRef.current;
227
248
 
@@ -240,9 +261,10 @@ export function useFilterActionProps(args: UseFilterActionPropsArgs): UseFilterA
240
261
  });
241
262
 
242
263
  const onReset = useMemoizedFn(() => {
243
- value.logic = '$and';
244
- value.items = [];
245
- onApply(undefined, 'reset');
264
+ const next = cloneFilterGroup(defaultGroup);
265
+ value.logic = next.logic;
266
+ value.items = next.items;
267
+ onApply(compileFilterGroup(value), 'reset');
246
268
  });
247
269
 
248
270
  const translate = useMemoizedFn((key: string) => (t ? t(key) : key));
@@ -261,7 +283,16 @@ export function useFilterActionProps(args: UseFilterActionPropsArgs): UseFilterA
261
283
  );
262
284
 
263
285
  // Re-read on each render so `observer`-wrapped hosts re-render when the reactive `items` array length changes. No useMemo needed — the `value` object's identity is stable (held in a ref), but its observable `items.length` is what we actually care about, and the eslint exhaustive-deps rule rightly complains about depending on a mutable property of a stable ref.
264
- const conditionCount = value.items.length;
286
+ const conditionCount = (() => {
287
+ const compiled = compileFilterGroup(value);
288
+ if (compiled?.$and && Array.isArray(compiled.$and)) {
289
+ return compiled.$and.length;
290
+ }
291
+ if (compiled?.$or && Array.isArray(compiled.$or)) {
292
+ return compiled.$or.length;
293
+ }
294
+ return 0;
295
+ })();
265
296
 
266
297
  return { value, options, FilterItem, ctx, onSubmit, onReset, conditionCount };
267
298
  }
@@ -28,11 +28,11 @@ const isTableColumnFieldSubModel = (model) => {
28
28
 
29
29
  const syncTableColumnDateTimeFormatProps = (ctx, props) => {
30
30
  const model = ctx.model;
31
- if (!isTableColumnFieldSubModel(model) || !model?.parent?.collectionField?.isAssociationField?.()) {
31
+ if (!isTableColumnFieldSubModel(model)) {
32
32
  return;
33
33
  }
34
34
 
35
- model.parent.setProps(props);
35
+ model.parent?.setProps?.(props);
36
36
  };
37
37
 
38
38
  export const dateTimeFormat = defineAction({
@@ -20,6 +20,7 @@ import {
20
20
  type BaseLayoutRouteCoordinatorOptions,
21
21
  type RoutePageMeta,
22
22
  } from './BaseLayoutRouteCoordinator';
23
+ import { NocoBaseDesktopRouteType } from '../../flow-compat';
23
24
  import type { LayoutDefinition } from '../../layout-manager/types';
24
25
  import { isLayoutContentRouteName } from '../../layout-manager/utils';
25
26
 
@@ -322,6 +323,18 @@ export class BaseLayoutModel<
322
323
  };
323
324
  }
324
325
 
326
+ const routeRepository = this.flowEngine.context.routeRepository;
327
+ const schemaRoute = routeRepository?.getRouteBySchemaUid?.(pageUid);
328
+ const route = schemaRoute ? undefined : routeRepository?.getRouteById?.(pageUid);
329
+ if (!schemaRoute && route?.type === NocoBaseDesktopRouteType.group) {
330
+ return {
331
+ type: 'root',
332
+ pathname,
333
+ basePathname,
334
+ relativePath,
335
+ };
336
+ }
337
+
325
338
  return {
326
339
  type: 'page',
327
340
  pathname,
@@ -10,8 +10,9 @@
10
10
  import { FlowEngine, FlowEngineProvider } from '@nocobase/flow-engine';
11
11
  import { act, render, screen, waitFor } from '@testing-library/react';
12
12
  import React from 'react';
13
- import { createMemoryRouter, RouterProvider } from 'react-router-dom';
13
+ import { createMemoryRouter, Outlet, RouterProvider } from 'react-router-dom';
14
14
  import { describe, expect, it, vi } from 'vitest';
15
+ import { NocoBaseDesktopRouteType } from '../../../flow-compat';
15
16
  import { RouteRepository } from '../../../RouteRepository';
16
17
  import { AdminLayoutEntryGuard } from './AdminLayoutEntryGuard';
17
18
  import type { AdminLayoutModel } from './AdminLayoutModel';
@@ -307,4 +308,179 @@ describe('AdminLayoutEntryGuard', () => {
307
308
  expect(activateLayout).toHaveBeenCalledTimes(2);
308
309
  expect(activateLayout).toHaveBeenLastCalledWith(expect.objectContaining({ uid: 'admin-layout-next' }));
309
310
  });
311
+
312
+ it('should redirect group id paths to the first v2 landing route', async () => {
313
+ const modernWindow = window as Window & { __nocobase_modern_client_prefix__?: string };
314
+ modernWindow.__nocobase_modern_client_prefix__ = 'v2';
315
+ const engine = new FlowEngine();
316
+ const request = vi.fn().mockResolvedValue({
317
+ data: {
318
+ data: [],
319
+ },
320
+ });
321
+ const routeRepository = new RouteRepository({
322
+ api: {
323
+ request,
324
+ resource: vi.fn(),
325
+ },
326
+ } as never);
327
+ routeRepository.setRoutes([
328
+ {
329
+ id: 1,
330
+ title: 'Group',
331
+ type: NocoBaseDesktopRouteType.group,
332
+ children: [
333
+ {
334
+ id: 11,
335
+ title: 'Flow page',
336
+ schemaUid: 'flow-page-1',
337
+ type: NocoBaseDesktopRouteType.flowPage,
338
+ },
339
+ ],
340
+ },
341
+ ]);
342
+ engine.context.defineProperty('routeRepository', {
343
+ value: routeRepository,
344
+ });
345
+ engine.context.defineProperty('app', {
346
+ value: {
347
+ getPublicPath: () => '/apps/demo/v2/',
348
+ router: {
349
+ getBasename: () => '/apps/demo/v2',
350
+ },
351
+ },
352
+ });
353
+
354
+ const model = {
355
+ layout: {
356
+ routeName: 'admin',
357
+ routePath: '/admin',
358
+ uid: 'admin-layout-model',
359
+ },
360
+ } as AdminLayoutModel;
361
+ const router = createMemoryRouter(
362
+ [
363
+ {
364
+ path: '/admin',
365
+ id: 'admin',
366
+ element: (
367
+ <FlowEngineProvider engine={engine}>
368
+ <AdminLayoutEntryGuard model={model}>
369
+ <Outlet />
370
+ </AdminLayoutEntryGuard>
371
+ </FlowEngineProvider>
372
+ ),
373
+ children: [
374
+ {
375
+ path: ':name',
376
+ id: 'admin.__page',
377
+ element: <div>Admin page shell</div>,
378
+ },
379
+ ],
380
+ },
381
+ ],
382
+ {
383
+ initialEntries: ['/admin/1'],
384
+ },
385
+ );
386
+
387
+ try {
388
+ render(<RouterProvider router={router} />);
389
+
390
+ await waitFor(() => {
391
+ expect(router.state.location.pathname).toBe('/admin/flow-page-1');
392
+ });
393
+ expect(await screen.findByText('Admin page shell')).toBeInTheDocument();
394
+ } finally {
395
+ delete modernWindow.__nocobase_modern_client_prefix__;
396
+ }
397
+ });
398
+
399
+ it('should prefer schema uid routes before resolving numeric group ids', async () => {
400
+ const modernWindow = window as Window & { __nocobase_modern_client_prefix__?: string };
401
+ modernWindow.__nocobase_modern_client_prefix__ = 'v2';
402
+ const engine = new FlowEngine();
403
+ const routeRepository = {
404
+ activateLayout: vi.fn(() => vi.fn()),
405
+ ensureAccessibleLoaded: vi.fn().mockResolvedValue([]),
406
+ isAccessibleLoaded: vi.fn(() => true),
407
+ getRouteBySchemaUid: vi.fn((pageUid: string) =>
408
+ pageUid === '1'
409
+ ? {
410
+ schemaUid: '1',
411
+ type: NocoBaseDesktopRouteType.flowPage,
412
+ }
413
+ : undefined,
414
+ ),
415
+ getRouteById: vi.fn((routeId: string) =>
416
+ routeId === '1'
417
+ ? {
418
+ id: 1,
419
+ type: NocoBaseDesktopRouteType.group,
420
+ children: [
421
+ {
422
+ schemaUid: 'flow-page-1',
423
+ type: NocoBaseDesktopRouteType.flowPage,
424
+ },
425
+ ],
426
+ }
427
+ : undefined,
428
+ ),
429
+ listAccessible: vi.fn(() => []),
430
+ };
431
+ engine.context.defineProperty('routeRepository', {
432
+ value: routeRepository,
433
+ });
434
+ engine.context.defineProperty('app', {
435
+ value: {
436
+ getPublicPath: () => '/apps/demo/v2/',
437
+ router: {
438
+ getBasename: () => '/apps/demo/v2',
439
+ },
440
+ },
441
+ });
442
+
443
+ const model = {
444
+ layout: {
445
+ routeName: 'admin',
446
+ routePath: '/admin',
447
+ uid: 'admin-layout-model',
448
+ },
449
+ } as AdminLayoutModel;
450
+ const router = createMemoryRouter(
451
+ [
452
+ {
453
+ path: '/admin',
454
+ id: 'admin',
455
+ element: (
456
+ <FlowEngineProvider engine={engine}>
457
+ <AdminLayoutEntryGuard model={model}>
458
+ <Outlet />
459
+ </AdminLayoutEntryGuard>
460
+ </FlowEngineProvider>
461
+ ),
462
+ children: [
463
+ {
464
+ path: ':name',
465
+ id: 'admin.__page',
466
+ element: <div>Admin page shell</div>,
467
+ },
468
+ ],
469
+ },
470
+ ],
471
+ {
472
+ initialEntries: ['/admin/1'],
473
+ },
474
+ );
475
+
476
+ try {
477
+ render(<RouterProvider router={router} />);
478
+
479
+ await screen.findByText('Admin page shell');
480
+ expect(router.state.location.pathname).toBe('/admin/1');
481
+ expect(routeRepository.getRouteById).not.toHaveBeenCalled();
482
+ } finally {
483
+ delete modernWindow.__nocobase_modern_client_prefix__;
484
+ }
485
+ });
310
486
  });
@@ -132,6 +132,26 @@ export const AdminLayoutEntryGuard: FC<{ children: React.ReactNode; model?: Admi
132
132
  }
133
133
  }
134
134
 
135
+ const groupRoute = currentRoute ? undefined : routeRepository?.getRouteById?.(pageUid);
136
+ if (!currentRoute && groupRoute?.type === NocoBaseDesktopRouteType.group) {
137
+ const target = resolveAdminRouteRuntimeTarget({
138
+ app,
139
+ route: groupRoute,
140
+ layout: layoutRuntime,
141
+ });
142
+
143
+ if (target.runtimePath) {
144
+ replaceTriggeredRef.current = true;
145
+ if (target.navigationMode === 'document') {
146
+ window.location.replace(target.runtimePath);
147
+ return;
148
+ }
149
+
150
+ navigate(toRouterNavigationPath(target.runtimePath, app.router.getBasename()), { replace: true });
151
+ return;
152
+ }
153
+ }
154
+
135
155
  if (active) {
136
156
  setReady(true);
137
157
  }
@@ -44,6 +44,7 @@ import {
44
44
  type FlowModel,
45
45
  } from '@nocobase/flow-engine';
46
46
  import { AdminLayoutModel, getAdminLayoutModel } from '..';
47
+ import { NocoBaseDesktopRouteType } from '../../../../flow-compat';
47
48
  import { getLayoutPageRouteName, getLayoutPageViewRouteName } from '../../../../layout-manager/utils';
48
49
  import { TopbarActionModel } from '../../../models/topbar/TopbarActionModel';
49
50
  import { UserCenterTopbarActionModel } from '../../../models/topbar/UserCenterTopbarActionModel';
@@ -295,6 +296,82 @@ describe('AdminLayoutModel runtime', () => {
295
296
  });
296
297
  });
297
298
 
299
+ it('should resolve group id paths as blank root routes', async () => {
300
+ const engine = new FlowEngine();
301
+ engine.context.defineProperty('routeRepository', {
302
+ value: {
303
+ getRouteById: (routeId: string) =>
304
+ routeId === '1'
305
+ ? {
306
+ id: 1,
307
+ type: NocoBaseDesktopRouteType.group,
308
+ }
309
+ : undefined,
310
+ },
311
+ });
312
+
313
+ render(
314
+ <FlowEngineProvider engine={engine}>
315
+ <TestAdminLayoutHost />
316
+ </FlowEngineProvider>,
317
+ );
318
+ const model = engine.getModel<TestAdminLayoutModel>('admin-layout-model');
319
+ expect(model).toBeTruthy();
320
+
321
+ expect(
322
+ model.resolveLayoutRoute({
323
+ name: getLayoutPageRouteName('admin'),
324
+ pathname: '/admin/1',
325
+ layoutBasePathname: '/admin',
326
+ }),
327
+ ).toMatchObject({
328
+ type: 'root',
329
+ pathname: '/admin/1',
330
+ relativePath: '1',
331
+ });
332
+ });
333
+
334
+ it('should prefer schema uid routes before treating numeric paths as group ids', async () => {
335
+ const engine = new FlowEngine();
336
+ engine.context.defineProperty('routeRepository', {
337
+ value: {
338
+ getRouteBySchemaUid: (pageUid: string) =>
339
+ pageUid === '1'
340
+ ? {
341
+ schemaUid: '1',
342
+ type: NocoBaseDesktopRouteType.flowPage,
343
+ }
344
+ : undefined,
345
+ getRouteById: (routeId: string) =>
346
+ routeId === '1'
347
+ ? {
348
+ id: 1,
349
+ type: NocoBaseDesktopRouteType.group,
350
+ }
351
+ : undefined,
352
+ },
353
+ });
354
+
355
+ render(
356
+ <FlowEngineProvider engine={engine}>
357
+ <TestAdminLayoutHost />
358
+ </FlowEngineProvider>,
359
+ );
360
+ const model = engine.getModel<TestAdminLayoutModel>('admin-layout-model');
361
+ expect(model).toBeTruthy();
362
+
363
+ expect(
364
+ model.resolveLayoutRoute({
365
+ name: getLayoutPageRouteName('admin'),
366
+ pathname: '/admin/1',
367
+ layoutBasePathname: '/admin',
368
+ }),
369
+ ).toMatchObject({
370
+ type: 'page',
371
+ pageUid: '1',
372
+ });
373
+ });
374
+
298
375
  it('should not consume global routes that belong to nested layouts', async () => {
299
376
  const engine = new FlowEngine();
300
377
  const routeRef = observable.ref({
@@ -25,7 +25,7 @@ export function ActionWithoutPermission(props) {
25
25
  const dataSourcePrefix = `${t(dataSource.displayName || dataSource.key)} > `;
26
26
  const collectionPrefix = collection ? `${t(collection.title) || collection.name || collection.tableName} ` : '';
27
27
  return `${dataSourcePrefix}${collectionPrefix}`;
28
- }, []);
28
+ }, [collection, dataSource.displayName, dataSource.key, t]);
29
29
  const { actionName } = props?.forbidden || model.forbidden;
30
30
  const messageValue = useMemo(() => {
31
31
  return t(
@@ -143,10 +143,11 @@ export class ActionModel<T extends DefaultStructure = DefaultStructure> extends
143
143
  renderButton() {
144
144
  const { iconOnly, ...props } = this.props;
145
145
  const icon = this.getIcon() ? <Icon type={this.getIcon() as any} /> : undefined;
146
+ const titleContent = iconOnly && icon ? null : props.children || this.getTitle();
146
147
 
147
148
  return (
148
149
  <Button {...props} onClick={this.onClick.bind(this)} icon={icon}>
149
- {iconOnly ? null : props.children || this.getTitle()}
150
+ {titleContent}
150
151
  </Button>
151
152
  );
152
153
  }
@@ -162,11 +163,12 @@ export class ActionModel<T extends DefaultStructure = DefaultStructure> extends
162
163
  renderHiddenInConfig(): React.ReactNode | undefined {
163
164
  const { iconOnly, ...props } = this.props;
164
165
  const icon = this.getIcon() ? <Icon type={this.getIcon() as any} /> : undefined;
166
+ const titleContent = iconOnly && icon ? null : props.children || this.getTitle();
165
167
  if (this.forbidden) {
166
168
  return (
167
169
  <ActionWithoutPermission>
168
170
  <Button {...props} onClick={this.onClick.bind(this)} icon={icon} style={{ opacity: '0.3' }}>
169
- {iconOnly ? null : props.children || this.getTitle()}
171
+ {titleContent}
170
172
  </Button>
171
173
  </ActionWithoutPermission>
172
174
  );
@@ -174,7 +176,7 @@ export class ActionModel<T extends DefaultStructure = DefaultStructure> extends
174
176
  return (
175
177
  <Tooltip title={this.context.t('The button is hidden and only visible when the UI Editor is active')}>
176
178
  <Button {...props} onClick={this.onClick.bind(this)} icon={icon} style={{ opacity: '0.3' }}>
177
- {iconOnly ? null : props.children || this.getTitle()}
179
+ {titleContent}
178
180
  </Button>
179
181
  </Tooltip>
180
182
  );
@@ -0,0 +1,37 @@
1
+ import { render, screen } from '@nocobase/test/client';
2
+ import { FlowEngine, FlowEngineProvider } from '@nocobase/flow-engine';
3
+ import { App, ConfigProvider } from 'antd';
4
+ import React from 'react';
5
+ import { describe, expect, it } from 'vitest';
6
+ import { ActionModel } from '../ActionModel';
7
+
8
+ class NoIconActionModel extends ActionModel {
9
+ defaultProps = {
10
+ type: 'link' as const,
11
+ title: 'Open details',
12
+ };
13
+ }
14
+
15
+ describe('ActionModel rendering', () => {
16
+ it('shows the title when iconOnly is true but no icon is configured', () => {
17
+ const engine = new FlowEngine();
18
+ engine.registerModels({ NoIconActionModel });
19
+ const model = engine.createModel<NoIconActionModel>({
20
+ use: 'NoIconActionModel',
21
+ props: {
22
+ title: 'Open details',
23
+ iconOnly: true,
24
+ },
25
+ });
26
+
27
+ render(
28
+ <FlowEngineProvider engine={engine}>
29
+ <ConfigProvider>
30
+ <App>{model.render()}</App>
31
+ </ConfigProvider>
32
+ </FlowEngineProvider>,
33
+ );
34
+
35
+ expect(screen.getByRole('button', { name: 'Open details' })).toBeInTheDocument();
36
+ });
37
+ });
@@ -127,6 +127,93 @@ function createFieldContext(runtime: FormValueRuntime) {
127
127
  }
128
128
 
129
129
  describe('FormValueRuntime (default rules)', () => {
130
+ it('builds draft snapshots from current user-edited values only', async () => {
131
+ const engineEmitter = new EventEmitter();
132
+ const blockEmitter = new EventEmitter();
133
+ const formStub = createFormStub({});
134
+ const dispatchEvent = vi.fn();
135
+
136
+ const blockModel = {
137
+ uid: 'form-user-edited-draft-snapshot',
138
+ flowEngine: { emitter: engineEmitter },
139
+ emitter: blockEmitter,
140
+ dispatchEvent,
141
+ getAclActionName: () => 'create',
142
+ } as ConstructorParameters<typeof FormValueRuntime>[0]['model'];
143
+
144
+ const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as unknown as FormInstance });
145
+ runtime.mount({ sync: true });
146
+
147
+ const blockCtx = createFieldContext(runtime);
148
+ await runtime.setFormValues(blockCtx, [{ path: ['fixed'], value: 'Fixed auto value' }], { source: 'system' });
149
+ await runtime.setFormValues(blockCtx, [{ path: ['defaultTitle'], value: 'Default auto value' }], {
150
+ source: 'default',
151
+ });
152
+ await runtime.setFormValues(blockCtx, [{ path: ['overrideTitle'], value: 'Override auto value' }], {
153
+ source: 'override',
154
+ });
155
+
156
+ expect(runtime.getUserEditedValuePatches()).toEqual([]);
157
+ expect(runtime.getUserEditedValuesSnapshot()).toEqual({});
158
+
159
+ await runtime.setFormValues(
160
+ blockCtx,
161
+ [
162
+ { path: ['title'], value: 'Manual title' },
163
+ { path: ['roles', 0, 'roleName'], value: 'Manual role' },
164
+ ],
165
+ { source: 'user' },
166
+ );
167
+
168
+ expect(runtime.getUserEditedValuePatches()).toEqual([
169
+ { path: ['title'], value: 'Manual title' },
170
+ { path: ['roles', 0, 'roleName'], value: 'Manual role' },
171
+ ]);
172
+ expect(runtime.getUserEditedValuesSnapshot()).toEqual({
173
+ title: 'Manual title',
174
+ roles: [{ roleName: 'Manual role' }],
175
+ });
176
+
177
+ await runtime.setFormValues(blockCtx, [{ path: ['title'], value: 'Fixed title' }], { source: 'system' });
178
+
179
+ expect(runtime.getUserEditedValuesSnapshot()).toEqual({
180
+ roles: [{ roleName: 'Manual role' }],
181
+ });
182
+ });
183
+
184
+ it('omits non-user descendant values from parent user-edited draft patches', async () => {
185
+ const engineEmitter = new EventEmitter();
186
+ const blockEmitter = new EventEmitter();
187
+ const formStub = createFormStub({});
188
+ const dispatchEvent = vi.fn();
189
+
190
+ const blockModel = {
191
+ uid: 'form-user-edited-parent-draft-patch',
192
+ flowEngine: { emitter: engineEmitter },
193
+ emitter: blockEmitter,
194
+ dispatchEvent,
195
+ getAclActionName: () => 'create',
196
+ } as ConstructorParameters<typeof FormValueRuntime>[0]['model'];
197
+
198
+ const runtime = new FormValueRuntime({ model: blockModel, getForm: () => formStub as unknown as FormInstance });
199
+ runtime.mount({ sync: true });
200
+
201
+ const blockCtx = createFieldContext(runtime);
202
+ await runtime.setFormValues(
203
+ blockCtx,
204
+ [{ path: ['roles'], value: [{ roleName: 'Manual role', fixedRoleName: 'Initial fixed role' }] }],
205
+ { source: 'user' },
206
+ );
207
+ await runtime.setFormValues(blockCtx, [{ path: ['roles', 0, 'fixedRoleName'], value: 'System fixed role' }], {
208
+ source: 'system',
209
+ });
210
+
211
+ expect(runtime.getUserEditedValuePatches()).toEqual([{ path: ['roles'], value: [{ roleName: 'Manual role' }] }]);
212
+ expect(runtime.getUserEditedValuesSnapshot()).toEqual({
213
+ roles: [{ roleName: 'Manual role' }],
214
+ });
215
+ });
216
+
130
217
  it('skips object patches when values are unchanged', async () => {
131
218
  const engineEmitter = new EventEmitter();
132
219
  const blockEmitter = new EventEmitter();