@nocobase/client-v2 2.2.0-beta.2 → 2.2.0-beta.5
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.
- package/es/flow/models/fields/AssociationFieldModel/RecordSelectFieldModel.d.ts +2 -0
- package/es/flow/models/fields/AssociationFieldModel/SubTableFieldModel/SubTableColumnModel.d.ts +6 -0
- package/es/flow/utils/dataScopeRowSnapshot.d.ts +59 -0
- package/es/flow/utils/dateTimeDisplayProps.d.ts +49 -0
- package/es/flow/utils/formValueDeps.d.ts +32 -0
- package/es/index.mjs +113 -93
- package/lib/index.js +104 -84
- package/package.json +7 -7
- package/src/components/AppComponents.tsx +19 -3
- package/src/flow/actions/__tests__/dataScopeFormValueClear.test.ts +1022 -0
- package/src/flow/actions/__tests__/subFormFieldLinkageRules.inputArgs.test.ts +2 -2
- package/src/flow/actions/dateTimeFormat.tsx +42 -28
- package/src/flow/actions/linkageRules.tsx +1 -1
- package/src/flow/actions/linkageRulesFormValueRefresh.ts +22 -130
- package/src/flow/admin-shell/admin-layout/HelpLite.tsx +1 -3
- package/src/flow/components/DynamicFlowsIcon.tsx +447 -126
- package/src/flow/components/__tests__/DynamicFlowsIcon.test.tsx +148 -2
- package/src/flow/flows/editMarkdownFlow.tsx +1 -1
- package/src/flow/index.ts +1 -1
- package/src/flow/internal/utils/operatorSchemaHelper.ts +15 -1
- package/src/flow/models/blocks/filter-manager/flow-actions/__tests__/customizeFilterRender.test.tsx +56 -1
- package/src/flow/models/blocks/table/TableColumnModel.tsx +36 -3
- package/src/flow/models/blocks/table/__tests__/TableColumnModel.test.tsx +159 -1
- package/src/flow/models/fields/AssociationFieldModel/RecordSelectFieldModel.tsx +16 -4
- package/src/flow/models/fields/AssociationFieldModel/SubTableFieldModel/SubTableColumnModel.tsx +141 -19
- package/src/flow/models/fields/AssociationFieldModel/SubTableFieldModel/__tests__/SubTableColumnModel.rowRecord.test.ts +197 -0
- package/src/flow/models/fields/AssociationFieldModel/__tests__/RecordPickerFieldModel.itemContext.test.ts +23 -0
- package/src/flow/models/fields/ClickableFieldModel.tsx +5 -0
- package/src/flow/models/fields/DisplayDateTimeFieldModel.tsx +29 -1
- package/src/flow/models/fields/InputFieldModel.tsx +48 -2
- package/src/flow/models/fields/SelectFieldModel.tsx +6 -4
- package/src/flow/models/fields/TextareaFieldModel.tsx +49 -3
- package/src/flow/models/fields/__tests__/DisplayDateTimeFieldModel.test.tsx +96 -0
- package/src/flow/models/fields/__tests__/InputFieldModel.test.tsx +100 -1
- package/src/flow/models/fields/__tests__/SelectFieldModel.test.tsx +43 -0
- package/src/flow/models/fields/__tests__/TextareaFieldModel.test.tsx +100 -0
- package/src/flow/utils/__tests__/dateTimeFormat.test.ts +258 -0
- package/src/flow/utils/dataScopeFormValueClear.ts +218 -81
- package/src/flow/utils/dataScopeRowSnapshot.ts +616 -0
- package/src/flow/utils/dateTimeDisplayProps.ts +135 -0
- package/src/flow/utils/formValueDeps.ts +170 -0
- package/src/settings-center/AdminSettingsLayout.tsx +7 -2
package/src/flow/models/fields/AssociationFieldModel/SubTableFieldModel/SubTableColumnModel.tsx
CHANGED
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
observer,
|
|
27
27
|
FlowModelProvider,
|
|
28
28
|
FlowErrorFallback,
|
|
29
|
+
extractUsedVariablePaths,
|
|
29
30
|
} from '@nocobase/flow-engine';
|
|
30
31
|
import { TableColumnProps, Tooltip, Input, Space, Divider } from 'antd';
|
|
31
32
|
import { ErrorBoundary } from 'react-error-boundary';
|
|
@@ -37,6 +38,14 @@ import { FieldDeletePlaceholder, CustomWidth, normalizeTableColumnWidth } from '
|
|
|
37
38
|
import { buildDynamicNamePath } from '../../../blocks/form/dynamicNamePath';
|
|
38
39
|
import { getSubTableRowIdentity } from './rowIdentity';
|
|
39
40
|
import { getFieldBindingUse, rebuildFieldSubModel } from '../../../../internal/utils/rebuildFieldSubModel';
|
|
41
|
+
import {
|
|
42
|
+
buildCurrentItemTitle,
|
|
43
|
+
createAssociationItemChainContextPropertyOptions,
|
|
44
|
+
createItemChainGetter,
|
|
45
|
+
createParentItemAccessorsFromContext,
|
|
46
|
+
createRootItemChain,
|
|
47
|
+
type ItemChain,
|
|
48
|
+
} from '../itemChain';
|
|
40
49
|
|
|
41
50
|
export const SUB_TABLE_COLUMN_FIELD_COMPONENT_CONTEXT = 'subTableColumn';
|
|
42
51
|
|
|
@@ -180,6 +189,25 @@ const handleModelName = (modelName) => {
|
|
|
180
189
|
return modelName;
|
|
181
190
|
};
|
|
182
191
|
|
|
192
|
+
const DATA_SCOPE_FLOW_KEYS = ['selectSettings', 'cascadeSelectSettings'];
|
|
193
|
+
|
|
194
|
+
function hasFormValueDrivenDataScope(filter: any) {
|
|
195
|
+
if (!filter) return false;
|
|
196
|
+
try {
|
|
197
|
+
const usage = extractUsedVariablePaths(filter) || {};
|
|
198
|
+
return ['item', 'formValues'].some((name) => Object.prototype.hasOwnProperty.call(usage, name));
|
|
199
|
+
} catch {
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function hasFormValueDrivenDataScopeField(fieldModel: any) {
|
|
205
|
+
return DATA_SCOPE_FLOW_KEYS.some((flowKey) => {
|
|
206
|
+
const params = fieldModel?.getStepParams?.(flowKey, 'dataScope');
|
|
207
|
+
return hasFormValueDrivenDataScope(params?.filter);
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
|
|
183
211
|
const MemoFieldRenderer = React.memo(FieldModelRenderer, (prev, next) => {
|
|
184
212
|
return prev.value === next.value && prev.model === next.model;
|
|
185
213
|
});
|
|
@@ -203,6 +231,20 @@ export function getLatestSubTableRowRecord(form: any, fieldIndex: unknown, fallb
|
|
|
203
231
|
return typeof latestRecord === 'undefined' ? fallbackRecord : latestRecord;
|
|
204
232
|
}
|
|
205
233
|
|
|
234
|
+
export function buildSubTableColumnNamePath(
|
|
235
|
+
fieldPath: Array<string | number>,
|
|
236
|
+
rowIdx: number,
|
|
237
|
+
namePath: string | number,
|
|
238
|
+
rowFieldIndex: unknown,
|
|
239
|
+
): Array<string | number> {
|
|
240
|
+
const currentRowPath = buildRowPathFromFieldIndex(rowFieldIndex);
|
|
241
|
+
if (currentRowPath?.length) {
|
|
242
|
+
return [...currentRowPath, namePath];
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return [...fieldPath, rowIdx, namePath];
|
|
246
|
+
}
|
|
247
|
+
|
|
206
248
|
function shouldCommitImmediately(value: any) {
|
|
207
249
|
if (Array.isArray(value)) {
|
|
208
250
|
return true;
|
|
@@ -344,11 +386,23 @@ const MemoCell: React.FC<CellProps> = React.memo(
|
|
|
344
386
|
{parent.mapSubModels('field', (action: FieldModel) => {
|
|
345
387
|
const fieldPath = action.context.fieldPath.split('.');
|
|
346
388
|
const namePath = fieldPath.pop();
|
|
389
|
+
if (typeof namePath === 'undefined') {
|
|
390
|
+
return null;
|
|
391
|
+
}
|
|
392
|
+
const fieldNamePath = buildSubTableColumnNamePath(fieldPath, rowIdx, namePath, rowFork?.context?.fieldIndex);
|
|
393
|
+
const formItemName = buildDynamicNamePath([...fieldPath, rowIdx, namePath], parentFieldIndex);
|
|
347
394
|
|
|
348
395
|
const fork: any = action.createFork({}, `${id}`);
|
|
349
396
|
fork.context.defineProperty('currentObject', { get: () => record });
|
|
397
|
+
fork.context.defineProperty('fieldPathArray', {
|
|
398
|
+
get: () => fieldNamePath,
|
|
399
|
+
cache: false,
|
|
400
|
+
});
|
|
350
401
|
if (rowFork) {
|
|
402
|
+
const itemOptions = rowFork.context.getPropertyOptions?.('item');
|
|
403
|
+
const { value: _value, ...itemOptionsWithoutValue } = (itemOptions || {}) as any;
|
|
351
404
|
fork.context.defineProperty('item', {
|
|
405
|
+
...itemOptionsWithoutValue,
|
|
352
406
|
get: () => rowFork.context.item,
|
|
353
407
|
cache: false,
|
|
354
408
|
});
|
|
@@ -384,7 +438,7 @@ const MemoCell: React.FC<CellProps> = React.memo(
|
|
|
384
438
|
<FormItem
|
|
385
439
|
{...parent.props}
|
|
386
440
|
key={id}
|
|
387
|
-
name={
|
|
441
|
+
name={formItemName}
|
|
388
442
|
style={{ marginBottom: 0 }}
|
|
389
443
|
showLabel={false}
|
|
390
444
|
disabled={
|
|
@@ -445,6 +499,57 @@ export class SubTableColumnModel<
|
|
|
445
499
|
static renderMode = ModelRenderMode.RenderFunction;
|
|
446
500
|
static fieldComponentContext = SUB_TABLE_COLUMN_FIELD_COMPONENT_CONTEXT;
|
|
447
501
|
|
|
502
|
+
private getAssociationField() {
|
|
503
|
+
return (this.parent as any)?.context?.collectionField;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
private getParentFormValues() {
|
|
507
|
+
return (this.context?.blockModel as any)?.context?.formValues;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
private createParentItemAccessors(parentItemAccessor?: () => ItemChain | undefined) {
|
|
511
|
+
const baseAccessors = createParentItemAccessorsFromContext({
|
|
512
|
+
parentContextAccessor: () => (this.parent as any)?.context,
|
|
513
|
+
fallbackParentPropertiesAccessor: () => this.getParentFormValues(),
|
|
514
|
+
});
|
|
515
|
+
|
|
516
|
+
if (!parentItemAccessor) {
|
|
517
|
+
return baseAccessors;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
return {
|
|
521
|
+
parentPropertiesAccessor: (ctx?: any) =>
|
|
522
|
+
parentItemAccessor()?.value ?? baseAccessors.parentPropertiesAccessor(ctx),
|
|
523
|
+
parentItemMetaAccessor: baseAccessors.parentItemMetaAccessor,
|
|
524
|
+
parentItemResolverAccessor: baseAccessors.parentItemResolverAccessor,
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
private createRowItemContextPropertyOptions(
|
|
529
|
+
options: {
|
|
530
|
+
resolverPropertiesAccessor?: () => unknown;
|
|
531
|
+
parentItemAccessor?: () => ItemChain | undefined;
|
|
532
|
+
showParentIndex?: boolean;
|
|
533
|
+
} = {},
|
|
534
|
+
) {
|
|
535
|
+
const associationField = this.getAssociationField();
|
|
536
|
+
|
|
537
|
+
return createAssociationItemChainContextPropertyOptions({
|
|
538
|
+
t: this.context.t,
|
|
539
|
+
title: buildCurrentItemTitle(this.context.t, associationField, this.props?.name),
|
|
540
|
+
showIndex: true,
|
|
541
|
+
showParentIndex:
|
|
542
|
+
options.showParentIndex ??
|
|
543
|
+
(Array.isArray((this.parent as any)?.context?.fieldIndex) &&
|
|
544
|
+
(this.parent as any).context.fieldIndex.length > 0),
|
|
545
|
+
collectionAccessor: () => (this.parent as any)?.collection ?? associationField?.targetCollection ?? null,
|
|
546
|
+
propertiesAccessor: (ctx) => ctx?.item?.value,
|
|
547
|
+
resolverPropertiesAccessor: options.resolverPropertiesAccessor ?? (() => undefined),
|
|
548
|
+
parentCollectionAccessor: () => associationField?.collection,
|
|
549
|
+
parentAccessors: this.createParentItemAccessors(options.parentItemAccessor),
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
|
|
448
553
|
renderHiddenInConfig() {
|
|
449
554
|
return <FieldWithoutPermissionPlaceholder targetModel={this} />;
|
|
450
555
|
}
|
|
@@ -505,6 +610,14 @@ export class SubTableColumnModel<
|
|
|
505
610
|
).some(Boolean);
|
|
506
611
|
}
|
|
507
612
|
|
|
613
|
+
get hasFormValueDrivenDataScopeColumn() {
|
|
614
|
+
return (
|
|
615
|
+
this.parent?.mapSubModels('columns', (column: SubTableColumnModel) => {
|
|
616
|
+
return hasFormValueDrivenDataScopeField(column?.subModels?.field);
|
|
617
|
+
}) || []
|
|
618
|
+
).some(Boolean);
|
|
619
|
+
}
|
|
620
|
+
|
|
508
621
|
onInit(options: any): void {
|
|
509
622
|
super.onInit(options);
|
|
510
623
|
this.context.defineProperty('resourceName', {
|
|
@@ -516,6 +629,10 @@ export class SubTableColumnModel<
|
|
|
516
629
|
this.context.defineProperty('actionName', {
|
|
517
630
|
get: () => 'view',
|
|
518
631
|
});
|
|
632
|
+
this.context.defineProperty('item', {
|
|
633
|
+
get: () => undefined,
|
|
634
|
+
...this.createRowItemContextPropertyOptions(),
|
|
635
|
+
});
|
|
519
636
|
this.emitter.on('onSubModelAdded', (subModel: FieldModel) => {
|
|
520
637
|
if (this.collectionField) {
|
|
521
638
|
subModel.setProps(this.collectionField.getComponentProps());
|
|
@@ -673,25 +790,30 @@ export class SubTableColumnModel<
|
|
|
673
790
|
value: [...baseArr, `${associationKey}:${rowIndex}`],
|
|
674
791
|
});
|
|
675
792
|
}
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
793
|
+
const getRowRecord = () => {
|
|
794
|
+
const form = (fork.context as any)?.form || (this.context?.blockModel as any)?.context?.form;
|
|
795
|
+
return getLatestSubTableRowRecord(form, fork.context.fieldIndex, record);
|
|
796
|
+
};
|
|
797
|
+
const getParentItem = () => {
|
|
798
|
+
const parentItemCtx = (parentItem ?? (this.parent as any)?.context?.item) as ItemChain | undefined;
|
|
799
|
+
return parentItemCtx ?? createRootItemChain(this.getParentFormValues());
|
|
800
|
+
};
|
|
801
|
+
const getRowItem = createItemChainGetter({
|
|
802
|
+
valueAccessor: getRowRecord,
|
|
803
|
+
parentItemAccessor: getParentItem,
|
|
804
|
+
indexAccessor: () => (Number.isFinite(rowIndex) ? rowIndex : undefined),
|
|
805
|
+
lengthAccessor: () => {
|
|
683
806
|
const list = (this.parent as any)?.props?.value;
|
|
684
|
-
|
|
685
|
-
return {
|
|
686
|
-
index: Number.isFinite(rowIndex) ? rowIndex : undefined,
|
|
687
|
-
length,
|
|
688
|
-
__is_new__: isNew,
|
|
689
|
-
__is_stored__: isStored,
|
|
690
|
-
value: rowRecord,
|
|
691
|
-
parentItem: parentItemCtx,
|
|
692
|
-
};
|
|
807
|
+
return Array.isArray(list) ? list.length : undefined;
|
|
693
808
|
},
|
|
694
|
-
|
|
809
|
+
});
|
|
810
|
+
fork.context.defineProperty('item', {
|
|
811
|
+
get: getRowItem,
|
|
812
|
+
...this.createRowItemContextPropertyOptions({
|
|
813
|
+
resolverPropertiesAccessor: getRowRecord,
|
|
814
|
+
parentItemAccessor: getParentItem,
|
|
815
|
+
showParentIndex: baseArr.length > 0,
|
|
816
|
+
}),
|
|
695
817
|
});
|
|
696
818
|
return fork;
|
|
697
819
|
})();
|
|
@@ -707,7 +829,7 @@ export class SubTableColumnModel<
|
|
|
707
829
|
rowFork={rowFork}
|
|
708
830
|
memoKey={cellModeKey}
|
|
709
831
|
width={this.props.width}
|
|
710
|
-
commitOnChange={this.hasFormulaColumn}
|
|
832
|
+
commitOnChange={this.hasFormulaColumn || this.hasFormValueDrivenDataScopeColumn}
|
|
711
833
|
/>
|
|
712
834
|
);
|
|
713
835
|
};
|
|
@@ -15,18 +15,50 @@ import {
|
|
|
15
15
|
SubTableColumnModel,
|
|
16
16
|
getLatestSubTableRowRecord,
|
|
17
17
|
buildRowPathFromFieldIndex,
|
|
18
|
+
buildSubTableColumnNamePath,
|
|
18
19
|
isSubTableColumnConfiguredReadPretty,
|
|
19
20
|
getSubTableColumnTitleField,
|
|
20
21
|
getSubTableColumnReadPrettyFieldProps,
|
|
21
22
|
isSubTableColumnReadPretty,
|
|
22
23
|
} from '../SubTableColumnModel';
|
|
23
24
|
|
|
25
|
+
function createMockCollection(name: string, fields: any[] = []) {
|
|
26
|
+
const collection: any = {
|
|
27
|
+
name,
|
|
28
|
+
title: name,
|
|
29
|
+
dataSourceKey: 'main',
|
|
30
|
+
filterTargetKey: 'id',
|
|
31
|
+
fields,
|
|
32
|
+
getFields: () => collection.fields,
|
|
33
|
+
getField: (fieldName: string) => collection.fields.find((field) => field.name === fieldName),
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
collection.fields.forEach((field) => {
|
|
37
|
+
field.collection = field.collection ?? collection;
|
|
38
|
+
field.filterable = field.filterable ?? true;
|
|
39
|
+
field.isAssociationField = field.isAssociationField ?? (() => false);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
return collection;
|
|
43
|
+
}
|
|
44
|
+
|
|
24
45
|
describe('SubTableColumnModel row record helpers', () => {
|
|
25
46
|
it('builds the row path from fieldIndex entries', () => {
|
|
26
47
|
expect(buildRowPathFromFieldIndex(['roles:0'])).toEqual(['roles', 0]);
|
|
27
48
|
expect(buildRowPathFromFieldIndex(['users:1', 'roles:2'])).toEqual(['users', 1, 'roles', 2]);
|
|
28
49
|
});
|
|
29
50
|
|
|
51
|
+
it('builds absolute form item paths for nested sub-table columns', () => {
|
|
52
|
+
expect(buildSubTableColumnNamePath(['roles'], 0, 'name', ['roles:0'])).toEqual(['roles', 0, 'name']);
|
|
53
|
+
expect(buildSubTableColumnNamePath(['orders', 'lines'], 1, 'product', ['orders:0', 'lines:1'])).toEqual([
|
|
54
|
+
'orders',
|
|
55
|
+
0,
|
|
56
|
+
'lines',
|
|
57
|
+
1,
|
|
58
|
+
'product',
|
|
59
|
+
]);
|
|
60
|
+
});
|
|
61
|
+
|
|
30
62
|
it('prefers the latest row value from form over the fallback record', () => {
|
|
31
63
|
const form = {
|
|
32
64
|
getFieldValue: vi.fn((path: any) => {
|
|
@@ -51,6 +83,171 @@ describe('SubTableColumnModel row record helpers', () => {
|
|
|
51
83
|
expect(getLatestSubTableRowRecord(form, ['roles:0'], fallback)).toBe(fallback);
|
|
52
84
|
});
|
|
53
85
|
|
|
86
|
+
it('provides current item meta for sub-table column data scope variables', async () => {
|
|
87
|
+
const engine = new FlowEngine();
|
|
88
|
+
engine.registerModels({ SubTableColumnModel });
|
|
89
|
+
|
|
90
|
+
const tagsCollection = createMockCollection('tags', [
|
|
91
|
+
{ name: 'id', title: 'ID', type: 'integer', interface: 'integer' },
|
|
92
|
+
{ name: 'name', title: 'Name', type: 'string', interface: 'input' },
|
|
93
|
+
]);
|
|
94
|
+
const rolesCollection = createMockCollection('roles', [
|
|
95
|
+
{ name: 'id', title: 'ID', type: 'integer', interface: 'integer' },
|
|
96
|
+
{ name: 'name', title: 'Name', type: 'string', interface: 'input' },
|
|
97
|
+
{
|
|
98
|
+
name: 'tags',
|
|
99
|
+
title: 'Tags',
|
|
100
|
+
type: 'hasMany',
|
|
101
|
+
interface: 'o2m',
|
|
102
|
+
target: 'tags',
|
|
103
|
+
targetCollection: tagsCollection,
|
|
104
|
+
isAssociationField: () => true,
|
|
105
|
+
},
|
|
106
|
+
]);
|
|
107
|
+
const usersCollection = createMockCollection('users', [
|
|
108
|
+
{ name: 'id', title: 'ID', type: 'integer', interface: 'integer' },
|
|
109
|
+
{ name: 'nickname', title: 'Nickname', type: 'string', interface: 'input' },
|
|
110
|
+
]);
|
|
111
|
+
const rolesField = {
|
|
112
|
+
name: 'roles',
|
|
113
|
+
title: 'Roles',
|
|
114
|
+
type: 'hasMany',
|
|
115
|
+
interface: 'o2m',
|
|
116
|
+
collection: usersCollection,
|
|
117
|
+
target: 'roles',
|
|
118
|
+
targetCollection: rolesCollection,
|
|
119
|
+
isAssociationField: () => true,
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const form = {
|
|
123
|
+
getFieldValue: vi.fn((path: any) => {
|
|
124
|
+
if (JSON.stringify(path) === JSON.stringify(['roles', 0])) {
|
|
125
|
+
return { id: 11, name: 'Admin', tags: [{ id: 7 }] };
|
|
126
|
+
}
|
|
127
|
+
}),
|
|
128
|
+
};
|
|
129
|
+
const blockModel: any = engine.createModel({ use: 'FlowModel', uid: 'form-block', structure: {} as any });
|
|
130
|
+
blockModel.context.defineProperty('form', { value: form });
|
|
131
|
+
blockModel.context.defineProperty('formValues', {
|
|
132
|
+
value: {
|
|
133
|
+
id: 1,
|
|
134
|
+
nickname: 'Alice',
|
|
135
|
+
roles: [{ id: 11, name: 'Admin' }],
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
const subTableFieldModel: any = engine.createModel({
|
|
140
|
+
use: 'FlowModel',
|
|
141
|
+
uid: 'users.roles',
|
|
142
|
+
structure: {} as any,
|
|
143
|
+
});
|
|
144
|
+
subTableFieldModel.collection = rolesCollection;
|
|
145
|
+
subTableFieldModel.setProps({ value: [{ id: 11, name: 'Admin' }] });
|
|
146
|
+
subTableFieldModel.context.defineProperty('collectionField', { value: rolesField });
|
|
147
|
+
subTableFieldModel.context.defineProperty('fieldPath', { value: 'roles' });
|
|
148
|
+
subTableFieldModel.context.defineProperty('blockModel', { value: blockModel });
|
|
149
|
+
|
|
150
|
+
const column: any = engine.createModel({
|
|
151
|
+
use: 'SubTableColumnModel',
|
|
152
|
+
uid: 'users.roles.tags',
|
|
153
|
+
stepParams: {
|
|
154
|
+
fieldSettings: {
|
|
155
|
+
init: {
|
|
156
|
+
fieldPath: 'roles.tags',
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
structure: {} as any,
|
|
161
|
+
});
|
|
162
|
+
column.setParent(subTableFieldModel);
|
|
163
|
+
column.context.defineProperty('blockModel', { value: blockModel });
|
|
164
|
+
column.subModels = { field: [] };
|
|
165
|
+
|
|
166
|
+
const designTimeItemOptions = column.context.getPropertyOptions('item');
|
|
167
|
+
expect(typeof designTimeItemOptions.meta).toBe('function');
|
|
168
|
+
const designTimeMeta = await designTimeItemOptions.meta();
|
|
169
|
+
expect(designTimeMeta.properties.value.title).toBe('Attributes');
|
|
170
|
+
expect(designTimeMeta.properties.parentItem.properties.value.title).toBe('Attributes');
|
|
171
|
+
|
|
172
|
+
const renderCell = column.renderItem();
|
|
173
|
+
renderCell({
|
|
174
|
+
id: 'cell-roles-tags-0',
|
|
175
|
+
rowIdx: 0,
|
|
176
|
+
record: { id: 11, name: 'Stale admin', tags: [{ id: 7 }] },
|
|
177
|
+
parentItem: {
|
|
178
|
+
value: { id: 1, nickname: 'Alice' },
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
const [rowFork] = Array.from(column.forks ?? []) as any[];
|
|
183
|
+
const rowItemOptions = rowFork.context.getPropertyOptions('item');
|
|
184
|
+
expect(typeof rowItemOptions.meta).toBe('function');
|
|
185
|
+
expect(rowItemOptions.resolveOnServer('value.tags.name')).toBe(true);
|
|
186
|
+
|
|
187
|
+
const rowMeta = await rowItemOptions.meta();
|
|
188
|
+
expect(rowMeta.properties.value.title).toBe('Attributes');
|
|
189
|
+
expect(rowMeta.properties.parentItem.properties.value.title).toBe('Attributes');
|
|
190
|
+
expect(rowFork.context.item).toMatchObject({
|
|
191
|
+
index: 0,
|
|
192
|
+
length: 1,
|
|
193
|
+
value: { id: 11, name: 'Admin', tags: [{ id: 7 }] },
|
|
194
|
+
parentItem: {
|
|
195
|
+
value: { id: 1, nickname: 'Alice' },
|
|
196
|
+
},
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it('detects variable data scope columns for immediate row commits', () => {
|
|
201
|
+
const engine = new FlowEngine();
|
|
202
|
+
engine.registerModels({ SubTableColumnModel });
|
|
203
|
+
|
|
204
|
+
const inputColumn: any = engine.createModel({
|
|
205
|
+
use: 'SubTableColumnModel',
|
|
206
|
+
uid: 'users.roles.name',
|
|
207
|
+
structure: {} as any,
|
|
208
|
+
});
|
|
209
|
+
const scopedColumn: any = engine.createModel({
|
|
210
|
+
use: 'SubTableColumnModel',
|
|
211
|
+
uid: 'users.roles.tags',
|
|
212
|
+
structure: {} as any,
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
inputColumn.subModels = {
|
|
216
|
+
field: {
|
|
217
|
+
getStepParams: vi.fn(() => undefined),
|
|
218
|
+
},
|
|
219
|
+
};
|
|
220
|
+
scopedColumn.subModels = {
|
|
221
|
+
field: {
|
|
222
|
+
getStepParams: vi.fn((flowKey: string, stepKey: string) => {
|
|
223
|
+
if (flowKey !== 'selectSettings' || stepKey !== 'dataScope') {
|
|
224
|
+
return undefined;
|
|
225
|
+
}
|
|
226
|
+
return {
|
|
227
|
+
filter: {
|
|
228
|
+
logic: '$and',
|
|
229
|
+
items: [{ path: 'name', operator: '$eq', value: '{{ ctx.item.value.name }}' }],
|
|
230
|
+
},
|
|
231
|
+
};
|
|
232
|
+
}),
|
|
233
|
+
},
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
const parent: any = engine.createModel({
|
|
237
|
+
use: 'FlowModel',
|
|
238
|
+
uid: 'users.roles-table',
|
|
239
|
+
structure: {} as any,
|
|
240
|
+
});
|
|
241
|
+
parent.mapSubModels = vi.fn((key: string, iterator: (column: SubTableColumnModel) => unknown) => {
|
|
242
|
+
if (key !== 'columns') return [];
|
|
243
|
+
return [inputColumn, scopedColumn].map(iterator);
|
|
244
|
+
});
|
|
245
|
+
inputColumn.setParent(parent);
|
|
246
|
+
scopedColumn.setParent(parent);
|
|
247
|
+
|
|
248
|
+
expect(inputColumn.hasFormValueDrivenDataScopeColumn).toBe(true);
|
|
249
|
+
});
|
|
250
|
+
|
|
54
251
|
it('treats a display-only column pattern as read-pretty mode', () => {
|
|
55
252
|
expect(isSubTableColumnReadPretty({ props: { pattern: 'readPretty' } })).toBe(true);
|
|
56
253
|
expect(isSubTableColumnReadPretty({ props: { readPretty: true } })).toBe(true);
|
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
normalizeRecordPickerValue,
|
|
29
29
|
shouldClearRecordPickerValueOnMultipleChange,
|
|
30
30
|
} from '../RecordPickerFieldModel';
|
|
31
|
+
import { getAssociationHydrationNamePath, getAssociationHydrationSetterContext } from '../RecordSelectFieldModel';
|
|
31
32
|
|
|
32
33
|
function createMockCollection() {
|
|
33
34
|
return {
|
|
@@ -93,6 +94,28 @@ describe('RecordPickerFieldModel item context', () => {
|
|
|
93
94
|
expect(shouldClearRecordPickerValueOnMultipleChange({ type: 'belongsTo' }, true, false)).toBe(false);
|
|
94
95
|
});
|
|
95
96
|
|
|
97
|
+
it('uses the current field context for association hydration writes', () => {
|
|
98
|
+
const setFormValue = vi.fn();
|
|
99
|
+
const blockSetFormValue = vi.fn();
|
|
100
|
+
const model = {
|
|
101
|
+
props: {
|
|
102
|
+
name: 'orders',
|
|
103
|
+
},
|
|
104
|
+
context: {
|
|
105
|
+
fieldPathArray: ['orders', 0, 'lines', 1, 'product'],
|
|
106
|
+
setFormValue,
|
|
107
|
+
blockModel: {
|
|
108
|
+
context: {
|
|
109
|
+
setFormValue: blockSetFormValue,
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
expect(getAssociationHydrationNamePath(model)).toEqual(['orders', 0, 'lines', 1, 'product']);
|
|
116
|
+
expect(getAssociationHydrationSetterContext(model)).toBe(model.context);
|
|
117
|
+
});
|
|
118
|
+
|
|
96
119
|
it('itemChain helpers: createParentItemAccessorsFromInputArgs works', () => {
|
|
97
120
|
const inputArgs = {
|
|
98
121
|
parentItem: { value: { id: 1 } },
|
|
@@ -8,14 +8,42 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { DisplayItemModel, tExpr } from '@nocobase/flow-engine';
|
|
11
|
+
import { getDateTimeFormat, getPickerFormat } from '@nocobase/utils/client';
|
|
11
12
|
import dayjs from 'dayjs';
|
|
12
13
|
import React from 'react';
|
|
13
14
|
import { ClickableFieldModel } from './ClickableFieldModel';
|
|
14
15
|
|
|
16
|
+
const stripTimeFromFormat = (format?: string) =>
|
|
17
|
+
format ? format.replace(/\s*[Hh]{1,2}:mm(?::ss)?(?:\.SSS)?(?:\s*[aA])?/g, '').trim() : format;
|
|
18
|
+
|
|
19
|
+
interface DisplayDateTimeFormatProps {
|
|
20
|
+
dateOnly?: boolean;
|
|
21
|
+
picker?: string;
|
|
22
|
+
format?: string;
|
|
23
|
+
dateFormat?: string;
|
|
24
|
+
showTime?: boolean;
|
|
25
|
+
timeFormat?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const resolveDisplayDateTimeFormat = (props: DisplayDateTimeFormatProps) => {
|
|
29
|
+
const { dateOnly, picker = 'date', format, dateFormat, showTime, timeFormat } = props;
|
|
30
|
+
const normalizedFormat = stripTimeFromFormat(format);
|
|
31
|
+
if (picker !== 'date') {
|
|
32
|
+
return dateFormat || normalizedFormat || getPickerFormat(picker);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (!dateOnly && !dateFormat && typeof showTime === 'undefined' && !timeFormat && normalizedFormat) {
|
|
36
|
+
return format;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const normalizedDateFormat = dateFormat || normalizedFormat || getPickerFormat(picker);
|
|
40
|
+
return getDateTimeFormat(picker, normalizedDateFormat, showTime, timeFormat);
|
|
41
|
+
};
|
|
42
|
+
|
|
15
43
|
export class DisplayDateTimeFieldModel extends ClickableFieldModel {
|
|
16
44
|
public renderComponent(value) {
|
|
17
45
|
const { className, style } = this.props;
|
|
18
|
-
const finalFormat = this.props
|
|
46
|
+
const finalFormat = resolveDisplayDateTimeFormat(this.props);
|
|
19
47
|
let formattedValue = '';
|
|
20
48
|
if (value) {
|
|
21
49
|
const day = dayjs(value);
|
|
@@ -9,18 +9,64 @@
|
|
|
9
9
|
|
|
10
10
|
import { EditableItemModel, FilterableItemModel, tExpr } from '@nocobase/flow-engine';
|
|
11
11
|
import { Input } from 'antd';
|
|
12
|
-
import
|
|
12
|
+
import type { InputProps, InputRef } from 'antd';
|
|
13
|
+
import React, { useEffect, useRef } from 'react';
|
|
13
14
|
import { customAlphabet as Alphabet } from 'nanoid';
|
|
14
15
|
import { FieldModel } from '../base/FieldModel';
|
|
15
16
|
import { ScanInput } from '../../../components/form/ScanInput';
|
|
16
17
|
|
|
18
|
+
function IMESafeInput(props: InputProps) {
|
|
19
|
+
const { value, onChange, onCompositionStart, onCompositionEnd, ...rest } = props;
|
|
20
|
+
const inputRef = useRef<InputRef>(null);
|
|
21
|
+
const previousValueRef = useRef(value);
|
|
22
|
+
const defaultValue = typeof value === 'bigint' ? String(value) : value;
|
|
23
|
+
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (Object.is(previousValueRef.current, value)) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
previousValueRef.current = value;
|
|
29
|
+
|
|
30
|
+
const input = inputRef.current?.input;
|
|
31
|
+
if (input) {
|
|
32
|
+
const nextValue = value == null ? '' : String(value);
|
|
33
|
+
if (input.value !== nextValue) {
|
|
34
|
+
input.value = nextValue;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}, [value]);
|
|
38
|
+
|
|
39
|
+
const getEventValue = (event: React.ChangeEvent<HTMLInputElement> | React.CompositionEvent<HTMLInputElement>) =>
|
|
40
|
+
event.currentTarget.value;
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<Input
|
|
44
|
+
{...rest}
|
|
45
|
+
ref={inputRef}
|
|
46
|
+
defaultValue={defaultValue}
|
|
47
|
+
onChange={(event) => {
|
|
48
|
+
previousValueRef.current = getEventValue(event);
|
|
49
|
+
onChange?.(event);
|
|
50
|
+
}}
|
|
51
|
+
onCompositionStart={(event) => {
|
|
52
|
+
previousValueRef.current = getEventValue(event);
|
|
53
|
+
onCompositionStart?.(event);
|
|
54
|
+
}}
|
|
55
|
+
onCompositionEnd={(event) => {
|
|
56
|
+
previousValueRef.current = getEventValue(event);
|
|
57
|
+
onCompositionEnd?.(event);
|
|
58
|
+
}}
|
|
59
|
+
/>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
17
63
|
export class InputFieldModel extends FieldModel {
|
|
18
64
|
render() {
|
|
19
65
|
if (this.props.enableScan) {
|
|
20
66
|
return <ScanInput {...this.props} />;
|
|
21
67
|
}
|
|
22
68
|
const { enableScan, disableManualInput, ...inputProps } = this.props;
|
|
23
|
-
return <
|
|
69
|
+
return <IMESafeInput {...inputProps} />;
|
|
24
70
|
}
|
|
25
71
|
}
|
|
26
72
|
|
|
@@ -15,17 +15,20 @@ import { MobileSelect } from './mobile-components/MobileSelect';
|
|
|
15
15
|
import { enumToOptions, getSelectedEnumLabels, translateOptionLabel } from '../../internal/utils/enumOptionsUtils';
|
|
16
16
|
|
|
17
17
|
const getOriginalEnumOptions = (model: SelectFieldModel) => {
|
|
18
|
-
const fromEnum = enumToOptions(model.context.collectionField?.uiSchema?.enum,
|
|
18
|
+
const fromEnum = enumToOptions(model.context.collectionField?.uiSchema?.enum, model.translate) || [];
|
|
19
19
|
if (fromEnum.length > 0) {
|
|
20
20
|
return fromEnum.map((option) => ({ ...option }));
|
|
21
21
|
}
|
|
22
22
|
const current = Array.isArray(model.props.options) ? model.props.options : [];
|
|
23
|
-
return current.map((option) => ({
|
|
23
|
+
return current.map((option) => ({
|
|
24
|
+
...option,
|
|
25
|
+
label: translateOptionLabel(option.label, model.translate),
|
|
26
|
+
}));
|
|
24
27
|
};
|
|
25
|
-
|
|
26
28
|
export class SelectFieldModel extends FieldModel {
|
|
27
29
|
render() {
|
|
28
30
|
const fallbackOptions = getOriginalEnumOptions(this);
|
|
31
|
+
|
|
29
32
|
const options = this.props.options?.map((v) => {
|
|
30
33
|
return {
|
|
31
34
|
...v,
|
|
@@ -46,7 +49,6 @@ export class SelectFieldModel extends FieldModel {
|
|
|
46
49
|
if (this.context.isMobileLayout) {
|
|
47
50
|
return <MobileSelect {...this.props} options={options} displayValue={value} />;
|
|
48
51
|
}
|
|
49
|
-
|
|
50
52
|
return (
|
|
51
53
|
<Select
|
|
52
54
|
{...this.props}
|