@nocobase/client-v2 2.3.0-alpha.1 → 3.0.0-alpha.2
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/acl/ACLProvider.d.ts +10 -0
- package/es/authRedirect.d.ts +5 -0
- package/es/components/AttachmentUpload.d.ts +51 -0
- package/es/components/form/ScanInput/useCodeScanner.d.ts +2 -2
- package/es/components/index.d.ts +1 -0
- package/es/flow/actions/linkageRules.d.ts +1 -0
- package/es/flow/admin-shell/admin-layout/NocoBaseLogo.d.ts +10 -0
- package/es/flow/components/FlowRoute.d.ts +2 -2
- package/es/flow/internal/registerDeviceTypeContext.d.ts +10 -0
- package/es/flow/models/base/ActionModelCore.d.ts +4 -2
- package/es/flow/models/base/BlockGridModel.d.ts +3 -0
- package/es/flow/models/blocks/table/TableColumnModel.d.ts +1 -0
- package/es/flow/models/fields/DateTimeFieldModel/dateLimit.d.ts +15 -7
- package/es/index.d.ts +4 -1
- package/es/index.mjs +139 -125
- package/es/nocobase-buildin-plugin/currentUserAuthStatus.d.ts +11 -0
- package/es/nocobase-buildin-plugin/index.d.ts +9 -0
- package/es/settings-app/SettingsApplication.d.ts +18 -0
- package/es/settings-app/SettingsBrand.d.ts +16 -0
- package/es/settings-app/SettingsBuildInPlugin.d.ts +9 -0
- package/es/settings-app/SettingsDocumentRedirect.d.ts +10 -0
- package/es/settings-app/SettingsGroupNav.d.ts +17 -0
- package/es/settings-app/SettingsPluginSettingsManager.d.ts +14 -0
- package/es/settings-app/SettingsRouterManager.d.ts +15 -0
- package/es/settings-app/SettingsSearch.d.ts +17 -0
- package/es/settings-app/SettingsShell.d.ts +10 -0
- package/es/settings-app/isSettingsApp.d.ts +18 -0
- package/es/settings-app/runtimePaths.d.ts +18 -0
- package/es/settings-app/settingsDocumentPath.d.ts +14 -0
- package/es/settings-app/settingsTheme.d.ts +87 -0
- package/es/settings-app/useSettingsThemeConfig.d.ts +22 -0
- package/es/settings-center/AdminSettingsLayout.d.ts +2 -2
- package/es/settings-center/groups.d.ts +66 -0
- package/es/settings-center/useSettingsGroups.d.ts +36 -0
- package/es/settings-center/useSettingsSearch.d.ts +35 -0
- package/es/settings-center/utils.d.ts +24 -0
- package/es/theme/index.d.ts +1 -0
- package/es/theme/itemActive.d.ts +24 -0
- package/es/theme/type.d.ts +9 -0
- package/lib/index.js +141 -127
- package/lib/locale/languageCodes.js +1 -0
- package/package.json +8 -7
- package/src/__tests__/authRedirect.test.ts +137 -0
- package/src/__tests__/browserChecker.test.ts +124 -6
- package/src/__tests__/mockSettingsApplication.ts +29 -0
- package/src/__tests__/nocobase-buildin-plugin-auth.test.tsx +51 -10
- package/src/__tests__/plugin-manager.test.tsx +7 -6
- package/src/__tests__/settings-application.test.ts +164 -0
- package/src/__tests__/settings-auth-routes.test.ts +71 -0
- package/src/__tests__/settings-center.test.tsx +38 -37
- package/src/__tests__/settings-layout-root.test.tsx +260 -0
- package/src/__tests__/settings-runtime-paths.test.ts +99 -0
- package/src/__tests__/settings-shell.test.tsx +200 -0
- package/src/acl/ACLProvider.tsx +21 -0
- package/src/authRedirect.ts +72 -3
- package/src/components/AttachmentUpload.tsx +275 -0
- package/src/components/form/ScanInput/CodeScanner.tsx +61 -34
- package/src/components/form/ScanInput/__tests__/CodeScanner.test.tsx +101 -0
- package/src/components/form/ScanInput/__tests__/useCodeScanner.test.tsx +114 -18
- package/src/components/form/ScanInput/useCodeScanner.ts +166 -23
- package/src/components/index.ts +1 -0
- package/src/flow/__tests__/FlowRoute.test.tsx +126 -8
- package/src/flow/__tests__/PluginFlowEngine.test.ts +58 -0
- package/src/flow/actions/__tests__/actionLinkageRules.forkProps.test.ts +314 -0
- package/src/flow/actions/__tests__/dataScopeFormValueClear.test.ts +102 -0
- package/src/flow/actions/linkageRules.tsx +26 -6
- package/src/flow/admin-shell/admin-layout/AdminLayoutComponent.tsx +1 -56
- package/src/flow/admin-shell/admin-layout/NocoBaseLogo.tsx +77 -0
- package/src/flow/admin-shell/admin-layout/TopbarActionsBar.tsx +37 -14
- package/src/flow/admin-shell/admin-layout/__tests__/TopbarActionsBar.test.tsx +77 -13
- package/src/flow/common/Markdown/style.ts +4 -0
- package/src/flow/components/BlockItemCard.tsx +2 -2
- package/src/flow/components/FlowRoute.tsx +71 -29
- package/src/flow/index.ts +2 -0
- package/src/flow/internal/registerDeviceTypeContext.ts +39 -0
- package/src/flow/models/base/ActionModelCore.tsx +11 -2
- package/src/flow/models/base/BlockGridModel.tsx +26 -0
- package/src/flow/models/base/CollectionBlockModel.tsx +6 -2
- package/src/flow/models/base/PageModel/PageTabModel.tsx +67 -17
- package/src/flow/models/base/PageModel/__tests__/PageTabModel.test.ts +509 -12
- package/src/flow/models/base/__tests__/ActionModelCore.render.test.tsx +49 -0
- package/src/flow/models/base/__tests__/BlockGridModel.selectSceneActivation.test.ts +124 -0
- package/src/flow/models/base/__tests__/CollectionBlockModel.addAppends.test.ts +41 -0
- package/src/flow/models/blocks/filter-form/FilterFormBlockModel.tsx +27 -3
- package/src/flow/models/blocks/filter-form/__tests__/defaultValues.wiring.test.ts +32 -4
- package/src/flow/models/blocks/js-block/JSBlock.tsx +1 -1
- package/src/flow/models/blocks/table/TableBlockModel.tsx +3 -1
- package/src/flow/models/blocks/table/TableColumnModel.tsx +30 -1
- package/src/flow/models/blocks/table/__tests__/TableBlockModel.quickEditRefresh.test.ts +12 -0
- package/src/flow/models/blocks/table/__tests__/TableColumnModel.test.tsx +33 -0
- package/src/flow/models/fields/DateTimeFieldModel/__tests__/DateTimeNoTzFieldModel.dateLimit.test.tsx +149 -0
- package/src/flow/models/fields/DateTimeFieldModel/dateLimit.ts +149 -113
- package/src/flow/models/fields/JsonFieldModel.tsx +31 -8
- package/src/flow/models/fields/__tests__/JsonFieldModel.test.ts +82 -0
- package/src/flow/models/topbar/TopbarActionModel.tsx +52 -180
- package/src/flow/utils/dataScopeFormValueClear.ts +4 -3
- package/src/index.ts +10 -1
- package/src/locale/languageCodes.ts +1 -0
- package/src/nocobase-buildin-plugin/currentUserAuthStatus.ts +58 -0
- package/src/nocobase-buildin-plugin/index.tsx +99 -71
- package/src/settings-app/SettingsApplication.ts +31 -0
- package/src/settings-app/SettingsBrand.tsx +108 -0
- package/src/settings-app/SettingsBuildInPlugin.ts +10 -0
- package/src/settings-app/SettingsDocumentRedirect.tsx +26 -0
- package/src/settings-app/SettingsGroupNav.tsx +124 -0
- package/src/settings-app/SettingsPluginSettingsManager.ts +38 -0
- package/src/settings-app/SettingsRouterManager.ts +92 -0
- package/src/settings-app/SettingsSearch.tsx +238 -0
- package/src/settings-app/SettingsShell.tsx +167 -0
- package/src/settings-app/isSettingsApp.ts +21 -0
- package/src/settings-app/runtimePaths.ts +104 -0
- package/src/settings-app/settingsDocumentPath.ts +66 -0
- package/src/settings-app/settingsTheme.ts +301 -0
- package/src/settings-app/useSettingsThemeConfig.ts +100 -0
- package/src/settings-center/AdminSettingsLayout.tsx +122 -141
- package/src/settings-center/SystemSettingsPage.tsx +4 -170
- package/src/settings-center/groups.ts +108 -0
- package/src/settings-center/useSettingsGroups.ts +105 -0
- package/src/settings-center/useSettingsSearch.ts +173 -0
- package/src/settings-center/utils.tsx +50 -1
- package/src/theme/index.tsx +1 -0
- package/src/theme/itemActive.ts +31 -0
- package/src/theme/type.ts +10 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { FlowEngine, type FlowModelContext, MultiRecordResource, VIEW_ACTIVATED_EVENT } from '@nocobase/flow-engine';
|
|
11
|
+
import { beforeEach, describe, expect, it } from 'vitest';
|
|
12
|
+
import { BlockGridModel } from '../BlockGridModel';
|
|
13
|
+
import { CollectionBlockModel } from '../CollectionBlockModel';
|
|
14
|
+
|
|
15
|
+
class TestBlockGridModel extends BlockGridModel {
|
|
16
|
+
mountForTest() {
|
|
17
|
+
super.onMount();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
unmountForTest() {
|
|
21
|
+
super.onUnmount();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
class TestMultiRecordResource extends MultiRecordResource<Record<string, unknown>> {
|
|
26
|
+
refreshCalls = 0;
|
|
27
|
+
|
|
28
|
+
override async refresh(): Promise<void> {
|
|
29
|
+
this.refreshCalls += 1;
|
|
30
|
+
this.emit('refresh');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
class TestCollectionBlockModel extends CollectionBlockModel {
|
|
35
|
+
createResource(ctx: FlowModelContext) {
|
|
36
|
+
return ctx.createResource(TestMultiRecordResource);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
mountForTest() {
|
|
40
|
+
super.onMount();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
describe('BlockGridModel - select scene activation', () => {
|
|
45
|
+
let engine: FlowEngine;
|
|
46
|
+
|
|
47
|
+
beforeEach(() => {
|
|
48
|
+
engine = new FlowEngine();
|
|
49
|
+
engine.context.defineProperty('location', { value: { search: '' } });
|
|
50
|
+
engine.registerModels({ TestBlockGridModel, TestCollectionBlockModel });
|
|
51
|
+
|
|
52
|
+
engine.dataSourceManager.getDataSource('main').addCollection({
|
|
53
|
+
name: 'roles',
|
|
54
|
+
filterTargetKey: 'id',
|
|
55
|
+
fields: [
|
|
56
|
+
{ name: 'id', type: 'integer', interface: 'number' },
|
|
57
|
+
{ name: 'name', type: 'string', interface: 'input' },
|
|
58
|
+
],
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
function createModels(scene = 'select') {
|
|
63
|
+
engine.context.defineProperty('view', { value: { inputArgs: { scene } } });
|
|
64
|
+
const grid = engine.createModel<TestBlockGridModel>({ use: 'TestBlockGridModel' });
|
|
65
|
+
const block = grid.addSubModel<TestCollectionBlockModel>('items', {
|
|
66
|
+
use: 'TestCollectionBlockModel',
|
|
67
|
+
stepParams: {
|
|
68
|
+
resourceSettings: {
|
|
69
|
+
init: {
|
|
70
|
+
dataSourceKey: 'main',
|
|
71
|
+
collectionName: 'roles',
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
const resource = block.context.resource as TestMultiRecordResource;
|
|
77
|
+
|
|
78
|
+
block.mountForTest();
|
|
79
|
+
grid.mountForTest();
|
|
80
|
+
return { grid, resource };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
it('refreshes dirty collection blocks once when a nested view closes', async () => {
|
|
84
|
+
const { grid, resource } = createModels();
|
|
85
|
+
|
|
86
|
+
engine.markDataSourceDirty('main', 'roles');
|
|
87
|
+
engine.emitter.emit(VIEW_ACTIVATED_EVENT);
|
|
88
|
+
await Promise.resolve();
|
|
89
|
+
|
|
90
|
+
expect(resource.refreshCalls).toBe(1);
|
|
91
|
+
|
|
92
|
+
engine.emitter.emit(VIEW_ACTIVATED_EVENT);
|
|
93
|
+
await Promise.resolve();
|
|
94
|
+
|
|
95
|
+
expect(resource.refreshCalls).toBe(1);
|
|
96
|
+
grid.unmountForTest();
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('does not refresh without dirty data or after the grid unmounts', async () => {
|
|
100
|
+
const { grid, resource } = createModels();
|
|
101
|
+
|
|
102
|
+
engine.emitter.emit(VIEW_ACTIVATED_EVENT);
|
|
103
|
+
await Promise.resolve();
|
|
104
|
+
expect(resource.refreshCalls).toBe(0);
|
|
105
|
+
|
|
106
|
+
grid.unmountForTest();
|
|
107
|
+
engine.markDataSourceDirty('main', 'roles');
|
|
108
|
+
engine.emitter.emit(VIEW_ACTIVATED_EVENT);
|
|
109
|
+
await Promise.resolve();
|
|
110
|
+
|
|
111
|
+
expect(resource.refreshCalls).toBe(0);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('does not handle activation outside the select scene', async () => {
|
|
115
|
+
const { grid, resource } = createModels('list');
|
|
116
|
+
|
|
117
|
+
engine.markDataSourceDirty('main', 'roles');
|
|
118
|
+
engine.emitter.emit(VIEW_ACTIVATED_EVENT);
|
|
119
|
+
await Promise.resolve();
|
|
120
|
+
|
|
121
|
+
expect(resource.refreshCalls).toBe(0);
|
|
122
|
+
grid.unmountForTest();
|
|
123
|
+
});
|
|
124
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { FlowEngine, FlowModelContext, MultiRecordResource } from '@nocobase/flow-engine';
|
|
11
|
+
import { describe, expect, it } from 'vitest';
|
|
12
|
+
import { CollectionBlockModel } from '../CollectionBlockModel';
|
|
13
|
+
|
|
14
|
+
class AddAppendsCollectionBlockModel extends CollectionBlockModel {
|
|
15
|
+
createResource(ctx: FlowModelContext) {
|
|
16
|
+
return ctx.createResource(MultiRecordResource);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
describe('CollectionBlockModel addAppends', () => {
|
|
21
|
+
it('does not throw for a nested field path when the collection is unavailable', () => {
|
|
22
|
+
const engine = new FlowEngine();
|
|
23
|
+
engine.registerModels({ AddAppendsCollectionBlockModel });
|
|
24
|
+
|
|
25
|
+
const model = engine.createModel<AddAppendsCollectionBlockModel>({
|
|
26
|
+
uid: 'missing-collection-add-appends-block',
|
|
27
|
+
use: 'AddAppendsCollectionBlockModel',
|
|
28
|
+
stepParams: {
|
|
29
|
+
resourceSettings: {
|
|
30
|
+
init: {
|
|
31
|
+
dataSourceKey: 'main',
|
|
32
|
+
collectionName: 'missing_collection',
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
expect(model.collection).toBeUndefined();
|
|
39
|
+
expect(() => model.addAppends('createdBy.departments')).not.toThrow();
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -15,8 +15,10 @@ import {
|
|
|
15
15
|
DndProvider,
|
|
16
16
|
DragHandler,
|
|
17
17
|
Droppable,
|
|
18
|
+
isCtxDateExpression,
|
|
18
19
|
isRunJSValue,
|
|
19
20
|
normalizeRunJSValue,
|
|
21
|
+
parseCtxDateExpression,
|
|
20
22
|
tExpr,
|
|
21
23
|
FlowModelRenderer,
|
|
22
24
|
FlowSettingsButton,
|
|
@@ -44,6 +46,15 @@ import { normalizeFilterValueByOperator } from './valueNormalization';
|
|
|
44
46
|
|
|
45
47
|
const RELATION_FIELD_TYPES = ['belongsTo', 'hasOne', 'hasMany', 'belongsToMany', 'belongsToArray'];
|
|
46
48
|
const NUMERIC_FIELD_TYPES = ['integer', 'float', 'double', 'decimal'];
|
|
49
|
+
const DATE_FILTER_OPERATORS = new Set([
|
|
50
|
+
'$dateOn',
|
|
51
|
+
'$dateNotOn',
|
|
52
|
+
'$dateBefore',
|
|
53
|
+
'$dateAfter',
|
|
54
|
+
'$dateNotBefore',
|
|
55
|
+
'$dateNotAfter',
|
|
56
|
+
'$dateBetween',
|
|
57
|
+
]);
|
|
47
58
|
|
|
48
59
|
function getFilterFormFieldMetaType(field: CollectionField) {
|
|
49
60
|
if (RELATION_FIELD_TYPES.includes(field.type)) {
|
|
@@ -66,6 +77,14 @@ function getFilterFormFieldMetaType(field: CollectionField) {
|
|
|
66
77
|
}
|
|
67
78
|
}
|
|
68
79
|
|
|
80
|
+
function parseDateFilterDefaultValue(operator: string | undefined, rawValue: unknown) {
|
|
81
|
+
if (!operator || !DATE_FILTER_OPERATORS.has(operator) || !isCtxDateExpression(rawValue)) {
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return parseCtxDateExpression(rawValue);
|
|
86
|
+
}
|
|
87
|
+
|
|
69
88
|
function shouldShowFilterFormFieldMeta(field: CollectionField) {
|
|
70
89
|
return Boolean(field?.interface);
|
|
71
90
|
}
|
|
@@ -489,7 +508,7 @@ export class FilterFormBlockModel extends FilterBlockModel<{
|
|
|
489
508
|
const rules = (params?.value || []) as any[];
|
|
490
509
|
if (!Array.isArray(rules) || rules.length === 0) return appliedValues;
|
|
491
510
|
|
|
492
|
-
const resolveValue = async (raw: any) => {
|
|
511
|
+
const resolveValue = async (raw: any, operator?: string) => {
|
|
493
512
|
// RunJS support
|
|
494
513
|
if (isRunJSValue(raw)) {
|
|
495
514
|
const { code, version } = normalizeRunJSValue(raw);
|
|
@@ -497,6 +516,11 @@ export class FilterFormBlockModel extends FilterBlockModel<{
|
|
|
497
516
|
return ret?.success ? ret.value : undefined;
|
|
498
517
|
}
|
|
499
518
|
|
|
519
|
+
const parsedDateFilterValue = parseDateFilterDefaultValue(operator, raw);
|
|
520
|
+
if (typeof parsedDateFilterValue !== 'undefined') {
|
|
521
|
+
return parsedDateFilterValue;
|
|
522
|
+
}
|
|
523
|
+
|
|
500
524
|
return await (this.context as any).resolveJsonTemplate?.(raw);
|
|
501
525
|
};
|
|
502
526
|
|
|
@@ -520,11 +544,11 @@ export class FilterFormBlockModel extends FilterBlockModel<{
|
|
|
520
544
|
|
|
521
545
|
const current = (form as any).getFieldValue?.(name);
|
|
522
546
|
|
|
523
|
-
const
|
|
547
|
+
const operator = getDefaultOperator(itemModel as any);
|
|
548
|
+
const resolved = await resolveValue(rule.value, operator);
|
|
524
549
|
if (options?.refreshSeq && options.refreshSeq !== this.defaultValuesRefreshSeq) return appliedValues;
|
|
525
550
|
if (typeof resolved === 'undefined') continue;
|
|
526
551
|
|
|
527
|
-
const operator = getDefaultOperator(itemModel as any);
|
|
528
552
|
const normalized = normalizeFilterValueByOperator(operator, resolved);
|
|
529
553
|
const mode = this.normalizeFieldValueMode(rule.mode);
|
|
530
554
|
if (mode === 'default' && !this.canApplyFormDefaultValue(String(name), current, force)) continue;
|
|
@@ -17,7 +17,15 @@ import { FilterFormBlockModel } from '../FilterFormBlockModel';
|
|
|
17
17
|
function resolveTemplateValue(raw: any, values: Record<string, any>): any {
|
|
18
18
|
if (typeof raw === 'string') {
|
|
19
19
|
const matched = raw.match(/^\{\{\s*ctx\.formValues\.([^}]+?)\s*\}\}$/);
|
|
20
|
-
|
|
20
|
+
if (matched) {
|
|
21
|
+
return values[matched[1]];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (/^\{\{\s*ctx\.date\.relative\.past\.day\.n7\s*\}\}$/.test(raw)) {
|
|
25
|
+
return '2026-06-15';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return raw;
|
|
21
29
|
}
|
|
22
30
|
if (Array.isArray(raw)) {
|
|
23
31
|
return raw.map((item) => resolveTemplateValue(item, values));
|
|
@@ -30,7 +38,7 @@ function resolveTemplateValue(raw: any, values: Record<string, any>): any {
|
|
|
30
38
|
|
|
31
39
|
function createFilterFormDefaultValuesModel(rules: any[], initialValues: Record<string, any> = {}) {
|
|
32
40
|
const values = { ...initialValues };
|
|
33
|
-
const createItem = (fieldPath: string, uid: string) => ({
|
|
41
|
+
const createItem = (fieldPath: string, uid: string, operator?: string) => ({
|
|
34
42
|
uid,
|
|
35
43
|
fieldPath,
|
|
36
44
|
props: { name: `${fieldPath}_${uid}` },
|
|
@@ -44,7 +52,7 @@ function createFilterFormDefaultValuesModel(rules: any[], initialValues: Record<
|
|
|
44
52
|
return undefined;
|
|
45
53
|
},
|
|
46
54
|
subModels: {
|
|
47
|
-
field: {},
|
|
55
|
+
field: operator ? { operator } : {},
|
|
48
56
|
},
|
|
49
57
|
});
|
|
50
58
|
const model = {
|
|
@@ -76,7 +84,11 @@ function createFilterFormDefaultValuesModel(rules: any[], initialValues: Record<
|
|
|
76
84
|
subModels: {
|
|
77
85
|
grid: {
|
|
78
86
|
subModels: {
|
|
79
|
-
items: [
|
|
87
|
+
items: [
|
|
88
|
+
createItem('nickname', 'nick'),
|
|
89
|
+
createItem('username', 'user'),
|
|
90
|
+
createItem('birthdate_tz', 'birthdate', '$dateOn'),
|
|
91
|
+
],
|
|
80
92
|
},
|
|
81
93
|
},
|
|
82
94
|
},
|
|
@@ -354,6 +366,22 @@ describe('filter-form defaultValues wiring', () => {
|
|
|
354
366
|
expect(values.username_user).toBe('Bob');
|
|
355
367
|
});
|
|
356
368
|
|
|
369
|
+
it('preserves relative date descriptors for date filter default values', async () => {
|
|
370
|
+
const { model, values } = createFilterFormDefaultValuesModel([
|
|
371
|
+
{
|
|
372
|
+
key: 'birthdate-default',
|
|
373
|
+
enable: true,
|
|
374
|
+
targetPath: 'birthdate_tz',
|
|
375
|
+
mode: 'assign',
|
|
376
|
+
value: '{{ ctx.date.relative.past.day.n7 }}',
|
|
377
|
+
},
|
|
378
|
+
]);
|
|
379
|
+
|
|
380
|
+
await FilterFormBlockModel.prototype.applyFormDefaultValues.call(model as any);
|
|
381
|
+
|
|
382
|
+
expect(values.birthdate_tz_birthdate).toEqual({ type: 'past', unit: 'day', number: 7 });
|
|
383
|
+
});
|
|
384
|
+
|
|
357
385
|
it('applies override values until the target filter field is changed by user', async () => {
|
|
358
386
|
const { model, values } = createFilterFormDefaultValuesModel(
|
|
359
387
|
[
|
|
@@ -235,7 +235,7 @@ export class JSBlockModel extends BlockModel {
|
|
|
235
235
|
const cardProps = {
|
|
236
236
|
...rest,
|
|
237
237
|
height,
|
|
238
|
-
style,
|
|
238
|
+
...(style === undefined ? {} : { style }),
|
|
239
239
|
...(beforeContent === undefined ? {} : { beforeContent }),
|
|
240
240
|
...(afterContent === undefined ? {} : { afterContent }),
|
|
241
241
|
};
|
|
@@ -244,7 +244,9 @@ export class TableBlockModel extends CollectionBlockModel<TableBlockModelStructu
|
|
|
244
244
|
}
|
|
245
245
|
|
|
246
246
|
createResource(ctx, params) {
|
|
247
|
-
|
|
247
|
+
const resource = this.context.createResource(MultiRecordResource);
|
|
248
|
+
resource.addRequestHeader('X-With-ACL-Meta', 'true');
|
|
249
|
+
return resource;
|
|
248
250
|
}
|
|
249
251
|
|
|
250
252
|
/**
|
|
@@ -194,6 +194,35 @@ export class TableColumnModel extends DisplayItemModel {
|
|
|
194
194
|
.filter(Boolean);
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
+
canQuickEdit(record: Record<string, unknown>): boolean {
|
|
198
|
+
if (!this.props.editable) {
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
if (this.context.skipAclCheck) {
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const blockModel = this.context.blockModel;
|
|
206
|
+
const collection = blockModel?.collection;
|
|
207
|
+
const resource = blockModel?.resource;
|
|
208
|
+
const collectionField = this.collectionField;
|
|
209
|
+
if (!collection || !resource || !collectionField) {
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const filterByTk = collection.getFilterByTK(record);
|
|
214
|
+
const recordPkValue = typeof filterByTk === 'string' || typeof filterByTk === 'number' ? filterByTk : undefined;
|
|
215
|
+
|
|
216
|
+
return this.context.acl.can({
|
|
217
|
+
dataSourceKey: collection.dataSourceKey,
|
|
218
|
+
resourceName: resource.getResourceName() || collection.name,
|
|
219
|
+
actionName: 'update',
|
|
220
|
+
recordPkValue,
|
|
221
|
+
allowedActions: resource.getMeta('allowedActions'),
|
|
222
|
+
fields: [collectionField.name],
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
|
|
197
226
|
getColumnProps(): TableColumnProps & { sortField?: string } {
|
|
198
227
|
if (!this.props.width) {
|
|
199
228
|
return;
|
|
@@ -250,7 +279,7 @@ export class TableColumnModel extends DisplayItemModel {
|
|
|
250
279
|
record,
|
|
251
280
|
recordIndex: record?.__index || recordIndex,
|
|
252
281
|
width: this.props.width - 16,
|
|
253
|
-
editable: this.
|
|
282
|
+
editable: this.canQuickEdit(record),
|
|
254
283
|
dataIndex: this.props.dataIndex,
|
|
255
284
|
title: this.props.title,
|
|
256
285
|
overflowMode: this.props.overflowMode,
|
|
@@ -9,8 +9,20 @@
|
|
|
9
9
|
|
|
10
10
|
import { FlowEngine, MultiRecordResource } from '@nocobase/flow-engine';
|
|
11
11
|
import { describe, expect, it } from 'vitest';
|
|
12
|
+
import { TableBlockModel } from '../TableBlockModel';
|
|
12
13
|
|
|
13
14
|
describe('TableBlockModel quick edit refresh', () => {
|
|
15
|
+
it('requests record-level ACL metadata for table data', () => {
|
|
16
|
+
const engine = new FlowEngine();
|
|
17
|
+
const model = {
|
|
18
|
+
context: engine.context,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const resource = TableBlockModel.prototype.createResource.call(model, {}, {});
|
|
22
|
+
|
|
23
|
+
expect(resource.getRequestOptions().headers['X-With-ACL-Meta']).toBe('true');
|
|
24
|
+
});
|
|
25
|
+
|
|
14
26
|
it('updates table data through a new array reference after quick editing a flat row', () => {
|
|
15
27
|
const engine = new FlowEngine();
|
|
16
28
|
const resource = engine.context.createResource(MultiRecordResource);
|
|
@@ -66,6 +66,39 @@ describe('TableColumnModel sorter settings', () => {
|
|
|
66
66
|
expect(setProps).toHaveBeenCalledWith('editable', false);
|
|
67
67
|
});
|
|
68
68
|
|
|
69
|
+
it('checks record update scope and field permission before enabling quick edit', () => {
|
|
70
|
+
const can = vi.fn(() => false);
|
|
71
|
+
const model = {
|
|
72
|
+
props: { editable: true },
|
|
73
|
+
collectionField: { name: 'title' },
|
|
74
|
+
context: {
|
|
75
|
+
skipAclCheck: false,
|
|
76
|
+
acl: { can },
|
|
77
|
+
blockModel: {
|
|
78
|
+
collection: {
|
|
79
|
+
dataSourceKey: 'main',
|
|
80
|
+
name: 'posts',
|
|
81
|
+
getFilterByTK: () => 2,
|
|
82
|
+
},
|
|
83
|
+
resource: {
|
|
84
|
+
getResourceName: () => 'posts',
|
|
85
|
+
getMeta: () => ({ update: [1] }),
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
expect(TableColumnModel.prototype.canQuickEdit.call(model, { id: 2 })).toBe(false);
|
|
92
|
+
expect(can).toHaveBeenCalledWith({
|
|
93
|
+
dataSourceKey: 'main',
|
|
94
|
+
resourceName: 'posts',
|
|
95
|
+
actionName: 'update',
|
|
96
|
+
recordPkValue: 2,
|
|
97
|
+
allowedActions: { update: [1] },
|
|
98
|
+
fields: ['title'],
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
69
102
|
it('hides sortable setting for association fields', async () => {
|
|
70
103
|
const engine = new FlowEngine();
|
|
71
104
|
const model = new TableColumnModel({ uid: 'table-column-association-sorter', flowEngine: engine } as any);
|
|
@@ -17,6 +17,8 @@ import { DateTimeNoTzPicker } from '../DateTimeNoTzFieldModel';
|
|
|
17
17
|
let capturedDatePickerProps: any;
|
|
18
18
|
let currentForm: any;
|
|
19
19
|
const mockResolveJsonTemplate = vi.fn();
|
|
20
|
+
const mockRunjs = vi.fn();
|
|
21
|
+
const mockLoggerWarn = vi.fn();
|
|
20
22
|
|
|
21
23
|
vi.mock('@nocobase/flow-engine', async (importOriginal) => {
|
|
22
24
|
const actual = await importOriginal<typeof import('@nocobase/flow-engine')>();
|
|
@@ -32,6 +34,10 @@ vi.mock('@nocobase/flow-engine', async (importOriginal) => {
|
|
|
32
34
|
}),
|
|
33
35
|
useFlowContext: () => ({
|
|
34
36
|
resolveJsonTemplate: mockResolveJsonTemplate,
|
|
37
|
+
runjs: mockRunjs,
|
|
38
|
+
logger: {
|
|
39
|
+
warn: mockLoggerWarn,
|
|
40
|
+
},
|
|
35
41
|
}),
|
|
36
42
|
};
|
|
37
43
|
});
|
|
@@ -64,6 +70,9 @@ describe('DateTimeNoTzPicker date range limit', () => {
|
|
|
64
70
|
currentForm = undefined;
|
|
65
71
|
capturedDatePickerProps = undefined;
|
|
66
72
|
mockResolveJsonTemplate.mockReset();
|
|
73
|
+
mockRunjs.mockReset();
|
|
74
|
+
mockLoggerWarn.mockReset();
|
|
75
|
+
mockRunjs.mockResolvedValue({ success: true, value: undefined });
|
|
67
76
|
mockResolveJsonTemplate.mockImplementation(async (params) => ({
|
|
68
77
|
...params,
|
|
69
78
|
_maxDate: currentForm?.getFieldValue?.('b'),
|
|
@@ -239,4 +248,144 @@ describe('DateTimeNoTzPicker date range limit', () => {
|
|
|
239
248
|
expect(timeConfig?.disabledMinutes?.(12)).toEqual([]);
|
|
240
249
|
expect(timeConfig?.disabledSeconds?.(12, 34)).toEqual([]);
|
|
241
250
|
});
|
|
251
|
+
|
|
252
|
+
it('evaluates RunJS before applying minDate', async () => {
|
|
253
|
+
const code = 'return new Date("2026-05-10T08:09:10.000Z").toISOString();';
|
|
254
|
+
mockRunjs.mockResolvedValue({ success: true, value: '2026-05-10T08:09:10.000Z' });
|
|
255
|
+
mockResolveJsonTemplate.mockImplementation(async (params) => params);
|
|
256
|
+
|
|
257
|
+
render(<TestWrapper picker="date" showTime _minDate={{ code, version: 'v2' }} onChange={vi.fn()} value={null} />);
|
|
258
|
+
|
|
259
|
+
await waitFor(() => {
|
|
260
|
+
expect(capturedDatePickerProps?.disabledDate?.(dayjs('2026-05-09 00:00:00'))).toBe(true);
|
|
261
|
+
expect(capturedDatePickerProps?.disabledDate?.(dayjs('2026-05-10 00:00:00'))).toBe(false);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
expect(mockRunjs.mock.calls[0]?.[0]).toBe(code);
|
|
265
|
+
expect(mockRunjs.mock.calls[0]?.[2]).toEqual({ version: 'v2' });
|
|
266
|
+
expect(mockResolveJsonTemplate).toHaveBeenCalledWith({
|
|
267
|
+
_minDate: '2026-05-10T08:09:10.000Z',
|
|
268
|
+
_maxDate: undefined,
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
it('supports a RunJS minDate together with a variable maxDate', async () => {
|
|
273
|
+
mockRunjs.mockResolvedValue({ success: true, value: '2026-05-10 08:00:00' });
|
|
274
|
+
mockResolveJsonTemplate.mockImplementation(async (params) => ({
|
|
275
|
+
...params,
|
|
276
|
+
_maxDate: '2026-05-12 18:30:40',
|
|
277
|
+
}));
|
|
278
|
+
|
|
279
|
+
render(
|
|
280
|
+
<TestWrapper
|
|
281
|
+
picker="date"
|
|
282
|
+
showTime
|
|
283
|
+
_minDate={{ code: 'return "2026-05-10 08:00:00";', version: 'v2' }}
|
|
284
|
+
_maxDate={'{{ $nForm.max }}'}
|
|
285
|
+
onChange={vi.fn()}
|
|
286
|
+
value={null}
|
|
287
|
+
/>,
|
|
288
|
+
);
|
|
289
|
+
|
|
290
|
+
await waitFor(() => {
|
|
291
|
+
expect(capturedDatePickerProps?.disabledDate?.(dayjs('2026-05-09 00:00:00'))).toBe(true);
|
|
292
|
+
expect(capturedDatePickerProps?.disabledDate?.(dayjs('2026-05-13 00:00:00'))).toBe(true);
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
expect(capturedDatePickerProps?.disabledDate?.(dayjs('2026-05-11 00:00:00'))).toBe(false);
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
it('clears stale restrictions when RunJS execution fails', async () => {
|
|
299
|
+
mockResolveJsonTemplate.mockImplementation(async (params) => params);
|
|
300
|
+
mockRunjs.mockImplementation(async (code) => {
|
|
301
|
+
if (code === 'throw new Error("failed");') {
|
|
302
|
+
return { success: false, error: new Error('failed') };
|
|
303
|
+
}
|
|
304
|
+
return { success: true, value: '2026-05-10 08:00:00' };
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
const view = render(
|
|
308
|
+
<TestWrapper
|
|
309
|
+
picker="date"
|
|
310
|
+
showTime
|
|
311
|
+
_minDate={{ code: 'return "2026-05-10 08:00:00";', version: 'v2' }}
|
|
312
|
+
onChange={vi.fn()}
|
|
313
|
+
value={null}
|
|
314
|
+
/>,
|
|
315
|
+
);
|
|
316
|
+
|
|
317
|
+
await waitFor(() => {
|
|
318
|
+
expect(capturedDatePickerProps?.disabledDate?.(dayjs('2026-05-09 00:00:00'))).toBe(true);
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
view.rerender(
|
|
322
|
+
<TestWrapper
|
|
323
|
+
picker="date"
|
|
324
|
+
showTime
|
|
325
|
+
_minDate={{ code: 'throw new Error("failed");', version: 'v2' }}
|
|
326
|
+
onChange={vi.fn()}
|
|
327
|
+
value={null}
|
|
328
|
+
/>,
|
|
329
|
+
);
|
|
330
|
+
|
|
331
|
+
await waitFor(() => {
|
|
332
|
+
expect(mockLoggerWarn).toHaveBeenCalled();
|
|
333
|
+
expect(capturedDatePickerProps?.minDate).toBeNull();
|
|
334
|
+
expect(capturedDatePickerProps?.disabledDate).toBeNull();
|
|
335
|
+
expect(capturedDatePickerProps?.disabledTime).toBeNull();
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
it('keeps the latest RunJS result when an earlier execution finishes later', async () => {
|
|
340
|
+
const slowResolvers: Array<(result: { success: boolean; value: string }) => void> = [];
|
|
341
|
+
mockResolveJsonTemplate.mockImplementation(async (params) => params);
|
|
342
|
+
mockRunjs.mockImplementation((code) => {
|
|
343
|
+
if (code === 'return "slow";') {
|
|
344
|
+
return new Promise((resolve) => {
|
|
345
|
+
slowResolvers.push(resolve);
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
return Promise.resolve({ success: true, value: '2026-06-01 00:00:00' });
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
const view = render(
|
|
352
|
+
<TestWrapper
|
|
353
|
+
picker="date"
|
|
354
|
+
showTime
|
|
355
|
+
_minDate={{ code: 'return "slow";', version: 'v2' }}
|
|
356
|
+
onChange={vi.fn()}
|
|
357
|
+
value={null}
|
|
358
|
+
/>,
|
|
359
|
+
);
|
|
360
|
+
|
|
361
|
+
await waitFor(() => {
|
|
362
|
+
expect(slowResolvers.length).toBeGreaterThan(0);
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
view.rerender(
|
|
366
|
+
<TestWrapper
|
|
367
|
+
picker="date"
|
|
368
|
+
showTime
|
|
369
|
+
_minDate={{ code: 'return "fast";', version: 'v2' }}
|
|
370
|
+
onChange={vi.fn()}
|
|
371
|
+
value={null}
|
|
372
|
+
/>,
|
|
373
|
+
);
|
|
374
|
+
|
|
375
|
+
await waitFor(() => {
|
|
376
|
+
expect(capturedDatePickerProps?.disabledDate?.(dayjs('2026-05-31 00:00:00'))).toBe(true);
|
|
377
|
+
expect(capturedDatePickerProps?.disabledDate?.(dayjs('2026-07-01 00:00:00'))).toBe(false);
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
slowResolvers.forEach((resolve) => resolve({ success: true, value: '2026-12-01 00:00:00' }));
|
|
381
|
+
|
|
382
|
+
await waitFor(() => {
|
|
383
|
+
expect(mockResolveJsonTemplate).toHaveBeenCalledWith({
|
|
384
|
+
_minDate: '2026-12-01 00:00:00',
|
|
385
|
+
_maxDate: undefined,
|
|
386
|
+
});
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
expect(capturedDatePickerProps?.disabledDate?.(dayjs('2026-07-01 00:00:00'))).toBe(false);
|
|
390
|
+
});
|
|
242
391
|
});
|