@nocobase/client-v2 2.2.0-beta.7 → 2.2.0-beta.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/es/flow/actions/afterSuccess.d.ts +8 -1
  2. package/es/flow/actions/index.d.ts +1 -1
  3. package/es/flow/admin-shell/admin-layout/AdminLayoutSlotModels.d.ts +1 -0
  4. package/es/flow/models/blocks/form/submitHandler.d.ts +1 -1
  5. package/es/flow/models/blocks/form/value-runtime/runtime.d.ts +9 -0
  6. package/es/flow/models/blocks/js-block/JSBlock.d.ts +1 -0
  7. package/es/flow/models/blocks/table/TableActionsColumnModel.d.ts +1 -0
  8. package/es/flow/models/blocks/table/TableBlockModel.d.ts +1 -0
  9. package/es/flow/models/blocks/table/dragSort/dragSortHooks.d.ts +1 -1
  10. package/es/flow/models/blocks/table/dragSort/dragSortSettings.d.ts +2 -1
  11. package/es/flow/models/blocks/table/dragSort/dragSortUtils.d.ts +6 -4
  12. package/es/flow/resolveViewParamsToViewList.d.ts +1 -1
  13. package/es/index.mjs +103 -87
  14. package/lib/index.js +105 -89
  15. package/package.json +7 -7
  16. package/src/collection-manager/field-configure.ts +1 -1
  17. package/src/collection-manager/interfaces/id.ts +1 -1
  18. package/src/collection-manager/interfaces/m2m.tsx +2 -2
  19. package/src/collection-manager/interfaces/m2o.tsx +2 -2
  20. package/src/collection-manager/interfaces/nanoid.ts +1 -1
  21. package/src/collection-manager/interfaces/o2m.tsx +2 -2
  22. package/src/collection-manager/interfaces/obo.tsx +2 -2
  23. package/src/collection-manager/interfaces/oho.tsx +2 -2
  24. package/src/collection-manager/interfaces/properties/index.ts +2 -2
  25. package/src/collection-manager/interfaces/uuid.ts +1 -1
  26. package/src/flow/__tests__/getKey.test.ts +7 -0
  27. package/src/flow/__tests__/resolveViewParamsToViewList.test.ts +34 -0
  28. package/src/flow/actions/__tests__/afterSuccess.test.ts +73 -0
  29. package/src/flow/actions/__tests__/openView.defineProps.route.test.tsx +104 -0
  30. package/src/flow/actions/afterSuccess.tsx +142 -3
  31. package/src/flow/actions/index.ts +1 -1
  32. package/src/flow/actions/openView.tsx +38 -4
  33. package/src/flow/admin-shell/BaseLayoutModel.tsx +25 -3
  34. package/src/flow/admin-shell/BaseLayoutRouteCoordinator.ts +5 -2
  35. package/src/flow/admin-shell/__tests__/AdminLayoutRouteCoordinator.test.ts +13 -0
  36. package/src/flow/admin-shell/admin-layout/AdminLayoutComponent.tsx +1 -0
  37. package/src/flow/admin-shell/admin-layout/AdminLayoutSlotModels.tsx +5 -4
  38. package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutModel.test.tsx +82 -0
  39. package/src/flow/getViewDiffAndUpdateHidden.tsx +1 -0
  40. package/src/flow/models/base/ActionModelCore.tsx +6 -4
  41. package/src/flow/models/base/__tests__/ActionModelCore.render.test.tsx +37 -0
  42. package/src/flow/models/blocks/filter-form/fields/FilterFormCustomFieldModel.tsx +1 -1
  43. package/src/flow/models/blocks/form/FormActionModel.tsx +1 -1
  44. package/src/flow/models/blocks/form/__tests__/submitHandler.test.ts +54 -1
  45. package/src/flow/models/blocks/form/submitHandler.ts +17 -3
  46. package/src/flow/models/blocks/form/value-runtime/__tests__/runtime.test.ts +87 -0
  47. package/src/flow/models/blocks/form/value-runtime/runtime.ts +91 -0
  48. package/src/flow/models/blocks/js-block/JSBlock.tsx +223 -2
  49. package/src/flow/models/blocks/js-block/__tests__/JSBlockModel.test.tsx +150 -0
  50. package/src/flow/models/blocks/table/TableActionsColumnModel.tsx +35 -12
  51. package/src/flow/models/blocks/table/TableBlockModel.tsx +25 -14
  52. package/src/flow/models/blocks/table/__tests__/TableActionsColumnModel.test.tsx +57 -1
  53. package/src/flow/models/blocks/table/__tests__/TableBlockModel.dragSort.test.ts +127 -0
  54. package/src/flow/models/blocks/table/__tests__/TableBlockModel.rowSelection.test.tsx +1 -0
  55. package/src/flow/models/blocks/table/dragSort/dragSortHooks.tsx +28 -17
  56. package/src/flow/models/blocks/table/dragSort/dragSortSettings.ts +13 -6
  57. package/src/flow/models/blocks/table/dragSort/dragSortUtils.ts +15 -2
  58. package/src/flow/resolveViewParamsToViewList.tsx +11 -3
  59. package/src/settings-center/SystemSettingsPage.tsx +1 -1
@@ -13,7 +13,7 @@ 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[] = [];
@@ -77,6 +77,10 @@ class TestAlwaysActionModel extends ActionModel {
77
77
  defaultProps: any = { type: 'link', title: 'Always' };
78
78
  }
79
79
 
80
+ class TestTextActionModel extends ActionModel {
81
+ defaultProps: any = { type: 'text', title: 'Text action' };
82
+ }
83
+
80
84
  // 在 beforeRender 中,根据 inputArgs(即当前行 record)决定是否隐藏按钮
81
85
  TestViewActionModel.registerFlow({
82
86
  key: 'autoHideByPhone',
@@ -174,6 +178,58 @@ describe('TableActionsColumnModel: hidden action layout', () => {
174
178
  expect(wrappers).toHaveLength(0);
175
179
  expect(secondUid).toBeTruthy();
176
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
+ });
177
233
  });
178
234
 
179
235
  describe('TableActionsColumnModel: drag integration', () => {
@@ -0,0 +1,127 @@
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 } from '@nocobase/flow-engine';
11
+ import { describe, expect, it } from 'vitest';
12
+ import '@nocobase/client';
13
+ import { initDragSortParams } from '../dragSort';
14
+ import { TableBlockModel } from '../TableBlockModel';
15
+
16
+ function createTableModel() {
17
+ const engine = new FlowEngine();
18
+ engine.registerModels({ TableBlockModel });
19
+
20
+ const ds = engine.dataSourceManager.getDataSource('main');
21
+ ds.addCollection({
22
+ name: 'posts',
23
+ filterTargetKey: 'id',
24
+ fields: [
25
+ { name: 'id', type: 'integer', interface: 'number' },
26
+ { name: 'title', type: 'string', interface: 'input' },
27
+ { name: 'sort', type: 'sort', interface: 'sort' },
28
+ ],
29
+ });
30
+
31
+ return engine.createModel<TableBlockModel>({
32
+ uid: 'posts-table',
33
+ use: 'TableBlockModel',
34
+ stepParams: {
35
+ resourceSettings: {
36
+ init: {
37
+ dataSourceKey: 'main',
38
+ collectionName: 'posts',
39
+ },
40
+ },
41
+ },
42
+ });
43
+ }
44
+
45
+ describe('TableBlockModel drag sorting settings', () => {
46
+ it('does not keep a deleted drag sort field in resource sort', () => {
47
+ const model = createTableModel();
48
+
49
+ model.setProps('dragSort', true);
50
+ model.setProps('dragSortBy', 'sort');
51
+ model.setProps('globalSort', ['title']);
52
+ model.resource.setSort(['sort']);
53
+ model.collection.fields.delete('sort');
54
+
55
+ initDragSortParams(model);
56
+
57
+ expect(model.getDragSortFieldName()).toBeUndefined();
58
+ expect(model.resource.getSort()).toEqual(['title']);
59
+ });
60
+
61
+ it('hides the drag handle when the configured sort field was deleted', () => {
62
+ const model = createTableModel();
63
+
64
+ model.setProps('enableRowSelection', false);
65
+ model.setProps('showIndex', false);
66
+ model.setProps('dragSort', true);
67
+ model.setProps('dragSortBy', 'sort');
68
+ model.collection.fields.delete('sort');
69
+
70
+ expect(model.getLeftAuxiliaryColumn()).toBeNull();
71
+ });
72
+
73
+ it('allows clearing the configured drag sort field and restores default sorting', () => {
74
+ const model = createTableModel();
75
+ const dragSortByStep = model.getFlow('tableSettings')?.steps?.dragSortBy;
76
+
77
+ model.setProps('dragSort', true);
78
+ model.setProps('dragSortBy', 'sort');
79
+ model.setProps('globalSort', ['title']);
80
+ model.resource.setSort(['sort']);
81
+
82
+ const uiMode =
83
+ typeof dragSortByStep?.uiMode === 'function' ? dragSortByStep.uiMode({ model, t: (key: string) => key }) : null;
84
+ dragSortByStep?.handler({ model }, { dragSortBy: null });
85
+
86
+ expect(uiMode).toMatchObject({
87
+ type: 'select',
88
+ key: 'dragSortBy',
89
+ props: {
90
+ allowClear: true,
91
+ },
92
+ });
93
+ expect(model.props.dragSortBy).toBeNull();
94
+ expect(model.resource.getSort()).toEqual(['title']);
95
+ });
96
+
97
+ it('ignores a deleted drag sort field submitted by settings', () => {
98
+ const model = createTableModel();
99
+ const dragSortByStep = model.getFlow('tableSettings')?.steps?.dragSortBy;
100
+
101
+ model.setProps('dragSort', true);
102
+ model.setProps('dragSortBy', 'sort');
103
+ model.setProps('globalSort', ['title']);
104
+ model.resource.setSort(['sort']);
105
+ model.collection.fields.delete('sort');
106
+
107
+ dragSortByStep?.handler({ model }, { dragSortBy: 'sort' });
108
+
109
+ expect(model.props.dragSortBy).toBeNull();
110
+ expect(model.resource.getSort()).toEqual(['title']);
111
+ });
112
+
113
+ it('restores default sorting when drag sorting is disabled', () => {
114
+ const model = createTableModel();
115
+ const dragSortStep = model.getFlow('tableSettings')?.steps?.dragSort;
116
+
117
+ model.setProps('dragSort', true);
118
+ model.setProps('dragSortBy', 'sort');
119
+ model.setProps('globalSort', ['title']);
120
+ model.resource.setSort(['sort']);
121
+
122
+ dragSortStep?.handler({ model }, { dragSort: false });
123
+
124
+ expect(model.props.dragSort).toBe(false);
125
+ expect(model.resource.getSort()).toEqual(['title']);
126
+ });
127
+ });
@@ -26,6 +26,7 @@ function createTableModel() {
26
26
  fields: [
27
27
  { name: 'id', type: 'integer', interface: 'number' },
28
28
  { name: 'title', type: 'string', interface: 'input' },
29
+ { name: 'sort', type: 'sort', interface: 'sort' },
29
30
  ],
30
31
  });
31
32
 
@@ -19,16 +19,23 @@ export function useDragSortBodyWrapper(
19
19
  model: TableBlockModel,
20
20
  dataSourceRef: React.MutableRefObject<any>,
21
21
  getRowKeyFunc: (record: any) => string | number,
22
+ dragSortFieldName?: string,
22
23
  ) {
24
+ const expandedRowKeys = model.props.expandedRowKeys;
25
+ const defaultExpandAllRows = model.props.defaultExpandAllRows;
26
+ const resource = model.resource;
27
+ const filterTargetKey = model.collection.filterTargetKey;
28
+ const message = (model as { ctx?: { message?: { error?: (content: string) => void } } }).ctx?.message;
29
+
23
30
  return useMemo(() => {
24
- if (!model.props.dragSort) {
31
+ if (!dragSortFieldName) {
25
32
  return (props) => <tbody {...props} />;
26
33
  }
27
34
 
28
35
  const flattenTreeData = (data: any[]) => {
29
36
  const result: any[] = [];
30
- const expandedKeys = new Set((model.props.expandedRowKeys || []).map((key) => (key == null ? key : String(key))));
31
- const includeAll = !!model.props.defaultExpandAllRows;
37
+ const expandedKeys = new Set((expandedRowKeys || []).map((key) => (key == null ? key : String(key))));
38
+ const includeAll = !!defaultExpandAllRows;
32
39
 
33
40
  const walk = (nodes: any[]) => {
34
41
  if (!nodes?.length) return;
@@ -73,22 +80,22 @@ export function useDragSortBodyWrapper(
73
80
  }
74
81
 
75
82
  if (from && to) {
76
- model.resource
83
+ resource
77
84
  .runAction('move', {
78
85
  method: 'post',
79
86
  params: {
80
- sourceId: getRowKey(from, model.collection.filterTargetKey),
81
- targetId: getRowKey(to, model.collection.filterTargetKey),
82
- sortField: model.props.dragSort ? model.props.dragSortBy : undefined,
87
+ sourceId: getRowKey(from, filterTargetKey),
88
+ targetId: getRowKey(to, filterTargetKey),
89
+ sortField: dragSortFieldName,
83
90
  },
84
91
  })
85
92
  .then(() => {
86
- model.resource.refresh();
93
+ resource.refresh();
87
94
  })
88
95
  .catch((error) => {
89
96
  console.error('Move failed:', error);
90
97
  // Show a user-facing error message if the message system is available
91
- (model as any)?.ctx?.message?.error?.(error?.message || 'Move failed');
98
+ message?.error?.(error?.message || 'Move failed');
92
99
  });
93
100
  }
94
101
  };
@@ -104,13 +111,14 @@ export function useDragSortBodyWrapper(
104
111
  );
105
112
  };
106
113
  }, [
107
- model.props.dragSort,
108
- model.props.dragSortBy,
109
- model.props.expandedRowKeys,
110
- model.props.defaultExpandAllRows,
111
- model.resource,
112
- model.collection.filterTargetKey,
114
+ dataSourceRef,
115
+ defaultExpandAllRows,
116
+ dragSortFieldName,
117
+ expandedRowKeys,
118
+ filterTargetKey,
113
119
  getRowKeyFunc,
120
+ message,
121
+ resource,
114
122
  ]);
115
123
  }
116
124
 
@@ -124,7 +132,10 @@ export function useDragSortRowComponent(dragSort: boolean) {
124
132
  }
125
133
 
126
134
  export function initDragSortParams(model: TableBlockModel) {
127
- if (model.props.dragSort && model.props.dragSortBy) {
128
- model.resource.setSort([model.props.dragSortBy]);
135
+ const dragSortFieldName = model.getDragSortFieldName();
136
+ if (dragSortFieldName) {
137
+ model.resource.setSort([dragSortFieldName]);
138
+ } else if (model.props.dragSort && model.props.dragSortBy) {
139
+ model.resource.setSort(Array.isArray(model.props.globalSort) ? model.props.globalSort : []);
129
140
  }
130
141
  }
@@ -9,7 +9,11 @@
9
9
 
10
10
  import { tExpr } from '@nocobase/flow-engine';
11
11
  import type { TableBlockModel } from '../TableBlockModel';
12
- import { convertFieldsToOptions, getSortFields } from './dragSortUtils';
12
+ import { convertFieldsToOptions, getSortFields, hasSortField } from './dragSortUtils';
13
+
14
+ function getFallbackSort(model: TableBlockModel): string[] {
15
+ return Array.isArray(model.props.globalSort) ? model.props.globalSort : [];
16
+ }
13
17
 
14
18
  export const dragSortSettings = {
15
19
  title: tExpr('Enable drag and drop sorting'),
@@ -17,9 +21,12 @@ export const dragSortSettings = {
17
21
  defaultParams: {
18
22
  dragSort: false,
19
23
  },
20
- async handler(ctx, params) {
24
+ handler(ctx, params) {
21
25
  const model = ctx.model as TableBlockModel;
22
26
  model.setProps('dragSort', params.dragSort);
27
+ if (!params.dragSort) {
28
+ model.resource.setSort(getFallbackSort(model));
29
+ }
23
30
 
24
31
  // Note: automatic configuration of the drag sort field has been removed;
25
32
  // users now configure `dragSortBy` explicitly via `dragSortBySettings`.
@@ -45,6 +52,7 @@ export const dragSortBySettings = {
45
52
  key: 'dragSortBy',
46
53
  props: {
47
54
  options,
55
+ allowClear: true,
48
56
  placeholder: ctx.t('Select field'),
49
57
  },
50
58
  };
@@ -54,9 +62,8 @@ export const dragSortBySettings = {
54
62
  },
55
63
  handler(ctx, params) {
56
64
  const model = ctx.model as TableBlockModel;
57
- model.setProps('dragSortBy', params.dragSortBy);
58
- if (params.dragSortBy) {
59
- model.resource.setSort([params.dragSortBy]);
60
- }
65
+ const dragSortBy = hasSortField(model.collection, params.dragSortBy) ? params.dragSortBy : null;
66
+ model.setProps('dragSortBy', dragSortBy);
67
+ model.resource.setSort(dragSortBy ? [dragSortBy] : getFallbackSort(model));
61
68
  },
62
69
  };
@@ -7,7 +7,7 @@
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
9
 
10
- import type { Collection } from '@nocobase/flow-engine';
10
+ import type { Collection, CollectionField } from '@nocobase/flow-engine';
11
11
 
12
12
  /**
13
13
  * 从 collection 中获取所有 sort 类型的字段
@@ -24,6 +24,19 @@ export function getSortFields(collection: Collection | undefined) {
24
24
  });
25
25
  }
26
26
 
27
+ export function getSortField(
28
+ collection: Collection | undefined,
29
+ fieldName?: string | null,
30
+ ): CollectionField | undefined {
31
+ if (!collection || !fieldName) return undefined;
32
+
33
+ return getSortFields(collection).find((field) => field.name === fieldName);
34
+ }
35
+
36
+ export function hasSortField(collection: Collection | undefined, fieldName?: string | null): boolean {
37
+ return !!getSortField(collection, fieldName);
38
+ }
39
+
27
40
  /**
28
41
  * 获取 collection 中第一个可用的 sort 字段
29
42
  * @param collection - 集合对象
@@ -39,7 +52,7 @@ export function getFirstSortField(collection: Collection | undefined) {
39
52
  * @param fields - 字段数组
40
53
  * @returns 选项数组
41
54
  */
42
- export function convertFieldsToOptions(fields: any[]) {
55
+ export function convertFieldsToOptions(fields: CollectionField[]) {
43
56
  return fields.map((field) => ({
44
57
  label: field?.uiSchema?.title || field?.name,
45
58
  value: field?.name,
@@ -49,12 +49,12 @@ export function resolveViewParamsToViewList(
49
49
  return viewItems;
50
50
  }
51
51
 
52
- export function updateViewListHidden(viewItems: ViewItem[]) {
52
+ export function updateViewListHidden(viewItems: ViewItem[], isMobileLayout = false) {
53
53
  // Calculate hidden values based on view types and positions
54
54
  let hasEmbedAfter = false;
55
55
  for (let i = viewItems.length - 1; i >= 0; i--) {
56
56
  const viewItem = viewItems[i];
57
- const viewType = getViewType(viewItem);
57
+ const viewType = getViewType(viewItem, isMobileLayout);
58
58
 
59
59
  if (viewType === 'embed' && !hasEmbedAfter) {
60
60
  hasEmbedAfter = true;
@@ -65,15 +65,23 @@ export function updateViewListHidden(viewItems: ViewItem[]) {
65
65
  }
66
66
  }
67
67
 
68
- function getViewType(viewItem: ViewItem): string {
68
+ function getViewType(viewItem: ViewItem, isMobileLayout = false): string {
69
69
  if (viewItem.model instanceof RouteModel) {
70
70
  return 'embed';
71
71
  }
72
72
 
73
+ if (isMobileLayout && viewItem.index > 0) {
74
+ return 'embed';
75
+ }
76
+
73
77
  if (!viewItem.model) {
74
78
  return 'drawer';
75
79
  }
76
80
 
81
+ if (viewItem.params.openViewRouteState?.mode) {
82
+ return viewItem.params.openViewRouteState.mode;
83
+ }
84
+
77
85
  const params = viewItem.model.getStepParams('popupSettings', 'openView');
78
86
  return params?.mode || 'drawer';
79
87
  }
@@ -239,7 +239,7 @@ export const SystemSettingsPage = () => {
239
239
  <Form.Item
240
240
  name="raw_title"
241
241
  label={t('System title')}
242
- rules={[{ required: true, message: t('Please enter') + t('System title') }]}
242
+ rules={[{ required: true, message: t('Please enter') + ' ' + t('System title') }]}
243
243
  >
244
244
  <Input.TextArea autoSize={{ minRows: 2, maxRows: 4 }} />
245
245
  </Form.Item>