@nocobase/client-v2 2.1.11 → 2.2.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/PluginSettingsManager.d.ts +33 -0
- package/es/RouteRepository.d.ts +21 -6
- package/es/components/category-tabs/SortableCategoryTabs.d.ts +55 -0
- package/es/components/category-tabs/index.d.ts +9 -0
- package/es/components/form/TypedVariableInput.d.ts +22 -4
- package/es/components/form/filter/CollectionFilterItem.d.ts +11 -1
- package/es/components/form/filter/index.d.ts +2 -0
- package/es/components/index.d.ts +2 -0
- package/es/flow/actions/afterSuccess.d.ts +8 -1
- package/es/flow/actions/index.d.ts +1 -1
- package/es/flow/admin-shell/admin-layout/AdminLayoutEntryGuard.d.ts +2 -0
- package/es/flow/admin-shell/admin-layout/AdminLayoutMenuFlowUtils.d.ts +2 -1
- package/es/flow/admin-shell/admin-layout/AdminLayoutMenuModels.d.ts +2 -0
- package/es/flow/admin-shell/admin-layout/AdminLayoutMenuUtils.d.ts +3 -2
- package/es/flow/admin-shell/admin-layout/AdminLayoutSlotModels.d.ts +5 -0
- package/es/flow/admin-shell/admin-layout/resolveAdminRouteRuntimeTarget.d.ts +6 -0
- package/es/flow/components/FieldAssignValueInput.d.ts +2 -0
- package/es/flow/index.d.ts +1 -0
- package/es/flow/models/base/GridModel.d.ts +1 -1
- package/es/flow/models/blocks/form/submitHandler.d.ts +1 -1
- package/es/flow/models/blocks/table/TableActionsColumnModel.d.ts +1 -0
- package/es/flow/models/blocks/table/TableBlockModel.d.ts +1 -0
- package/es/flow/models/blocks/table/dragSort/dragSortHooks.d.ts +1 -1
- package/es/flow/models/blocks/table/dragSort/dragSortSettings.d.ts +2 -1
- package/es/flow/models/blocks/table/dragSort/dragSortUtils.d.ts +6 -4
- package/es/flow/resolveViewParamsToViewList.d.ts +1 -1
- package/es/index.d.ts +2 -1
- package/es/index.mjs +181 -131
- package/lib/index.js +186 -136
- package/package.json +7 -7
- package/src/PluginSettingsManager.ts +53 -0
- package/src/RouteRepository.ts +126 -24
- package/src/__tests__/PluginSettingsManager.test.ts +13 -0
- package/src/__tests__/RouteRepository.test.ts +216 -0
- package/src/__tests__/browserChecker.test.ts +61 -0
- package/src/__tests__/exports.test.ts +16 -0
- package/src/__tests__/plugin-manager.test.tsx +44 -2
- package/src/__tests__/settings-center.test.tsx +40 -1
- package/src/collection-manager/field-configure.ts +1 -1
- package/src/collection-manager/interfaces/id.ts +1 -1
- package/src/collection-manager/interfaces/m2m.tsx +2 -2
- package/src/collection-manager/interfaces/m2o.tsx +2 -2
- package/src/collection-manager/interfaces/nanoid.ts +1 -1
- package/src/collection-manager/interfaces/o2m.tsx +2 -2
- package/src/collection-manager/interfaces/obo.tsx +2 -2
- package/src/collection-manager/interfaces/oho.tsx +2 -2
- package/src/collection-manager/interfaces/properties/index.ts +2 -2
- package/src/collection-manager/interfaces/uuid.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/TypedVariableInput.tsx +416 -93
- package/src/components/form/__tests__/TypedVariableInput.test.tsx +266 -9
- package/src/components/form/filter/CollectionFilterItem.tsx +32 -7
- package/src/components/form/filter/__tests__/CollectionFilterItem.test.tsx +38 -0
- package/src/components/form/filter/index.ts +2 -0
- package/src/components/index.ts +2 -0
- package/src/flow/__tests__/FlowRoute.test.tsx +443 -5
- package/src/flow/__tests__/getKey.test.ts +7 -0
- package/src/flow/__tests__/resolveViewParamsToViewList.test.ts +34 -0
- package/src/flow/actions/__tests__/afterSuccess.test.ts +73 -0
- package/src/flow/actions/__tests__/openView.defineProps.route.test.tsx +104 -0
- package/src/flow/actions/afterSuccess.tsx +142 -3
- package/src/flow/actions/customVariable.tsx +1 -2
- package/src/flow/actions/index.ts +1 -1
- package/src/flow/actions/linkageRules.tsx +2 -7
- package/src/flow/actions/openView.tsx +38 -4
- package/src/flow/actions/runjs.tsx +2 -14
- package/src/flow/admin-shell/BaseLayoutModel.tsx +25 -3
- package/src/flow/admin-shell/BaseLayoutRouteCoordinator.ts +5 -2
- package/src/flow/admin-shell/__tests__/AdminLayoutRouteCoordinator.test.ts +13 -0
- package/src/flow/admin-shell/admin-layout/AdminLayoutComponent.tsx +34 -10
- package/src/flow/admin-shell/admin-layout/AdminLayoutEntryGuard.test.tsx +310 -0
- package/src/flow/admin-shell/admin-layout/AdminLayoutEntryGuard.tsx +44 -8
- package/src/flow/admin-shell/admin-layout/AdminLayoutMenuFlowUtils.ts +5 -3
- package/src/flow/admin-shell/admin-layout/AdminLayoutMenuModels.tsx +61 -9
- package/src/flow/admin-shell/admin-layout/AdminLayoutMenuUtils.tsx +71 -8
- package/src/flow/admin-shell/admin-layout/AdminLayoutModel.tsx +1 -1
- package/src/flow/admin-shell/admin-layout/AdminLayoutSlotModels.tsx +23 -9
- package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutComponent.test.tsx +188 -0
- package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutMenuModels.test.ts +99 -0
- package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutModel.test.tsx +82 -0
- package/src/flow/admin-shell/admin-layout/__tests__/TopbarActionsBar.test.tsx +166 -2
- package/src/flow/admin-shell/admin-layout/resolveAdminRouteRuntimeTarget.test.ts +20 -0
- package/src/flow/admin-shell/admin-layout/resolveAdminRouteRuntimeTarget.ts +33 -5
- package/src/flow/components/DefaultValue.tsx +1 -2
- package/src/flow/components/FieldAssignValueInput.tsx +10 -5
- package/src/flow/components/FlowRoute.tsx +56 -11
- package/src/flow/components/code-editor/__tests__/useCodeRunner.test.tsx +2 -17
- package/src/flow/components/code-editor/hooks/useCodeRunner.ts +2 -14
- package/src/flow/components/code-editor/runjsDiagnostics.ts +8 -45
- package/src/flow/getViewDiffAndUpdateHidden.tsx +1 -0
- package/src/flow/index.ts +1 -0
- package/src/flow/models/actions/JSActionModel.tsx +2 -7
- package/src/flow/models/actions/JSCollectionActionModel.tsx +2 -7
- package/src/flow/models/actions/JSItemActionModel.tsx +2 -7
- package/src/flow/models/actions/JSRecordActionModel.tsx +2 -7
- package/src/flow/models/base/ActionModel.tsx +12 -1
- package/src/flow/models/base/GridModel.tsx +38 -7
- package/src/flow/models/base/PageModel/__tests__/PageModel.test.ts +0 -4
- package/src/flow/models/base/__tests__/ActionModel.test.ts +83 -0
- package/src/flow/models/base/__tests__/GridModel.dragSnapshotContainer.test.ts +239 -1
- package/src/flow/models/base/__tests__/transformRowsToSingleColumn.test.ts +48 -0
- package/src/flow/models/blocks/filter-form/FilterFormBlockModel.tsx +1 -2
- package/src/flow/models/blocks/filter-form/FilterFormJSActionModel.tsx +2 -7
- package/src/flow/models/blocks/filter-form/fields/FilterFormCustomFieldModel.tsx +1 -1
- package/src/flow/models/blocks/form/FormActionModel.tsx +1 -1
- package/src/flow/models/blocks/form/JSFormActionModel.tsx +2 -7
- package/src/flow/models/blocks/form/__tests__/submitHandler.test.ts +54 -1
- package/src/flow/models/blocks/form/submitHandler.ts +17 -3
- package/src/flow/models/blocks/form/value-runtime/rules.ts +2 -2
- package/src/flow/models/blocks/js-block/JSBlock.tsx +2 -7
- package/src/flow/models/blocks/table/JSColumnModel.tsx +1 -9
- package/src/flow/models/blocks/table/TableActionsColumnModel.tsx +36 -13
- package/src/flow/models/blocks/table/TableBlockModel.tsx +38 -17
- package/src/flow/models/blocks/table/__tests__/TableActionsColumnModel.test.tsx +111 -1
- package/src/flow/models/blocks/table/__tests__/TableBlockModel.dragSort.test.ts +127 -0
- package/src/flow/models/blocks/table/__tests__/TableBlockModel.mobileSettingsButtons.test.tsx +78 -0
- package/src/flow/models/blocks/table/__tests__/TableBlockModel.rowSelection.test.tsx +1 -0
- package/src/flow/models/blocks/table/dragSort/dragSortHooks.tsx +28 -17
- package/src/flow/models/blocks/table/dragSort/dragSortSettings.ts +13 -6
- package/src/flow/models/blocks/table/dragSort/dragSortUtils.ts +15 -2
- package/src/flow/models/fields/JSEditableFieldModel.tsx +2 -11
- package/src/flow/models/fields/JSFieldModel.tsx +2 -7
- package/src/flow/models/fields/JSItemModel.tsx +2 -14
- package/src/flow/models/topbar/TopbarActionModel.tsx +93 -10
- package/src/flow/resolveViewParamsToViewList.tsx +11 -3
- package/src/flow-compat/Popover.tsx +43 -4
- package/src/flow-compat/__tests__/Popover.test.tsx +34 -0
- package/src/index.ts +8 -1
- package/src/layout-manager/__tests__/LayoutRoute.test.tsx +41 -1
- package/src/nocobase-buildin-plugin/index.tsx +0 -2
- package/src/settings-center/AdminSettingsLayout.tsx +10 -2
- package/src/settings-center/SystemSettingsPage.tsx +1 -2
- package/src/settings-center/plugin-manager/PluginCard.tsx +2 -2
- package/src/settings-center/utils.tsx +0 -6
|
@@ -117,7 +117,7 @@ FormSubmitActionModel.registerFlow({
|
|
|
117
117
|
try {
|
|
118
118
|
ctx.model.setProps('loading', true);
|
|
119
119
|
const { submitHandler } = await import('./submitHandler');
|
|
120
|
-
await submitHandler(ctx, params);
|
|
120
|
+
return await submitHandler(ctx, params);
|
|
121
121
|
} catch (error) {
|
|
122
122
|
ctx.model.setProps('loading', false);
|
|
123
123
|
if (error instanceof FlowExitAllException) {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
/**
|
|
11
11
|
* JS Form Action:表单工具栏按钮点击执行 JS。
|
|
12
12
|
*/
|
|
13
|
-
import { tExpr
|
|
13
|
+
import { tExpr } from '@nocobase/flow-engine';
|
|
14
14
|
import { CodeEditor } from '../../../components/code-editor';
|
|
15
15
|
import { FormActionModel } from './FormActionModel';
|
|
16
16
|
import { resolveRunJsParams } from '../../utils/resolveRunJsParams';
|
|
@@ -73,12 +73,7 @@ ctx.message.success('Current form values: ' + JSON.stringify(values));
|
|
|
73
73
|
await ctx.resource.refresh();
|
|
74
74
|
}
|
|
75
75
|
});
|
|
76
|
-
|
|
77
|
-
await ctx.runjs(
|
|
78
|
-
code,
|
|
79
|
-
{ window: createSafeWindow({ navigator }), document: createSafeDocument(), navigator },
|
|
80
|
-
{ version },
|
|
81
|
-
);
|
|
76
|
+
await ctx.runjs(code, undefined, { version });
|
|
82
77
|
},
|
|
83
78
|
},
|
|
84
79
|
},
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
import { SingleRecordResource } from '@nocobase/flow-engine';
|
|
11
11
|
import { describe, expect, it, vi } from 'vitest';
|
|
12
|
+
import { EditFormModel } from '../EditFormModel';
|
|
12
13
|
import { submitHandler } from '../submitHandler';
|
|
13
14
|
|
|
14
15
|
describe('submitHandler', () => {
|
|
@@ -52,13 +53,14 @@ describe('submitHandler', () => {
|
|
|
52
53
|
t: (value: string) => value,
|
|
53
54
|
};
|
|
54
55
|
|
|
55
|
-
await submitHandler(ctx, {
|
|
56
|
+
const responseRecord = await submitHandler(ctx, {
|
|
56
57
|
assignedValues: {
|
|
57
58
|
status: 'published',
|
|
58
59
|
reviewer: 'Alice',
|
|
59
60
|
},
|
|
60
61
|
});
|
|
61
62
|
|
|
63
|
+
expect(responseRecord).toEqual({ id: 1 });
|
|
62
64
|
expect(resource.save).toHaveBeenCalledWith(
|
|
63
65
|
{
|
|
64
66
|
title: 'Draft title',
|
|
@@ -68,4 +70,55 @@ describe('submitHandler', () => {
|
|
|
68
70
|
undefined,
|
|
69
71
|
);
|
|
70
72
|
});
|
|
73
|
+
|
|
74
|
+
it('returns the refreshed record for edit forms when the save response is empty', async () => {
|
|
75
|
+
const refreshedRecord = { id: 2, title: 'Updated title' };
|
|
76
|
+
const resource = Object.create(SingleRecordResource.prototype);
|
|
77
|
+
resource.getMeta = vi.fn((key: string) => (key === 'currentFilterByTk' ? 2 : undefined));
|
|
78
|
+
resource.setFilterByTk = vi.fn(() => resource);
|
|
79
|
+
resource.save = vi.fn(async () => undefined);
|
|
80
|
+
resource.refresh = vi.fn(async () => undefined);
|
|
81
|
+
resource.getData = vi.fn(() => refreshedRecord);
|
|
82
|
+
|
|
83
|
+
const blockModel = Object.create(EditFormModel.prototype);
|
|
84
|
+
const form = {
|
|
85
|
+
validateFields: vi.fn(async () => undefined),
|
|
86
|
+
getFieldsValue: vi.fn(() => ({
|
|
87
|
+
title: 'Updated title',
|
|
88
|
+
})),
|
|
89
|
+
};
|
|
90
|
+
Object.defineProperty(blockModel, 'context', { value: { form } });
|
|
91
|
+
Object.defineProperty(blockModel, 'collection', {
|
|
92
|
+
value: {
|
|
93
|
+
name: 'posts',
|
|
94
|
+
getFilterByTK: (record: { id?: number }) => record.id,
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
blockModel.resetUserModifiedFields = vi.fn();
|
|
98
|
+
|
|
99
|
+
const responseRecord = await submitHandler(
|
|
100
|
+
{
|
|
101
|
+
resource,
|
|
102
|
+
blockModel,
|
|
103
|
+
model: {
|
|
104
|
+
getStepParams: vi.fn(),
|
|
105
|
+
},
|
|
106
|
+
message: {
|
|
107
|
+
error: vi.fn(),
|
|
108
|
+
},
|
|
109
|
+
t: (value: string) => value,
|
|
110
|
+
},
|
|
111
|
+
{},
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
expect(responseRecord).toBe(refreshedRecord);
|
|
115
|
+
expect(resource.setFilterByTk).toHaveBeenCalledWith(2);
|
|
116
|
+
expect(resource.save).toHaveBeenCalledWith(
|
|
117
|
+
{
|
|
118
|
+
title: 'Updated title',
|
|
119
|
+
},
|
|
120
|
+
undefined,
|
|
121
|
+
);
|
|
122
|
+
expect(resource.refresh).toHaveBeenCalled();
|
|
123
|
+
});
|
|
71
124
|
});
|
|
@@ -12,6 +12,16 @@ import { mergeAssignFieldValues, resolveAssignFieldValues } from '../assign-form
|
|
|
12
12
|
import type { FormBlockModel } from './FormBlockModel';
|
|
13
13
|
import { omitHiddenModelValuesFromSubmit, shouldSkipSubmitValidation, validateSubmitForm } from './submitValues';
|
|
14
14
|
|
|
15
|
+
function getResponseRecord(response: unknown) {
|
|
16
|
+
if (!response || typeof response !== 'object') {
|
|
17
|
+
return response;
|
|
18
|
+
}
|
|
19
|
+
if ('data' in response) {
|
|
20
|
+
return (response as { data?: unknown }).data;
|
|
21
|
+
}
|
|
22
|
+
return response;
|
|
23
|
+
}
|
|
24
|
+
|
|
15
25
|
export async function submitHandler(ctx, params, cb?: (values?: any, filterByTk?: any) => void) {
|
|
16
26
|
const resource = ctx.resource;
|
|
17
27
|
const blockModel = ctx.blockModel as FormBlockModel;
|
|
@@ -41,30 +51,34 @@ export async function submitHandler(ctx, params, cb?: (values?: any, filterByTk?
|
|
|
41
51
|
resource.setFilterByTk(currentFilterByTk);
|
|
42
52
|
}
|
|
43
53
|
}
|
|
44
|
-
const data:
|
|
54
|
+
const data: unknown = cb ? await cb(values) : await resource.save(values, params.requestConfig);
|
|
55
|
+
let responseRecord = getResponseRecord(data);
|
|
45
56
|
if (isEditFormModel) {
|
|
46
57
|
resource.isNewRecord = false;
|
|
47
58
|
// 编辑表单保存成功后,表单应回到“已同步”状态:下一次刷新应允许覆盖为服务端值
|
|
48
59
|
blockModel.resetUserModifiedFields?.();
|
|
49
60
|
await resource.refresh();
|
|
61
|
+
responseRecord = responseRecord ?? resource.getData?.();
|
|
50
62
|
} else {
|
|
51
63
|
blockModel.form.resetFields();
|
|
52
64
|
blockModel.emitter.emit('onFieldReset');
|
|
53
65
|
blockModel.resetUserModifiedFields?.();
|
|
54
66
|
blockModel.formValueRuntime?.resetAfterFormReset?.();
|
|
55
67
|
if (ctx.view.inputArgs.collectionName === blockModel.collection.name && ctx.view.inputArgs.onChange) {
|
|
56
|
-
ctx.view.inputArgs.onChange(
|
|
68
|
+
ctx.view.inputArgs.onChange(responseRecord);
|
|
57
69
|
}
|
|
58
70
|
}
|
|
71
|
+
return responseRecord;
|
|
59
72
|
} else if (resource instanceof MultiRecordResource) {
|
|
60
73
|
const currentFilterByTk = resource.getMeta('currentFilterByTk');
|
|
61
74
|
if (!currentFilterByTk) {
|
|
62
75
|
ctx.message.error(ctx.t('No filterByTk found for multi-record resource.'));
|
|
63
76
|
return;
|
|
64
77
|
}
|
|
65
|
-
|
|
78
|
+
const data = cb
|
|
66
79
|
? await cb(values, currentFilterByTk)
|
|
67
80
|
: await resource.update(currentFilterByTk, values, params.requestConfig);
|
|
68
81
|
blockModel.resetUserModifiedFields?.();
|
|
82
|
+
return getResponseRecord(data) ?? blockModel.getCurrentRecord?.();
|
|
69
83
|
}
|
|
70
84
|
}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { isObservable, reaction, toJS } from '@formily/reactive';
|
|
11
|
-
import { FlowContext, FlowModel, isRunJSValue, normalizeRunJSValue
|
|
11
|
+
import { FlowContext, FlowModel, isRunJSValue, normalizeRunJSValue } from '@nocobase/flow-engine';
|
|
12
12
|
import { getValuesByPath } from '@nocobase/shared';
|
|
13
13
|
import _ from 'lodash';
|
|
14
14
|
import { dayjs } from '@nocobase/utils/client';
|
|
@@ -1718,7 +1718,7 @@ export class RuleEngine {
|
|
|
1718
1718
|
): Promise<any> {
|
|
1719
1719
|
try {
|
|
1720
1720
|
const { code, version } = normalizeRunJSValue(rawValue);
|
|
1721
|
-
const ret = await
|
|
1721
|
+
const ret = await evalCtx.runjs(code, undefined, { version });
|
|
1722
1722
|
if (!ret?.success) {
|
|
1723
1723
|
if (seq !== state.runSeq) return SKIP_RULE_VALUE;
|
|
1724
1724
|
this.commitRuleDeps(rule, state, collector);
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { ElementProxy, tExpr
|
|
10
|
+
import { ElementProxy, tExpr } from '@nocobase/flow-engine';
|
|
11
11
|
import React from 'react';
|
|
12
12
|
import { BlockModel } from '../../base';
|
|
13
13
|
import { BlockItemCard } from '../../../components';
|
|
@@ -167,12 +167,7 @@ ctx.render(\`
|
|
|
167
167
|
},
|
|
168
168
|
},
|
|
169
169
|
});
|
|
170
|
-
|
|
171
|
-
await ctx.runjs(
|
|
172
|
-
code,
|
|
173
|
-
{ window: createSafeWindow({ navigator }), document: createSafeDocument(), navigator },
|
|
174
|
-
{ version },
|
|
175
|
-
);
|
|
170
|
+
await ctx.runjs(code, undefined, { version });
|
|
176
171
|
});
|
|
177
172
|
},
|
|
178
173
|
},
|
|
@@ -19,9 +19,6 @@ import {
|
|
|
19
19
|
createRecordMetaFactory,
|
|
20
20
|
createRecordResolveOnServerWithLocal,
|
|
21
21
|
ElementProxy,
|
|
22
|
-
createSafeDocument,
|
|
23
|
-
createSafeWindow,
|
|
24
|
-
createSafeNavigator,
|
|
25
22
|
observer,
|
|
26
23
|
} from '@nocobase/flow-engine';
|
|
27
24
|
import { Tooltip } from 'antd';
|
|
@@ -294,12 +291,7 @@ JSColumnModel.registerFlow({
|
|
|
294
291
|
get: () => new ElementProxy((ctx.ref?.current as HTMLElement | null) || element),
|
|
295
292
|
cache: false,
|
|
296
293
|
});
|
|
297
|
-
|
|
298
|
-
await ctx.runjs(
|
|
299
|
-
code,
|
|
300
|
-
{ window: createSafeWindow({ navigator }), document: createSafeDocument(), navigator },
|
|
301
|
-
{ version },
|
|
302
|
-
);
|
|
294
|
+
await ctx.runjs(code, undefined, { version });
|
|
303
295
|
});
|
|
304
296
|
},
|
|
305
297
|
},
|
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
observer,
|
|
23
23
|
} from '@nocobase/flow-engine';
|
|
24
24
|
import { Skeleton, Tooltip } from 'antd';
|
|
25
|
+
import classNames from 'classnames';
|
|
25
26
|
import React from 'react';
|
|
26
27
|
import { ActionModel } from '../../base/ActionModel';
|
|
27
28
|
import { TableCustomColumnModel } from './TableCustomColumnModel';
|
|
@@ -33,6 +34,33 @@ const rowActionButtonTypeOptions = [
|
|
|
33
34
|
{ value: 'link', label: '{{t("Link")}}' },
|
|
34
35
|
{ value: 'text', label: '{{t("Text")}}' },
|
|
35
36
|
];
|
|
37
|
+
export const tableRowActionsClassName = css`
|
|
38
|
+
display: flex;
|
|
39
|
+
flex-wrap: wrap;
|
|
40
|
+
align-items: center;
|
|
41
|
+
line-height: inherit;
|
|
42
|
+
> div:empty {
|
|
43
|
+
display: none;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.nb-table-row-action-button.ant-btn-link,
|
|
47
|
+
.nb-table-row-action-button.ant-btn-text {
|
|
48
|
+
display: inline-flex;
|
|
49
|
+
align-items: center;
|
|
50
|
+
font: inherit;
|
|
51
|
+
height: auto;
|
|
52
|
+
line-height: inherit;
|
|
53
|
+
padding: 0;
|
|
54
|
+
border: 0;
|
|
55
|
+
box-shadow: none;
|
|
56
|
+
vertical-align: baseline;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.nb-table-row-action-button.ant-btn-link > span,
|
|
60
|
+
.nb-table-row-action-button.ant-btn-text > span {
|
|
61
|
+
line-height: inherit;
|
|
62
|
+
}
|
|
63
|
+
`;
|
|
36
64
|
|
|
37
65
|
const Columns = observer<any>(({ record, model, index }) => {
|
|
38
66
|
const isConfigMode = !!model.context.flowSettingsEnabled;
|
|
@@ -42,17 +70,7 @@ const Columns = observer<any>(({ record, model, index }) => {
|
|
|
42
70
|
<DndProvider>
|
|
43
71
|
<div
|
|
44
72
|
style={{ gap: model.context?.themeToken?.marginSM ?? 16 }}
|
|
45
|
-
className={
|
|
46
|
-
display: flex;
|
|
47
|
-
flex-wrap: wrap;
|
|
48
|
-
align-items: center;
|
|
49
|
-
> div:empty {
|
|
50
|
-
display: none;
|
|
51
|
-
}
|
|
52
|
-
button {
|
|
53
|
-
padding: 0;
|
|
54
|
-
}
|
|
55
|
-
`}
|
|
73
|
+
className={`nb-table-row-actions ${tableRowActionsClassName}`}
|
|
56
74
|
>
|
|
57
75
|
{model.mapSubModels('actions', (action: ActionModel) => {
|
|
58
76
|
// Static hidden can be skipped safely; dynamic hidden is handled by fork.beforeRender + model.render wrapper.
|
|
@@ -68,7 +86,12 @@ const Columns = observer<any>(({ record, model, index }) => {
|
|
|
68
86
|
cachedFork.dispose();
|
|
69
87
|
}
|
|
70
88
|
|
|
71
|
-
const fork = action.createFork(
|
|
89
|
+
const fork = action.createFork(
|
|
90
|
+
{
|
|
91
|
+
className: classNames(action.props?.className, 'nb-table-row-action-button'),
|
|
92
|
+
},
|
|
93
|
+
slotKey,
|
|
94
|
+
);
|
|
72
95
|
(fork as any).buttonTypeOptions = rowActionButtonTypeOptions;
|
|
73
96
|
recordIdentityByFork.set(fork, recordIdentity);
|
|
74
97
|
|
|
@@ -140,7 +163,7 @@ const AddActionToolbarComponent = observer(({ model }: any) => {
|
|
|
140
163
|
subModelBaseClass={model.context.getModelClassName('RecordActionGroupModel')}
|
|
141
164
|
subModelKey="actions"
|
|
142
165
|
afterSubModelInit={async (actionModel) => {
|
|
143
|
-
actionModel.setStepParams('buttonSettings', 'general', { type: 'link', icon: null });
|
|
166
|
+
actionModel.setStepParams('buttonSettings', 'general', { type: 'link', icon: null, iconOnly: false });
|
|
144
167
|
}}
|
|
145
168
|
>
|
|
146
169
|
<PlusOutlined />
|
|
@@ -55,6 +55,7 @@ import {
|
|
|
55
55
|
useDragSortRowComponent,
|
|
56
56
|
dragSortSettings,
|
|
57
57
|
dragSortBySettings,
|
|
58
|
+
hasSortField,
|
|
58
59
|
} from './dragSort';
|
|
59
60
|
|
|
60
61
|
const MemoizedTable = React.memo(Table);
|
|
@@ -179,11 +180,21 @@ const AddFieldColumn = ({ model }: { model: TableBlockModel }) => {
|
|
|
179
180
|
].filter(Boolean)}
|
|
180
181
|
keepDropdownOpen
|
|
181
182
|
>
|
|
182
|
-
|
|
183
|
+
{renderTableSettingsButton(model, 'Fields')}
|
|
183
184
|
</AddSubModelButton>
|
|
184
185
|
);
|
|
185
186
|
};
|
|
186
187
|
|
|
188
|
+
function renderTableSettingsButton(model: TableBlockModel, title: string) {
|
|
189
|
+
const label = model.translate(title);
|
|
190
|
+
|
|
191
|
+
return (
|
|
192
|
+
<FlowSettingsButton aria-label={label} icon={<SettingOutlined />}>
|
|
193
|
+
{model.context.isMobileLayout ? null : label}
|
|
194
|
+
</FlowSettingsButton>
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
|
|
187
198
|
type CustomTableBlockModelClassesEnum = {
|
|
188
199
|
CollectionActionGroupModel?: string;
|
|
189
200
|
RecordActionGroupModel?: string;
|
|
@@ -265,7 +276,7 @@ export class TableBlockModel extends CollectionBlockModel<TableBlockModelStructu
|
|
|
265
276
|
cols.push({
|
|
266
277
|
key: 'addColumn',
|
|
267
278
|
fixed: 'right',
|
|
268
|
-
width: 100,
|
|
279
|
+
...(this.context.isMobileLayout ? {} : { width: 100 }),
|
|
269
280
|
title: <AddFieldColumn model={this} />,
|
|
270
281
|
} as any);
|
|
271
282
|
}
|
|
@@ -419,9 +430,18 @@ export class TableBlockModel extends CollectionBlockModel<TableBlockModelStructu
|
|
|
419
430
|
return nextIndex;
|
|
420
431
|
}
|
|
421
432
|
|
|
433
|
+
getDragSortFieldName(): string | undefined {
|
|
434
|
+
const dragSortBy = this.props.dragSortBy;
|
|
435
|
+
if (!this.props.dragSort || typeof dragSortBy !== 'string' || !hasSortField(this.collection, dragSortBy)) {
|
|
436
|
+
return undefined;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
return dragSortBy;
|
|
440
|
+
}
|
|
441
|
+
|
|
422
442
|
getLeftAuxiliaryColumn() {
|
|
423
443
|
const showIndex = this.isShowIndexEnabled();
|
|
424
|
-
const showDragHandle = this.
|
|
444
|
+
const showDragHandle = !!this.getDragSortFieldName();
|
|
425
445
|
if (!showIndex && !showDragHandle) {
|
|
426
446
|
return null;
|
|
427
447
|
}
|
|
@@ -467,7 +487,7 @@ export class TableBlockModel extends CollectionBlockModel<TableBlockModelStructu
|
|
|
467
487
|
index = this.getRecordIndex(record, index);
|
|
468
488
|
const rowKey = getRowKey(record, this.collection.filterTargetKey);
|
|
469
489
|
const rowKeyString = rowKey == null ? rowKey : String(rowKey);
|
|
470
|
-
const showDragHandle = this.
|
|
490
|
+
const showDragHandle = !!this.getDragSortFieldName();
|
|
471
491
|
return (
|
|
472
492
|
<div
|
|
473
493
|
role="button"
|
|
@@ -508,7 +528,7 @@ export class TableBlockModel extends CollectionBlockModel<TableBlockModelStructu
|
|
|
508
528
|
subModelBaseClass={this.getModelClassName('CollectionActionGroupModel')}
|
|
509
529
|
subModelKey="actions"
|
|
510
530
|
>
|
|
511
|
-
|
|
531
|
+
{renderTableSettingsButton(this, 'Actions')}
|
|
512
532
|
</AddSubModelButton>
|
|
513
533
|
);
|
|
514
534
|
}
|
|
@@ -1072,11 +1092,13 @@ const HighPerformanceTable = React.memo(
|
|
|
1072
1092
|
};
|
|
1073
1093
|
}, [rowKeys]);
|
|
1074
1094
|
|
|
1095
|
+
const dragSortFieldName = model.getDragSortFieldName();
|
|
1096
|
+
|
|
1075
1097
|
// 拖拽相关的 Body Wrapper 组件
|
|
1076
|
-
const BodyWrapperComponent = useDragSortBodyWrapper(model, dataSourceRef, getRowKeyFunc);
|
|
1098
|
+
const BodyWrapperComponent = useDragSortBodyWrapper(model, dataSourceRef, getRowKeyFunc, dragSortFieldName);
|
|
1077
1099
|
|
|
1078
1100
|
// 行组件
|
|
1079
|
-
const RowComponent = useDragSortRowComponent(
|
|
1101
|
+
const RowComponent = useDragSortRowComponent(!!dragSortFieldName);
|
|
1080
1102
|
|
|
1081
1103
|
const components = useMemo(() => {
|
|
1082
1104
|
return {
|
|
@@ -1099,15 +1121,14 @@ const HighPerformanceTable = React.memo(
|
|
|
1099
1121
|
}
|
|
1100
1122
|
`;
|
|
1101
1123
|
|
|
1102
|
-
const selectionPaddingClass =
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
: undefined;
|
|
1124
|
+
const selectionPaddingClass = dragSortFieldName
|
|
1125
|
+
? css`
|
|
1126
|
+
.ant-table-thead > tr > th.ant-table-selection-column,
|
|
1127
|
+
.ant-table-tbody > tr > td.ant-table-selection-column {
|
|
1128
|
+
padding-left: 32px !important;
|
|
1129
|
+
}
|
|
1130
|
+
`
|
|
1131
|
+
: undefined;
|
|
1111
1132
|
|
|
1112
1133
|
const tableBodyMinHeightClass = tableScroll?.y
|
|
1113
1134
|
? css`
|
|
@@ -1118,7 +1139,7 @@ const HighPerformanceTable = React.memo(
|
|
|
1118
1139
|
: undefined;
|
|
1119
1140
|
|
|
1120
1141
|
return classNames(baseClass, selectionPaddingClass, tableBodyMinHeightClass);
|
|
1121
|
-
}, [
|
|
1142
|
+
}, [dragSortFieldName, tableScroll?.y]);
|
|
1122
1143
|
|
|
1123
1144
|
return (
|
|
1124
1145
|
<MemoizedTable
|
|
@@ -13,17 +13,22 @@ import { App, ConfigProvider } from 'antd';
|
|
|
13
13
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
14
14
|
import { FlowEngine, FlowEngineProvider } from '@nocobase/flow-engine';
|
|
15
15
|
import { ActionModel } from '../../../base/ActionModel';
|
|
16
|
-
import { TableActionsColumnModel } from '../TableActionsColumnModel';
|
|
16
|
+
import { TableActionsColumnModel, tableRowActionsClassName } from '../TableActionsColumnModel';
|
|
17
17
|
|
|
18
18
|
const capturedDroppableUids: string[] = [];
|
|
19
19
|
const capturedRendererProps: any[] = [];
|
|
20
20
|
let latestOnDragEnd: ((event: any) => void) | undefined;
|
|
21
21
|
const capturedDndProviders: Array<{ persist: boolean }> = [];
|
|
22
|
+
const capturedAddSubModelButtonProps: any[] = [];
|
|
22
23
|
|
|
23
24
|
vi.mock('@nocobase/flow-engine', async () => {
|
|
24
25
|
const actual = await vi.importActual<any>('@nocobase/flow-engine');
|
|
25
26
|
return {
|
|
26
27
|
...actual,
|
|
28
|
+
AddSubModelButton: (props) => {
|
|
29
|
+
capturedAddSubModelButtonProps.push(props);
|
|
30
|
+
return <button data-testid="add-sub-model-button">{props.children}</button>;
|
|
31
|
+
},
|
|
27
32
|
DndProvider: ({ children, onDragEnd, persist = true, ...restProps }) => {
|
|
28
33
|
const engine = actual.useFlowEngine();
|
|
29
34
|
const handleDragEnd = (event: any) => {
|
|
@@ -50,6 +55,17 @@ vi.mock('@nocobase/flow-engine', async () => {
|
|
|
50
55
|
const ActualFlowModelRenderer = actual.FlowModelRenderer;
|
|
51
56
|
return <ActualFlowModelRenderer {...props} />;
|
|
52
57
|
},
|
|
58
|
+
FlowsFloatContextMenu: ({ children, extraToolbarItems = [], model }) => {
|
|
59
|
+
return (
|
|
60
|
+
<div data-test-flow-context-menu>
|
|
61
|
+
{children}
|
|
62
|
+
{extraToolbarItems.map((item) => {
|
|
63
|
+
const Component = item.component;
|
|
64
|
+
return <Component key={item.key} model={model} />;
|
|
65
|
+
})}
|
|
66
|
+
</div>
|
|
67
|
+
);
|
|
68
|
+
},
|
|
53
69
|
};
|
|
54
70
|
});
|
|
55
71
|
|
|
@@ -61,6 +77,10 @@ class TestAlwaysActionModel extends ActionModel {
|
|
|
61
77
|
defaultProps: any = { type: 'link', title: 'Always' };
|
|
62
78
|
}
|
|
63
79
|
|
|
80
|
+
class TestTextActionModel extends ActionModel {
|
|
81
|
+
defaultProps: any = { type: 'text', title: 'Text action' };
|
|
82
|
+
}
|
|
83
|
+
|
|
64
84
|
// 在 beforeRender 中,根据 inputArgs(即当前行 record)决定是否隐藏按钮
|
|
65
85
|
TestViewActionModel.registerFlow({
|
|
66
86
|
key: 'autoHideByPhone',
|
|
@@ -158,6 +178,58 @@ describe('TableActionsColumnModel: hidden action layout', () => {
|
|
|
158
178
|
expect(wrappers).toHaveLength(0);
|
|
159
179
|
expect(secondUid).toBeTruthy();
|
|
160
180
|
});
|
|
181
|
+
|
|
182
|
+
it('renders row link and text actions with compact button styles', async () => {
|
|
183
|
+
const engine = new FlowEngine();
|
|
184
|
+
engine.registerModels({ TableActionsColumnModel, TestViewActionModel, TestTextActionModel });
|
|
185
|
+
|
|
186
|
+
const actionsCol = engine.createModel<TableActionsColumnModel>({
|
|
187
|
+
use: 'TableActionsColumnModel',
|
|
188
|
+
props: { width: 200, title: 'Actions' },
|
|
189
|
+
subModels: { actions: [{ use: 'TestViewActionModel' }, { use: 'TestTextActionModel' }] },
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
const colProps = actionsCol.getColumnProps();
|
|
193
|
+
const record = { id: 1, phone: '000000' } as any;
|
|
194
|
+
|
|
195
|
+
const { container } = render(
|
|
196
|
+
<FlowEngineProvider engine={engine}>
|
|
197
|
+
<ConfigProvider>
|
|
198
|
+
<App>{colProps.render?.(undefined, record, 0) as any}</App>
|
|
199
|
+
</ConfigProvider>
|
|
200
|
+
</FlowEngineProvider>,
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
await waitFor(() => {
|
|
204
|
+
expect(screen.getByText('View')).toBeInTheDocument();
|
|
205
|
+
expect(screen.getByText('Text action')).toBeInTheDocument();
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
const actions = container.querySelector('.nb-table-row-actions');
|
|
209
|
+
expect(actions).toBeInTheDocument();
|
|
210
|
+
expect(actions).toHaveClass(tableRowActionsClassName);
|
|
211
|
+
|
|
212
|
+
const linkButton = actions?.querySelector('.ant-btn-link') as HTMLButtonElement;
|
|
213
|
+
const textButton = actions?.querySelector('.ant-btn-text') as HTMLButtonElement;
|
|
214
|
+
|
|
215
|
+
expect(linkButton).toBeInTheDocument();
|
|
216
|
+
expect(textButton).toBeInTheDocument();
|
|
217
|
+
expect(linkButton).toHaveClass('nb-table-row-action-button');
|
|
218
|
+
expect(textButton).toHaveClass('nb-table-row-action-button');
|
|
219
|
+
|
|
220
|
+
const actionButtonStyleText = Array.from(document.querySelectorAll('style'))
|
|
221
|
+
.map((style) => style.textContent || '')
|
|
222
|
+
.find((styleText) => styleText.includes('.nb-table-row-action-button.ant-btn-link'));
|
|
223
|
+
expect(actionButtonStyleText).toContain(tableRowActionsClassName);
|
|
224
|
+
expect(actionButtonStyleText).toContain('font:inherit');
|
|
225
|
+
expect(actionButtonStyleText).toContain('height:auto');
|
|
226
|
+
expect(actionButtonStyleText).toContain('line-height:inherit');
|
|
227
|
+
expect(actionButtonStyleText).toContain('padding:0');
|
|
228
|
+
expect(actionButtonStyleText).toContain('border:0');
|
|
229
|
+
expect(actionButtonStyleText).toContain('box-shadow:none');
|
|
230
|
+
expect(actionButtonStyleText).not.toContain('1.5714285714285714');
|
|
231
|
+
expect(actionButtonStyleText).not.toContain('!important');
|
|
232
|
+
});
|
|
161
233
|
});
|
|
162
234
|
|
|
163
235
|
describe('TableActionsColumnModel: drag integration', () => {
|
|
@@ -165,6 +237,7 @@ describe('TableActionsColumnModel: drag integration', () => {
|
|
|
165
237
|
capturedDroppableUids.length = 0;
|
|
166
238
|
capturedRendererProps.length = 0;
|
|
167
239
|
capturedDndProviders.length = 0;
|
|
240
|
+
capturedAddSubModelButtonProps.length = 0;
|
|
168
241
|
latestOnDragEnd = undefined;
|
|
169
242
|
});
|
|
170
243
|
|
|
@@ -177,6 +250,7 @@ describe('TableActionsColumnModel: drag integration', () => {
|
|
|
177
250
|
props: { width: 200, title: 'Actions' },
|
|
178
251
|
subModels: { actions: [{ use: 'TestViewActionModel' }, { use: 'TestViewActionModel' }] },
|
|
179
252
|
});
|
|
253
|
+
actionsCol.context.defineMethod('getModelClassName', (className: string) => className);
|
|
180
254
|
|
|
181
255
|
const colProps = actionsCol.getColumnProps();
|
|
182
256
|
const record = { id: 1, phone: '000000' } as any;
|
|
@@ -279,4 +353,40 @@ describe('TableActionsColumnModel: drag integration', () => {
|
|
|
279
353
|
|
|
280
354
|
expect(moveModelSpy).toHaveBeenCalledWith(firstUid, secondUid, { persist: true });
|
|
281
355
|
});
|
|
356
|
+
|
|
357
|
+
it('disables icon-only mode when adding row actions without icons', async () => {
|
|
358
|
+
const engine = new FlowEngine();
|
|
359
|
+
engine.registerModels({ TableActionsColumnModel, TestViewActionModel });
|
|
360
|
+
|
|
361
|
+
const actionsCol = engine.createModel<TableActionsColumnModel>({
|
|
362
|
+
use: 'TableActionsColumnModel',
|
|
363
|
+
props: { width: 200, title: 'Actions' },
|
|
364
|
+
});
|
|
365
|
+
actionsCol.context.defineMethod('getModelClassName', (className: string) => className);
|
|
366
|
+
|
|
367
|
+
render(
|
|
368
|
+
<FlowEngineProvider engine={engine}>
|
|
369
|
+
<ConfigProvider>
|
|
370
|
+
<App>{actionsCol.getColumnProps().title as React.ReactNode}</App>
|
|
371
|
+
</ConfigProvider>
|
|
372
|
+
</FlowEngineProvider>,
|
|
373
|
+
);
|
|
374
|
+
|
|
375
|
+
const addButtonProps = capturedAddSubModelButtonProps.find(
|
|
376
|
+
(props) => props.subModelKey === 'actions' && props.subModelBaseClass === 'RecordActionGroupModel',
|
|
377
|
+
);
|
|
378
|
+
expect(addButtonProps).toBeDefined();
|
|
379
|
+
expect(addButtonProps.afterSubModelInit).toBeTypeOf('function');
|
|
380
|
+
|
|
381
|
+
const actionModel = {
|
|
382
|
+
setStepParams: vi.fn(),
|
|
383
|
+
};
|
|
384
|
+
await addButtonProps.afterSubModelInit(actionModel);
|
|
385
|
+
|
|
386
|
+
expect(actionModel.setStepParams).toHaveBeenCalledWith('buttonSettings', 'general', {
|
|
387
|
+
type: 'link',
|
|
388
|
+
icon: null,
|
|
389
|
+
iconOnly: false,
|
|
390
|
+
});
|
|
391
|
+
});
|
|
282
392
|
});
|