@nocobase/client-v2 2.2.0-beta.6 → 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.
- package/es/PluginSettingsManager.d.ts +33 -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/AdminLayoutSlotModels.d.ts +1 -0
- package/es/flow/models/blocks/form/submitHandler.d.ts +1 -1
- package/es/flow/models/blocks/form/value-runtime/runtime.d.ts +9 -0
- package/es/flow/models/blocks/js-block/JSBlock.d.ts +1 -0
- 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.mjs +105 -89
- package/lib/index.js +106 -90
- package/package.json +7 -7
- package/src/PluginSettingsManager.ts +53 -0
- package/src/__tests__/PluginSettingsManager.test.ts +13 -0
- package/src/__tests__/plugin-manager.test.tsx +44 -2
- package/src/__tests__/settings-center.test.tsx +7 -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/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__/dataScopeFilter.test.ts +58 -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/dataScopeFilter.ts +10 -0
- package/src/flow/actions/index.ts +1 -1
- package/src/flow/actions/openView.tsx +38 -4
- 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 +1 -0
- package/src/flow/admin-shell/admin-layout/AdminLayoutSlotModels.tsx +5 -4
- package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutModel.test.tsx +82 -0
- package/src/flow/components/FieldAssignRulesEditor.tsx +66 -9
- package/src/flow/components/__tests__/FieldAssignRulesEditor.test.tsx +427 -0
- package/src/flow/components/__tests__/fieldAssignOptions.test.ts +151 -3
- package/src/flow/components/fieldAssignOptions.ts +155 -27
- package/src/flow/getViewDiffAndUpdateHidden.tsx +1 -0
- package/src/flow/models/base/ActionModelCore.tsx +6 -4
- package/src/flow/models/base/__tests__/ActionModelCore.render.test.tsx +37 -0
- 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/__tests__/submitHandler.test.ts +54 -1
- package/src/flow/models/blocks/form/submitHandler.ts +17 -3
- package/src/flow/models/blocks/form/value-runtime/__tests__/runtime.test.ts +87 -0
- package/src/flow/models/blocks/form/value-runtime/runtime.ts +91 -0
- package/src/flow/models/blocks/js-block/JSBlock.tsx +223 -2
- package/src/flow/models/blocks/js-block/__tests__/JSBlockModel.test.tsx +150 -0
- package/src/flow/models/blocks/table/TableActionsColumnModel.tsx +35 -12
- package/src/flow/models/blocks/table/TableBlockModel.tsx +25 -14
- package/src/flow/models/blocks/table/__tests__/TableActionsColumnModel.test.tsx +57 -1
- package/src/flow/models/blocks/table/__tests__/TableBlockModel.dragSort.test.ts +127 -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/resolveViewParamsToViewList.tsx +11 -3
- package/src/nocobase-buildin-plugin/index.tsx +0 -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
|
@@ -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);
|
|
@@ -429,9 +430,18 @@ export class TableBlockModel extends CollectionBlockModel<TableBlockModelStructu
|
|
|
429
430
|
return nextIndex;
|
|
430
431
|
}
|
|
431
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
|
+
|
|
432
442
|
getLeftAuxiliaryColumn() {
|
|
433
443
|
const showIndex = this.isShowIndexEnabled();
|
|
434
|
-
const showDragHandle = this.
|
|
444
|
+
const showDragHandle = !!this.getDragSortFieldName();
|
|
435
445
|
if (!showIndex && !showDragHandle) {
|
|
436
446
|
return null;
|
|
437
447
|
}
|
|
@@ -477,7 +487,7 @@ export class TableBlockModel extends CollectionBlockModel<TableBlockModelStructu
|
|
|
477
487
|
index = this.getRecordIndex(record, index);
|
|
478
488
|
const rowKey = getRowKey(record, this.collection.filterTargetKey);
|
|
479
489
|
const rowKeyString = rowKey == null ? rowKey : String(rowKey);
|
|
480
|
-
const showDragHandle = this.
|
|
490
|
+
const showDragHandle = !!this.getDragSortFieldName();
|
|
481
491
|
return (
|
|
482
492
|
<div
|
|
483
493
|
role="button"
|
|
@@ -1082,11 +1092,13 @@ const HighPerformanceTable = React.memo(
|
|
|
1082
1092
|
};
|
|
1083
1093
|
}, [rowKeys]);
|
|
1084
1094
|
|
|
1095
|
+
const dragSortFieldName = model.getDragSortFieldName();
|
|
1096
|
+
|
|
1085
1097
|
// 拖拽相关的 Body Wrapper 组件
|
|
1086
|
-
const BodyWrapperComponent = useDragSortBodyWrapper(model, dataSourceRef, getRowKeyFunc);
|
|
1098
|
+
const BodyWrapperComponent = useDragSortBodyWrapper(model, dataSourceRef, getRowKeyFunc, dragSortFieldName);
|
|
1087
1099
|
|
|
1088
1100
|
// 行组件
|
|
1089
|
-
const RowComponent = useDragSortRowComponent(
|
|
1101
|
+
const RowComponent = useDragSortRowComponent(!!dragSortFieldName);
|
|
1090
1102
|
|
|
1091
1103
|
const components = useMemo(() => {
|
|
1092
1104
|
return {
|
|
@@ -1109,15 +1121,14 @@ const HighPerformanceTable = React.memo(
|
|
|
1109
1121
|
}
|
|
1110
1122
|
`;
|
|
1111
1123
|
|
|
1112
|
-
const selectionPaddingClass =
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
: 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;
|
|
1121
1132
|
|
|
1122
1133
|
const tableBodyMinHeightClass = tableScroll?.y
|
|
1123
1134
|
? css`
|
|
@@ -1128,7 +1139,7 @@ const HighPerformanceTable = React.memo(
|
|
|
1128
1139
|
: undefined;
|
|
1129
1140
|
|
|
1130
1141
|
return classNames(baseClass, selectionPaddingClass, tableBodyMinHeightClass);
|
|
1131
|
-
}, [
|
|
1142
|
+
}, [dragSortFieldName, tableScroll?.y]);
|
|
1132
1143
|
|
|
1133
1144
|
return (
|
|
1134
1145
|
<MemoizedTable
|
|
@@ -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
|
+
});
|
|
@@ -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 (!
|
|
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((
|
|
31
|
-
const includeAll = !!
|
|
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
|
-
|
|
83
|
+
resource
|
|
77
84
|
.runAction('move', {
|
|
78
85
|
method: 'post',
|
|
79
86
|
params: {
|
|
80
|
-
sourceId: getRowKey(from,
|
|
81
|
-
targetId: getRowKey(to,
|
|
82
|
-
sortField:
|
|
87
|
+
sourceId: getRowKey(from, filterTargetKey),
|
|
88
|
+
targetId: getRowKey(to, filterTargetKey),
|
|
89
|
+
sortField: dragSortFieldName,
|
|
83
90
|
},
|
|
84
91
|
})
|
|
85
92
|
.then(() => {
|
|
86
|
-
|
|
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
|
-
|
|
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
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
-
|
|
128
|
-
|
|
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
|
-
|
|
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.
|
|
58
|
-
|
|
59
|
-
|
|
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:
|
|
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
|
}
|
|
@@ -355,7 +355,6 @@ export class NocoBaseBuildInPlugin extends Plugin<any, Application> {
|
|
|
355
355
|
title: this.app.i18n.t('System settings'),
|
|
356
356
|
icon: 'SettingOutlined',
|
|
357
357
|
aclSnippet: 'pm.system-settings.system-settings',
|
|
358
|
-
sort: -100,
|
|
359
358
|
});
|
|
360
359
|
this.app.pluginSettingsManager.addPageTabItem({
|
|
361
360
|
menuKey: 'system-settings',
|
|
@@ -363,7 +362,6 @@ export class NocoBaseBuildInPlugin extends Plugin<any, Application> {
|
|
|
363
362
|
title: this.app.i18n.t('System settings'),
|
|
364
363
|
componentLoader: () => import('../settings-center/SystemSettingsPage'),
|
|
365
364
|
aclSnippet: 'pm.system-settings.system-settings',
|
|
366
|
-
sort: -100,
|
|
367
365
|
});
|
|
368
366
|
// Parent menu for security-related plugin settings (password policy, locked users, etc.). Registered here in the buildin plugin so any pro plugin can attach page tabs to `menuKey: 'security'` without each one re-registering the same parent.
|
|
369
367
|
this.app.pluginSettingsManager.addMenuItem({
|
|
@@ -221,7 +221,6 @@ export const SystemSettingsPage = () => {
|
|
|
221
221
|
return (
|
|
222
222
|
<div
|
|
223
223
|
style={{
|
|
224
|
-
minHeight: '100%',
|
|
225
224
|
background: token.colorBgContainer,
|
|
226
225
|
borderRadius: token.borderRadiusLG,
|
|
227
226
|
padding: token.paddingLG,
|
|
@@ -240,7 +239,7 @@ export const SystemSettingsPage = () => {
|
|
|
240
239
|
<Form.Item
|
|
241
240
|
name="raw_title"
|
|
242
241
|
label={t('System title')}
|
|
243
|
-
rules={[{ required: true, message: t('Please enter') + t('System title') }]}
|
|
242
|
+
rules={[{ required: true, message: t('Please enter') + ' ' + t('System title') }]}
|
|
244
243
|
>
|
|
245
244
|
<Input.TextArea autoSize={{ minRows: 2, maxRows: 4 }} />
|
|
246
245
|
</Form.Item>
|
|
@@ -116,7 +116,7 @@ export const PluginCard: FC<PluginCardProps> = ({ data }) => {
|
|
|
116
116
|
});
|
|
117
117
|
|
|
118
118
|
const openSettings = useMemoizedFn(() => {
|
|
119
|
-
navigate(app.pluginSettingsManager.
|
|
119
|
+
navigate(app.pluginSettingsManager.getPluginSettingsRoutePath(name));
|
|
120
120
|
});
|
|
121
121
|
|
|
122
122
|
const cardClassName = useMemo(
|
|
@@ -180,7 +180,7 @@ export const PluginCard: FC<PluginCardProps> = ({ data }) => {
|
|
|
180
180
|
<ReadOutlined /> {t('Docs')}
|
|
181
181
|
</a>
|
|
182
182
|
)}
|
|
183
|
-
{enabled && app.pluginSettingsManager.
|
|
183
|
+
{enabled && app.pluginSettingsManager.hasPluginSettings(name) && (
|
|
184
184
|
<a
|
|
185
185
|
onClick={(e) => {
|
|
186
186
|
e.stopPropagation();
|
|
@@ -85,12 +85,6 @@ export function filterVisibleSettings(settings: readonly PluginSettingsPageType[
|
|
|
85
85
|
*/
|
|
86
86
|
export function sortTopLevelSettings(settings: PluginSettingsPageType[] = []) {
|
|
87
87
|
return [...settings].sort((a, b) => {
|
|
88
|
-
if (a.name === SYSTEM_SETTINGS_SETTING_NAME && b.name !== SYSTEM_SETTINGS_SETTING_NAME) {
|
|
89
|
-
return -1;
|
|
90
|
-
}
|
|
91
|
-
if (b.name === SYSTEM_SETTINGS_SETTING_NAME && a.name !== SYSTEM_SETTINGS_SETTING_NAME) {
|
|
92
|
-
return 1;
|
|
93
|
-
}
|
|
94
88
|
if ((a.sort || 0) !== (b.sort || 0)) {
|
|
95
89
|
return (a.sort || 0) - (b.sort || 0);
|
|
96
90
|
}
|