@nocobase/client-v2 2.2.0-beta.13 → 2.2.0-beta.15
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/APIClient.d.ts +1 -3
- package/es/components/category-tabs/SortableCategoryTabs.d.ts +55 -0
- package/es/components/category-tabs/index.d.ts +9 -0
- package/es/components/form/ScanInput/useCodeScanner.d.ts +2 -1
- package/es/components/form/TypedVariableInput.d.ts +31 -5
- package/es/components/form/filter/CollectionFilter.d.ts +2 -0
- package/es/components/form/filter/CollectionFilterItem.d.ts +11 -1
- package/es/components/form/filter/CollectionFilterPanel.d.ts +2 -0
- package/es/components/form/filter/index.d.ts +2 -0
- package/es/components/form/filter/useFilterActionProps.d.ts +2 -0
- package/es/components/index.d.ts +1 -0
- package/es/flow/actions/index.d.ts +1 -1
- package/es/flow/actions/linkageRules.d.ts +2 -0
- package/es/flow/admin-shell/admin-layout/AdminLayoutMenuModels.d.ts +1 -0
- package/es/flow/components/FieldAssignExactDatePicker.d.ts +1 -0
- package/es/flow/components/FieldAssignValueInput.d.ts +9 -0
- package/es/flow/components/RunJSValueEditor.d.ts +1 -0
- package/es/flow/components/filter/FilterGroup.d.ts +1 -0
- package/es/flow/components/filter/VariableFilterItem.d.ts +6 -1
- package/es/flow/index.d.ts +1 -0
- package/es/flow/models/base/PageModel/PageModel.d.ts +12 -0
- package/es/flow/models/base/PageModel/PageModelTabBar.d.ts +22 -0
- package/es/flow/models/base/PageModel/PageTabModel.d.ts +12 -0
- package/es/flow-compat/fieldValidationConstants.d.ts +1 -1
- package/es/flow-compat/routeTypes.d.ts +1 -0
- package/es/index.d.ts +4 -0
- package/es/index.mjs +144 -109
- package/es/utils/getRouteRuntimeVersion.d.ts +23 -0
- package/es/utils/index.d.ts +1 -0
- package/lib/index.js +153 -118
- package/lib/locale/languageCodes.js +2 -1
- package/package.json +7 -7
- package/src/APIClient.ts +1 -10
- package/src/Application.tsx +4 -0
- package/src/BaseApplication.tsx +1 -1
- package/src/__tests__/app.test.tsx +18 -0
- package/src/__tests__/browserChecker.test.ts +61 -0
- package/src/__tests__/getRouteRuntimeVersion.test.ts +68 -0
- package/src/__tests__/nocobase-buildin-plugin-auth.test.tsx +28 -0
- package/src/collection-manager/field-validation.ts +1 -1
- package/src/components/README.md +7 -1
- package/src/components/README.zh-CN.md +6 -1
- package/src/components/category-tabs/SortableCategoryTabs.tsx +210 -0
- package/src/components/category-tabs/index.ts +10 -0
- package/src/components/form/JsonTextArea.tsx +4 -0
- package/src/components/form/ScanInput/CodeScanner.tsx +23 -6
- package/src/components/form/ScanInput/__tests__/useCodeScanner.test.tsx +35 -1
- package/src/components/form/ScanInput/useCodeScanner.ts +16 -3
- package/src/components/form/TypedVariableInput.tsx +452 -101
- package/src/components/form/__tests__/TypedVariableInput.test.tsx +364 -12
- package/src/components/form/filter/CollectionFilter.tsx +4 -0
- package/src/components/form/filter/CollectionFilterItem.tsx +32 -7
- package/src/components/form/filter/CollectionFilterPanel.tsx +4 -0
- package/src/components/form/filter/__tests__/CollectionFilterItem.test.tsx +38 -0
- package/src/components/form/filter/__tests__/useFilterActionProps.test.tsx +95 -0
- package/src/components/form/filter/index.ts +2 -0
- package/src/components/form/filter/useFilterActionProps.ts +37 -6
- package/src/components/index.ts +1 -0
- package/src/flow/actions/__tests__/linkageRules.tab.test.ts +171 -0
- package/src/flow/actions/index.ts +2 -0
- package/src/flow/actions/linkageRules.tsx +86 -11
- package/src/flow/admin-shell/admin-layout/AdminLayoutComponent.tsx +0 -1
- package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutComponent.test.tsx +253 -6
- package/src/flow/components/FieldAssignExactDatePicker.tsx +25 -11
- package/src/flow/components/FieldAssignValueInput.tsx +76 -9
- package/src/flow/components/RunJSValueEditor.tsx +9 -1
- package/src/flow/components/__tests__/FieldAssignValueInput.context.test.tsx +84 -2
- package/src/flow/components/filter/FilterGroup.tsx +33 -5
- package/src/flow/components/filter/VariableFilterItem.tsx +158 -10
- package/src/flow/components/filter/__tests__/FilterGroup.test.tsx +45 -0
- package/src/flow/components/filter/__tests__/VariableFilterItem.leftMetaTree.test.tsx +9 -0
- package/src/flow/components/filter/__tests__/VariableFilterItem.test.tsx +70 -1
- package/src/flow/index.ts +1 -0
- package/src/flow/models/base/PageModel/PageModel.tsx +387 -53
- package/src/flow/models/base/PageModel/PageModelTabBar.tsx +114 -0
- package/src/flow/models/base/PageModel/PageTabModel.tsx +184 -3
- package/src/flow/models/base/PageModel/__tests__/PageModel.test.ts +790 -10
- package/src/flow/models/base/PageModel/__tests__/PageModelTabBar.module-isolation.test.tsx +130 -0
- package/src/flow/models/base/PageModel/__tests__/PageModelTabBar.test.tsx +118 -0
- package/src/flow/models/base/PageModel/__tests__/PageTabModel.test.ts +572 -1
- package/src/flow/models/blocks/table/TableBlockModel.tsx +1 -1
- package/src/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/PopupSubTableFieldModel.tsx +1 -1
- package/src/flow/models/fields/VariableFieldFormModel.tsx +3 -3
- package/src/flow/models/fields/__tests__/VariableFieldFormModel.test.tsx +51 -0
- package/src/flow-compat/fieldValidationConstants.ts +1 -1
- package/src/flow-compat/routeTypes.ts +1 -0
- package/src/index.ts +4 -0
- package/src/locale/languageCodes.ts +2 -1
- package/src/nocobase-buildin-plugin/index.tsx +12 -0
- package/src/utils/getRouteRuntimeVersion.ts +185 -0
- package/src/utils/index.tsx +1 -0
|
@@ -83,7 +83,8 @@ const languageCodes = {
|
|
|
83
83
|
"tk-TK": { label: "Turkmen" },
|
|
84
84
|
"tr-TR": { label: "T\xFCrk\xE7e" },
|
|
85
85
|
"uk-UA": { label: "\u0423\u043A\u0440\u0430\u0457\u043D\u0441\u044C\u043A\u0430" },
|
|
86
|
-
"ur-PK": { label: "
|
|
86
|
+
"ur-PK": { label: "\u0627\u0631\u062F\u0648" },
|
|
87
|
+
"uz-UZ": { label: "O\u02BBzbekcha" },
|
|
87
88
|
"vi-VN": { label: "Ti\u1EBFng Vi\u1EC7t" },
|
|
88
89
|
"zh-CN": { label: "\u7B80\u4F53\u4E2D\u6587" },
|
|
89
90
|
"zh-HK": { label: "\u7E41\u9AD4\u4E2D\u6587\uFF08\u9999\u6E2F\uFF09" },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/client-v2",
|
|
3
|
-
"version": "2.2.0-beta.
|
|
3
|
+
"version": "2.2.0-beta.15",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "es/index.mjs",
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
"@formily/antd-v5": "1.2.3",
|
|
28
28
|
"@formily/react": "^2.2.27",
|
|
29
29
|
"@formily/shared": "^2.2.27",
|
|
30
|
-
"@nocobase/evaluators": "2.2.0-beta.
|
|
31
|
-
"@nocobase/flow-engine": "2.2.0-beta.
|
|
32
|
-
"@nocobase/sdk": "2.2.0-beta.
|
|
33
|
-
"@nocobase/shared": "2.2.0-beta.
|
|
34
|
-
"@nocobase/utils": "2.2.0-beta.
|
|
30
|
+
"@nocobase/evaluators": "2.2.0-beta.15",
|
|
31
|
+
"@nocobase/flow-engine": "2.2.0-beta.15",
|
|
32
|
+
"@nocobase/sdk": "2.2.0-beta.15",
|
|
33
|
+
"@nocobase/shared": "2.2.0-beta.15",
|
|
34
|
+
"@nocobase/utils": "2.2.0-beta.15",
|
|
35
35
|
"ahooks": "^3.7.2",
|
|
36
36
|
"antd": "5.24.2",
|
|
37
37
|
"antd-style": "3.7.1",
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"react-i18next": "^11.15.1",
|
|
48
48
|
"react-router-dom": "^6.30.1"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "4c471f6b7d26adc412b2cc1d91264572296ca873"
|
|
51
51
|
}
|
package/src/APIClient.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { APIClient as APIClientSDK,
|
|
10
|
+
import { APIClient as APIClientSDK, hasHeaderValue } from '@nocobase/sdk';
|
|
11
11
|
|
|
12
12
|
function offsetToTimeZone(offset: number) {
|
|
13
13
|
const hours = Math.floor(Math.abs(offset));
|
|
@@ -23,15 +23,6 @@ function getCurrentTimezone() {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export class APIClient extends APIClientSDK {
|
|
26
|
-
appName?: string;
|
|
27
|
-
|
|
28
|
-
constructor(options?: APIClientOptions) {
|
|
29
|
-
super(options);
|
|
30
|
-
if (options && typeof options !== 'function') {
|
|
31
|
-
this.appName = options.appName;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
26
|
getHostname() {
|
|
36
27
|
if (process.env.API_BASE_URL) {
|
|
37
28
|
try {
|
package/src/Application.tsx
CHANGED
|
@@ -46,6 +46,10 @@ export class Application extends BaseApplication<
|
|
|
46
46
|
|
|
47
47
|
protected createApiClient(options: ApplicationOptions) {
|
|
48
48
|
return new APIClient({
|
|
49
|
+
// Cross-origin API deployments rely on cookies for auth (e.g. permanent file
|
|
50
|
+
// URLs); trust is enforced server-side via the CORS origin whitelist and the
|
|
51
|
+
// CSRF middleware, not by omitting credentials.
|
|
52
|
+
withCredentials: true,
|
|
49
53
|
...options.apiClient,
|
|
50
54
|
appName: options.name || getSubAppName(options.publicPath),
|
|
51
55
|
});
|
package/src/BaseApplication.tsx
CHANGED
|
@@ -403,7 +403,7 @@ export abstract class BaseApplication<
|
|
|
403
403
|
this.favicon = favicon || '';
|
|
404
404
|
}
|
|
405
405
|
|
|
406
|
-
const iconHref = this.favicon || '
|
|
406
|
+
const iconHref = this.favicon || this.getCdnUrl() + 'favicon/favicon.ico';
|
|
407
407
|
|
|
408
408
|
if (faviconLinkElement) {
|
|
409
409
|
faviconLinkElement.href = iconHref;
|
|
@@ -52,6 +52,24 @@ describe('app', () => {
|
|
|
52
52
|
expect(app.getHref('/test')).toBe('/test');
|
|
53
53
|
});
|
|
54
54
|
|
|
55
|
+
it('should enable credentials for api clients by default', () => {
|
|
56
|
+
const sameOriginApp = new Application({
|
|
57
|
+
router,
|
|
58
|
+
apiClient: {
|
|
59
|
+
baseURL: '/api/',
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
const crossOriginApp = new Application({
|
|
63
|
+
router,
|
|
64
|
+
apiClient: {
|
|
65
|
+
baseURL: 'https://api.example.com/api/',
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
expect(sameOriginApp.apiClient.axios.defaults.withCredentials).toBe(true);
|
|
70
|
+
expect(crossOriginApp.apiClient.axios.defaults.withCredentials).toBe(true);
|
|
71
|
+
});
|
|
72
|
+
|
|
55
73
|
it('should initialize shared jsonLogic operators', () => {
|
|
56
74
|
const app = new Application({ router });
|
|
57
75
|
|
|
@@ -15,6 +15,8 @@ import { fileURLToPath } from 'node:url';
|
|
|
15
15
|
type BrowserCheckerCase = {
|
|
16
16
|
pathname: string;
|
|
17
17
|
publicPath: string;
|
|
18
|
+
modernClientPrefix?: string;
|
|
19
|
+
appClientEntryMode?: string;
|
|
18
20
|
expectedRedirect?: string;
|
|
19
21
|
};
|
|
20
22
|
|
|
@@ -40,6 +42,8 @@ function executeBrowserChecker(scriptPath: string, input: BrowserCheckerCase) {
|
|
|
40
42
|
showLog: false,
|
|
41
43
|
window: {
|
|
42
44
|
__nocobase_public_path__: input.publicPath,
|
|
45
|
+
__nocobase_modern_client_prefix__: input.modernClientPrefix,
|
|
46
|
+
__nocobase_app_client_entry_mode__: input.appClientEntryMode,
|
|
43
47
|
location: {
|
|
44
48
|
origin: 'http://c.local.nocobase.com',
|
|
45
49
|
pathname: input.pathname,
|
|
@@ -109,4 +113,61 @@ describe.each(browserCheckerCases)('$label', ({ scriptPath }) => {
|
|
|
109
113
|
|
|
110
114
|
expect(replace).not.toHaveBeenCalled();
|
|
111
115
|
});
|
|
116
|
+
|
|
117
|
+
if (scriptPath.includes('/app/client/public/')) {
|
|
118
|
+
it('redirects app root to modern entry for modern-default', () => {
|
|
119
|
+
const replace = executeBrowserChecker(scriptPath, {
|
|
120
|
+
pathname: '/',
|
|
121
|
+
publicPath: '/',
|
|
122
|
+
modernClientPrefix: 'v',
|
|
123
|
+
appClientEntryMode: 'modern-default',
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
expect(replace).toHaveBeenCalledWith('http://c.local.nocobase.com/v/');
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('does not redirect legacy deep links for modern-default', () => {
|
|
130
|
+
const replace = executeBrowserChecker(scriptPath, {
|
|
131
|
+
pathname: '/admin',
|
|
132
|
+
publicPath: '/',
|
|
133
|
+
modernClientPrefix: 'v',
|
|
134
|
+
appClientEntryMode: 'modern-default',
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
expect(replace).not.toHaveBeenCalled();
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('rewrites legacy document paths for modern-only', () => {
|
|
141
|
+
const replace = executeBrowserChecker(scriptPath, {
|
|
142
|
+
pathname: '/admin/settings/workflow',
|
|
143
|
+
publicPath: '/',
|
|
144
|
+
modernClientPrefix: 'v',
|
|
145
|
+
appClientEntryMode: 'modern-only',
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
expect(replace).toHaveBeenCalledWith('http://c.local.nocobase.com/v/admin/settings/workflow');
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('redirects sub-path site root directly to final modern target', () => {
|
|
152
|
+
const replace = executeBrowserChecker(scriptPath, {
|
|
153
|
+
pathname: '/nocobase/',
|
|
154
|
+
publicPath: '/nocobase/',
|
|
155
|
+
modernClientPrefix: 'v',
|
|
156
|
+
appClientEntryMode: 'modern-default',
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
expect(replace).toHaveBeenCalledWith('http://c.local.nocobase.com/nocobase/v/');
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it('rewrites sub-app legacy deep links for modern-only without collapsing the sub-app segment', () => {
|
|
163
|
+
const replace = executeBrowserChecker(scriptPath, {
|
|
164
|
+
pathname: '/nocobase/apps/a_31itq60q4kg/admin/',
|
|
165
|
+
publicPath: '/nocobase/',
|
|
166
|
+
modernClientPrefix: 'v',
|
|
167
|
+
appClientEntryMode: 'modern-only',
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
expect(replace).toHaveBeenCalledWith('http://c.local.nocobase.com/nocobase/v/apps/a_31itq60q4kg/admin');
|
|
171
|
+
});
|
|
172
|
+
}
|
|
112
173
|
});
|
|
@@ -0,0 +1,68 @@
|
|
|
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 { afterEach, describe, expect, it } from 'vitest';
|
|
11
|
+
import { getRouteRuntimeVersion } from '../utils/getRouteRuntimeVersion';
|
|
12
|
+
|
|
13
|
+
function replacePathname(pathname: string) {
|
|
14
|
+
Object.defineProperty(window, 'location', {
|
|
15
|
+
configurable: true,
|
|
16
|
+
value: {
|
|
17
|
+
...window.location,
|
|
18
|
+
pathname,
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
describe('getRouteRuntimeVersion', () => {
|
|
24
|
+
afterEach(() => {
|
|
25
|
+
delete window.__nocobase_modern_client_prefix__;
|
|
26
|
+
delete window.__nocobase_public_path__;
|
|
27
|
+
replacePathname('/');
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('returns modern when the current pathname is inside the modern client prefix', () => {
|
|
31
|
+
window.__nocobase_modern_client_prefix__ = 'v';
|
|
32
|
+
window.__nocobase_public_path__ = '/nocobase/v/';
|
|
33
|
+
replacePathname('/nocobase/v/admin/settings/workflow');
|
|
34
|
+
|
|
35
|
+
expect(getRouteRuntimeVersion()).toBe('modern');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('returns legacy when reused v2 components run under the v1 settings page', () => {
|
|
39
|
+
window.__nocobase_modern_client_prefix__ = 'v';
|
|
40
|
+
window.__nocobase_public_path__ = '/nocobase/';
|
|
41
|
+
replacePathname('/nocobase/admin/settings/workflow/workflows/123');
|
|
42
|
+
|
|
43
|
+
expect(getRouteRuntimeVersion()).toBe('legacy');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('returns legacy when root public path is "/"', () => {
|
|
47
|
+
window.__nocobase_modern_client_prefix__ = 'v';
|
|
48
|
+
window.__nocobase_public_path__ = '/';
|
|
49
|
+
replacePathname('/admin/settings/workflow/workflows/123');
|
|
50
|
+
|
|
51
|
+
expect(getRouteRuntimeVersion()).toBe('legacy');
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('returns modern when root public path is "/v/"', () => {
|
|
55
|
+
window.__nocobase_modern_client_prefix__ = 'v';
|
|
56
|
+
window.__nocobase_public_path__ = '/v/';
|
|
57
|
+
replacePathname('/v/admin/workflow/workflows/123');
|
|
58
|
+
|
|
59
|
+
expect(getRouteRuntimeVersion()).toBe('modern');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('falls back to pathname matching when public path is unavailable', () => {
|
|
63
|
+
window.__nocobase_modern_client_prefix__ = 'v';
|
|
64
|
+
replacePathname('/v/admin/workflow/workflows/123');
|
|
65
|
+
|
|
66
|
+
expect(getRouteRuntimeVersion()).toBe('modern');
|
|
67
|
+
});
|
|
68
|
+
});
|
|
@@ -55,6 +55,7 @@ describe('nocobase buildin plugin auth redirect', () => {
|
|
|
55
55
|
const originalLocation = globalThis.window.location;
|
|
56
56
|
|
|
57
57
|
beforeEach(() => {
|
|
58
|
+
globalThis.window.localStorage.clear();
|
|
58
59
|
// These fixtures mount the modern client under the `v2` segment; tell the
|
|
59
60
|
// runtime-prefix helper so v2-runtime detection matches (server injects it
|
|
60
61
|
// in production).
|
|
@@ -75,6 +76,7 @@ describe('nocobase buildin plugin auth redirect', () => {
|
|
|
75
76
|
});
|
|
76
77
|
|
|
77
78
|
afterEach(() => {
|
|
79
|
+
globalThis.window.localStorage.clear();
|
|
78
80
|
delete (globalThis.window as any).__nocobase_modern_client_prefix__;
|
|
79
81
|
Object.defineProperty(globalThis.window, 'location', {
|
|
80
82
|
configurable: true,
|
|
@@ -116,6 +118,7 @@ describe('nocobase buildin plugin auth redirect', () => {
|
|
|
116
118
|
plugins: [NocoBaseBuildInPlugin as any],
|
|
117
119
|
router: { type: 'memory', initialEntries: ['/v2/admin'] },
|
|
118
120
|
});
|
|
121
|
+
app.apiClient.auth.setToken('test-token');
|
|
119
122
|
app.apiMock.onGet('app:getLang').reply(200, {
|
|
120
123
|
data: { lang: 'en-US', resources: { client: {} }, cron: {} },
|
|
121
124
|
});
|
|
@@ -130,6 +133,7 @@ describe('nocobase buildin plugin auth redirect', () => {
|
|
|
130
133
|
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
131
134
|
expect(app.router.router.state.location.pathname).toBe('/v2/admin');
|
|
132
135
|
expect(app.router.router.state.location.search).toBe('');
|
|
136
|
+
expect(app.apiMock.history.post.filter((request) => request.url === 'auth:syncCookies')).toHaveLength(0);
|
|
133
137
|
});
|
|
134
138
|
|
|
135
139
|
it('should redirect unauthenticated v2 root access to v2 signin via <Navigate />', async () => {
|
|
@@ -326,6 +330,29 @@ describe('nocobase buildin plugin auth redirect', () => {
|
|
|
326
330
|
data: { lang: 'en-US', resources: { client: {} }, cron: {} },
|
|
327
331
|
});
|
|
328
332
|
app.apiMock.onGet('/auth:check').reply(200, { data: { id: 1 } });
|
|
333
|
+
app.apiMock.onPost('auth:syncCookies').reply(200, { data: { synced: true } });
|
|
334
|
+
const ensureLoaded = vi.spyOn(app.dataSourceManager, 'ensureLoaded').mockResolvedValue(undefined);
|
|
335
|
+
|
|
336
|
+
const Root = app.getRootComponent();
|
|
337
|
+
render(<Root />);
|
|
338
|
+
|
|
339
|
+
expect(await screen.findByText('secure page')).toBeInTheDocument();
|
|
340
|
+
expect(ensureLoaded).toHaveBeenCalledTimes(1);
|
|
341
|
+
expect(app.apiMock.history.post.filter((request) => request.url === 'auth:syncCookies')).toHaveLength(1);
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
it('should keep authenticated v2 startup working when cookie bootstrap fails', async () => {
|
|
345
|
+
const app = createMockClient({
|
|
346
|
+
publicPath: '/v2/',
|
|
347
|
+
plugins: [NocoBaseBuildInPlugin as any, AuthBootstrapRoutePlugin as any],
|
|
348
|
+
router: { type: 'memory', initialEntries: ['/v2/secure'] },
|
|
349
|
+
});
|
|
350
|
+
app.apiClient.auth.setToken('test-token');
|
|
351
|
+
app.apiMock.onGet('app:getLang').reply(200, {
|
|
352
|
+
data: { lang: 'en-US', resources: { client: {} }, cron: {} },
|
|
353
|
+
});
|
|
354
|
+
app.apiMock.onGet('/auth:check').reply(200, { data: { id: 1 } });
|
|
355
|
+
app.apiMock.onPost('auth:syncCookies').reply(500, { errors: [{ message: 'cookie sync failed' }] });
|
|
329
356
|
const ensureLoaded = vi.spyOn(app.dataSourceManager, 'ensureLoaded').mockResolvedValue(undefined);
|
|
330
357
|
|
|
331
358
|
const Root = app.getRootComponent();
|
|
@@ -333,6 +360,7 @@ describe('nocobase buildin plugin auth redirect', () => {
|
|
|
333
360
|
|
|
334
361
|
expect(await screen.findByText('secure page')).toBeInTheDocument();
|
|
335
362
|
expect(ensureLoaded).toHaveBeenCalledTimes(1);
|
|
363
|
+
expect(app.apiMock.history.post.filter((request) => request.url === 'auth:syncCookies')).toHaveLength(1);
|
|
336
364
|
});
|
|
337
365
|
|
|
338
366
|
it('should not auth-check or bootstrap authCheck false routes', async () => {
|
|
@@ -132,7 +132,7 @@ fieldValidationConfigureRegistry.registerMany([
|
|
|
132
132
|
{ key: 'uri', label: 'URI', hasValue: false, params: [], paramsType: 'object' },
|
|
133
133
|
{
|
|
134
134
|
key: 'multiple',
|
|
135
|
-
label: 'Multiple',
|
|
135
|
+
label: 'Multiple of',
|
|
136
136
|
hasValue: true,
|
|
137
137
|
params: [{ key: 'base', label: 'Base', componentType: 'inputNumber', required: true }],
|
|
138
138
|
},
|
package/src/components/README.md
CHANGED
|
@@ -190,6 +190,10 @@ import { TypedVariableInput } from '@nocobase/client-v2';
|
|
|
190
190
|
<Form.Item name={['options', 'secure']} label={t('Secure')} initialValue={true}>
|
|
191
191
|
<TypedVariableInput types={['boolean']} namespaces={['$env']} />
|
|
192
192
|
</Form.Item>
|
|
193
|
+
|
|
194
|
+
// Inject a custom variable tree (e.g. a workflow node's upstream outputs,
|
|
195
|
+
// which are not in the global registry)
|
|
196
|
+
<TypedVariableInput types={['string', 'number']} metaTree={workflowMetaTree} />
|
|
193
197
|
```
|
|
194
198
|
|
|
195
199
|
Key props:
|
|
@@ -197,6 +201,7 @@ Key props:
|
|
|
197
201
|
- `types`: allowed constant types. Shape mirrors v1 `useTypedConstant` — pass bare type names (`['number', 'boolean']`) or `[type, editorProps]` tuples (`[['number', { min, max, step }]]`) to forward props to the underlying antd editor. Defaults to `['string', 'number', 'boolean', 'date']`. **Even when only one type is allowed, the `Constant` entry still expands into a typed submenu** (Number / Boolean / Date / String) — matches v1 so users can see what type the constant is
|
|
198
202
|
- `namespaces`: restrict the variable picker to specific top-level namespaces (e.g. `['$env']`). Omit to expose every namespace registered on `flowEngine.context`
|
|
199
203
|
- `extraNodes`: static leaves appended after the namespace-filtered nodes
|
|
204
|
+
- `metaTree`: **inject the variable tree directly** instead of reading the global `flowEngine.context` meta tree. When set, `namespaces`/`extraNodes` are ignored and this tree is used verbatim — for context-scoped variable sources that are not in the global registry (typically a workflow node's upstream outputs, `$jobsMapByNodeKey`). Nodes whose `children` is a thunk (`() => Promise<MetaTreeNode[]>`) are **lazy-loaded on expand** (via flow-engine's `loadMetaTreeChildren`)
|
|
200
205
|
- `nullable`: whether to expose the `Null` switcher entry. Default `true`. Combined with `Form.Item.rules={[{ required: true }]}`, the user can explicitly clear the field but submission is still blocked by validation — mirrors v1's "Null + required" pairing
|
|
201
206
|
- `delimiters`: variable-token delimiters, default `['{{', '}}']` — same as `VariableInput`
|
|
202
207
|
- `value` / `onChange` / `placeholder` / `disabled` / `style` / `className`: standard controlled-input props
|
|
@@ -212,9 +217,10 @@ When **not** to use it:
|
|
|
212
217
|
- **Pure literal fields** (users will never pass a variable) → use the antd primitive directly (`InputNumber` / `Select` / `DatePicker` / `Input`) and skip the Cascader column overhead
|
|
213
218
|
- **Pure variable fields** (users will never pass a literal) → use `EnvVariableInput` (`$env`-only, with optional password masking) or `VariableInput` (general-purpose)
|
|
214
219
|
|
|
220
|
+
Supported constant types: `string` / `number` / `boolean` / `date` / `object`. The `object` (JSON) type renders an inline monospace textarea (2 rows by default, drag-resizable) — it keeps the raw text as a draft while editing and `JSON.parse`s it back into an object on blur. On a parse failure it shows the raw `JSON.parse` message (e.g. `Expected property name or '}' in JSON at position …`, matching v1) on its own row below the input, and does not emit. Mirrors v1 `useTypedConstant`'s object form (default value `{}`).
|
|
221
|
+
|
|
215
222
|
Capabilities skipped (present in v1, not yet ported to v2):
|
|
216
223
|
|
|
217
|
-
- `object` constant type (JSON editor) — v2 has no inline "JSON editor + Cascader switcher" yet; add when there's a concrete caller
|
|
218
224
|
- Async `loadChildren` cascading — most MetaTree namespaces are already eagerly resolved by `useFilteredMetaTree`, so this hasn't been needed
|
|
219
225
|
|
|
220
226
|
#### FileSizeInput
|
|
@@ -190,6 +190,9 @@ import { TypedVariableInput } from '@nocobase/client-v2';
|
|
|
190
190
|
<Form.Item name={['options', 'secure']} label={t('安全模式')} initialValue={true}>
|
|
191
191
|
<TypedVariableInput types={['boolean']} namespaces={['$env']} />
|
|
192
192
|
</Form.Item>
|
|
193
|
+
|
|
194
|
+
// 注入自定义变量树(如工作流节点的上游输出,不在全局注册表里)
|
|
195
|
+
<TypedVariableInput types={['string', 'number']} metaTree={workflowMetaTree} />
|
|
193
196
|
```
|
|
194
197
|
|
|
195
198
|
主要属性:
|
|
@@ -197,6 +200,7 @@ import { TypedVariableInput } from '@nocobase/client-v2';
|
|
|
197
200
|
- `types`:允许的常量类型。形态对齐 v1 `useTypedConstant`,可以传裸类型名 `['number', 'boolean']`,也可以传 `[type, editorProps]` 元组 `[['number', { min, max, step }]]` 把 props 透传给底层 antd 编辑器。默认 `['string', 'number', 'boolean', 'date']`。**即使只允许一种类型,「常量」入口也会展开二级菜单**(数字 / 逻辑值 / 日期 / 字符串)——跟 v1 一致,让用户能直观看到当前常量是什么类型
|
|
198
201
|
- `namespaces`:限定变量 picker 可选的顶层命名空间(如 `['$env']`)。不传就用 `flowEngine.context` 里所有已注册命名空间
|
|
199
202
|
- `extraNodes`:在命名空间过滤后追加几条静态变量节点
|
|
203
|
+
- `metaTree`:**直接注入变量树**,取代读取全局 `flowEngine.context` 的 MetaTree。传了它就**忽略** `namespaces`/`extraNodes`,原样使用这棵树——用于不在全局注册表里的、上下文相关的变量源(典型如工作流节点的上游节点输出 `$jobsMapByNodeKey`)。树里 `children` 为函数(`() => Promise<MetaTreeNode[]>`)的节点会在用户展开 Cascader 时**按需懒加载**(复用 flow-engine 的 `loadMetaTreeChildren`)
|
|
200
204
|
- `nullable`:是否暴露「空值」入口,默认 `true`。配合 `Form.Item.rules={[{ required: true }]}` 可以让用户能手动清空、但提交时会被校验拦截——跟 v1 的「空值 + required」组合一致
|
|
201
205
|
- `delimiters`:变量 token 开闭分隔符,默认 `['{{', '}}']`,跟 `VariableInput` 一致
|
|
202
206
|
- `value` / `onChange` / `placeholder` / `disabled` / `style` / `className`:标准受控字段属性
|
|
@@ -212,9 +216,10 @@ import { TypedVariableInput } from '@nocobase/client-v2';
|
|
|
212
216
|
- **纯字面量字段**(用户不会想填变量)→ 直接用 antd `InputNumber` / `Select` / `DatePicker` / `Input`,省掉 Cascader 那一格的视觉开销
|
|
213
217
|
- **纯变量字段**(用户不会想填字面量)→ 用 `EnvVariableInput`(`$env` 专用,带 password mask)或 `VariableInput`(更通用)
|
|
214
218
|
|
|
219
|
+
支持的常量类型:`string` / `number` / `boolean` / `date` / `object`。其中 `object`(即 JSON)渲染为一个等宽字体的内联 textarea(默认两行、可拖拽拉伸),编辑时保留原始文本草稿、失焦(blur)时 `JSON.parse` 回写为对象;解析失败则在输入框**下方单独一行**显示原生 `JSON.parse` 的错误信息(如 `Expected property name or '}' in JSON at position …`,对齐 v1)且不回写。对齐 v1 `useTypedConstant` 的 object 形态(默认值 `{}`)。
|
|
220
|
+
|
|
215
221
|
跳过的能力(v1 有但 v2 还没补):
|
|
216
222
|
|
|
217
|
-
- `object` 类型(JSON 编辑器)——v2 还没对应的「内联 JSON 编辑器 + Cascader 切换」组件,等真有需求再补
|
|
218
223
|
- 异步 `loadChildren` 分支——大多数命名空间的 MetaTree 已经由 `useFilteredMetaTree` 提前展平,没遇到刚需
|
|
219
224
|
|
|
220
225
|
#### FileSizeInput
|
|
@@ -0,0 +1,210 @@
|
|
|
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 { MenuOutlined } from '@ant-design/icons';
|
|
11
|
+
import {
|
|
12
|
+
DndContext,
|
|
13
|
+
DragOverlay,
|
|
14
|
+
MouseSensor,
|
|
15
|
+
useDraggable,
|
|
16
|
+
useDroppable,
|
|
17
|
+
useSensor,
|
|
18
|
+
useSensors,
|
|
19
|
+
type DragEndEvent,
|
|
20
|
+
type DragStartEvent,
|
|
21
|
+
} from '@dnd-kit/core';
|
|
22
|
+
import { Badge, Button, Dropdown, Space, Tabs } from 'antd';
|
|
23
|
+
import type { TabsProps } from 'antd';
|
|
24
|
+
import React, { useCallback, useMemo, useState } from 'react';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* A category descriptor for {@link SortableCategoryTabs}. The component is
|
|
28
|
+
* i18n-agnostic: `label` is rendered verbatim, so consumers pass an
|
|
29
|
+
* already-compiled/translated node. `color` is an antd preset color name or a
|
|
30
|
+
* hex string; `'default'` / `undefined` renders no badge color.
|
|
31
|
+
*/
|
|
32
|
+
export type SortableCategoryTabItem = {
|
|
33
|
+
id: string | number;
|
|
34
|
+
label: React.ReactNode;
|
|
35
|
+
color?: string;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export type SortableCategoryTabsProps = {
|
|
39
|
+
activeKey: string;
|
|
40
|
+
onChange: (key: string) => void;
|
|
41
|
+
/** Draggable category tabs (the fixed leading tab is configured via `allTab`). */
|
|
42
|
+
categories: SortableCategoryTabItem[];
|
|
43
|
+
/** The fixed, non-draggable leading tab, e.g. "All". */
|
|
44
|
+
allTab: { key: string; label: React.ReactNode };
|
|
45
|
+
/** Show the "+" add button and handle its click. */
|
|
46
|
+
onAdd?: () => void;
|
|
47
|
+
/** Per-category edit menu item handler; menu is hidden when omitted. */
|
|
48
|
+
onEdit?: (id: string | number) => void;
|
|
49
|
+
/** Per-category delete menu item handler; menu is hidden when omitted. */
|
|
50
|
+
onDelete?: (id: string | number) => void;
|
|
51
|
+
/** Reorder handler. Receives the dragged and dropped category ids. */
|
|
52
|
+
onSort?: (sourceId: string | number, targetId: string | number) => void | Promise<void>;
|
|
53
|
+
/** Consumer-translated labels for the per-category dropdown menu. */
|
|
54
|
+
menuLabels?: { edit?: string; delete?: string };
|
|
55
|
+
className?: string;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
function DraggableTab(props: { id: string; children: React.ReactNode }) {
|
|
59
|
+
const { attributes, listeners, setNodeRef } = useDraggable({ id: props.id });
|
|
60
|
+
return (
|
|
61
|
+
<div ref={setNodeRef} {...listeners} {...attributes}>
|
|
62
|
+
{props.children}
|
|
63
|
+
</div>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function DroppableTab(props: { id: string; children: React.ReactNode }) {
|
|
68
|
+
const { isOver, setNodeRef } = useDroppable({ id: props.id });
|
|
69
|
+
return (
|
|
70
|
+
<div ref={setNodeRef} style={isOver ? { color: 'green' } : undefined}>
|
|
71
|
+
{props.children}
|
|
72
|
+
</div>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function CategoryTabContent(props: {
|
|
77
|
+
item: SortableCategoryTabItem;
|
|
78
|
+
onEdit?: (id: string | number) => void;
|
|
79
|
+
onDelete?: (id: string | number) => void;
|
|
80
|
+
menuLabels?: { edit?: string; delete?: string };
|
|
81
|
+
}) {
|
|
82
|
+
const { item, onEdit, onDelete, menuLabels } = props;
|
|
83
|
+
const hasMenu = Boolean(onEdit || onDelete);
|
|
84
|
+
const editLabel = menuLabels?.edit ?? 'Edit';
|
|
85
|
+
const deleteLabel = menuLabels?.delete ?? 'Delete';
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
<Space size={6}>
|
|
89
|
+
<Badge color={item.color === 'default' ? undefined : item.color} />
|
|
90
|
+
{item.label}
|
|
91
|
+
{hasMenu ? (
|
|
92
|
+
<Dropdown
|
|
93
|
+
trigger={['click']}
|
|
94
|
+
menu={{
|
|
95
|
+
items: [
|
|
96
|
+
onEdit ? { key: 'edit', label: editLabel } : null,
|
|
97
|
+
onDelete ? { key: 'delete', label: deleteLabel } : null,
|
|
98
|
+
].filter(Boolean) as { key: string; label: string }[],
|
|
99
|
+
onClick({ key, domEvent }) {
|
|
100
|
+
domEvent.stopPropagation();
|
|
101
|
+
if (key === 'edit') {
|
|
102
|
+
onEdit?.(item.id);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
onDelete?.(item.id);
|
|
106
|
+
},
|
|
107
|
+
}}
|
|
108
|
+
>
|
|
109
|
+
<Button
|
|
110
|
+
aria-label={editLabel}
|
|
111
|
+
icon={<MenuOutlined />}
|
|
112
|
+
size="small"
|
|
113
|
+
type="text"
|
|
114
|
+
onClick={(event) => event.stopPropagation()}
|
|
115
|
+
/>
|
|
116
|
+
</Dropdown>
|
|
117
|
+
) : null}
|
|
118
|
+
</Space>
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* A draggable, editable category tab bar. Renders only the tab bar (no content
|
|
124
|
+
* panes) — the page renders its content below and reacts to `activeKey`.
|
|
125
|
+
*
|
|
126
|
+
* Shared by settings pages that group records under reorderable categories
|
|
127
|
+
* (data-source collections, workflows, …). Drag-to-reorder is powered by
|
|
128
|
+
* `@dnd-kit`; the "+" / per-tab edit-delete affordances are optional.
|
|
129
|
+
*/
|
|
130
|
+
export function SortableCategoryTabs(props: SortableCategoryTabsProps) {
|
|
131
|
+
const { activeKey, onChange, categories, allTab, onAdd, onEdit, onDelete, onSort, menuLabels, className } = props;
|
|
132
|
+
const [activeDragId, setActiveDragId] = useState<string | null>(null);
|
|
133
|
+
const sensors = useSensors(useSensor(MouseSensor, { activationConstraint: { distance: 10 } }));
|
|
134
|
+
|
|
135
|
+
const handleDragStart = useCallback((event: DragStartEvent) => {
|
|
136
|
+
setActiveDragId(String(event.active.id));
|
|
137
|
+
}, []);
|
|
138
|
+
|
|
139
|
+
const handleDragEnd = useCallback(
|
|
140
|
+
async (event: DragEndEvent) => {
|
|
141
|
+
const { active, over } = event;
|
|
142
|
+
setActiveDragId(null);
|
|
143
|
+
if (!over || over.id === active.id) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
await onSort?.(active.id as string | number, over.id as string | number);
|
|
147
|
+
},
|
|
148
|
+
[onSort],
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
const items = useMemo<TabsProps['items']>(
|
|
152
|
+
() => [
|
|
153
|
+
{ key: allTab.key, label: allTab.label, closable: false },
|
|
154
|
+
...categories.map((item) => ({
|
|
155
|
+
key: String(item.id),
|
|
156
|
+
closable: false,
|
|
157
|
+
label: onSort ? (
|
|
158
|
+
<DroppableTab id={String(item.id)}>
|
|
159
|
+
<DraggableTab id={String(item.id)}>
|
|
160
|
+
<CategoryTabContent item={item} onEdit={onEdit} onDelete={onDelete} menuLabels={menuLabels} />
|
|
161
|
+
</DraggableTab>
|
|
162
|
+
</DroppableTab>
|
|
163
|
+
) : (
|
|
164
|
+
<CategoryTabContent item={item} onEdit={onEdit} onDelete={onDelete} menuLabels={menuLabels} />
|
|
165
|
+
),
|
|
166
|
+
})),
|
|
167
|
+
],
|
|
168
|
+
[allTab.key, allTab.label, categories, onSort, onEdit, onDelete, menuLabels],
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
const activeDragItem = useMemo(
|
|
172
|
+
() => categories.find((item) => String(item.id) === activeDragId),
|
|
173
|
+
[categories, activeDragId],
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
const tabs = (
|
|
177
|
+
<Tabs
|
|
178
|
+
className={className}
|
|
179
|
+
activeKey={activeKey}
|
|
180
|
+
type="editable-card"
|
|
181
|
+
hideAdd={!onAdd}
|
|
182
|
+
items={items}
|
|
183
|
+
onChange={onChange}
|
|
184
|
+
onEdit={(_, action) => {
|
|
185
|
+
if (action === 'add') {
|
|
186
|
+
onAdd?.();
|
|
187
|
+
}
|
|
188
|
+
}}
|
|
189
|
+
/>
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
if (!onSort) {
|
|
193
|
+
return tabs;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return (
|
|
197
|
+
<DndContext sensors={sensors} onDragStart={handleDragStart} onDragEnd={handleDragEnd}>
|
|
198
|
+
{tabs}
|
|
199
|
+
<DragOverlay dropAnimation={null}>
|
|
200
|
+
{activeDragItem ? (
|
|
201
|
+
<span style={{ whiteSpace: 'nowrap' }}>
|
|
202
|
+
<CategoryTabContent item={activeDragItem} menuLabels={menuLabels} />
|
|
203
|
+
</span>
|
|
204
|
+
) : null}
|
|
205
|
+
</DragOverlay>
|
|
206
|
+
</DndContext>
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export default SortableCategoryTabs;
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
export * from './SortableCategoryTabs';
|