@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
|
@@ -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
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
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 '@nocobase/client';
|
|
12
|
+
import React from 'react';
|
|
13
|
+
import { describe, expect, it } from 'vitest';
|
|
14
|
+
import { TableBlockModel } from '../TableBlockModel';
|
|
15
|
+
|
|
16
|
+
function createTableModel(options: { isMobileLayout?: boolean; flowSettingsEnabled?: boolean } = {}) {
|
|
17
|
+
const engine = new FlowEngine();
|
|
18
|
+
engine.registerModels({ TableBlockModel });
|
|
19
|
+
engine.context.defineProperty('isMobileLayout', { value: !!options.isMobileLayout });
|
|
20
|
+
engine.context.defineProperty('flowSettingsEnabled', { value: !!options.flowSettingsEnabled });
|
|
21
|
+
|
|
22
|
+
const ds = engine.dataSourceManager.getDataSource('main');
|
|
23
|
+
ds.addCollection({
|
|
24
|
+
name: 'posts',
|
|
25
|
+
filterTargetKey: 'id',
|
|
26
|
+
fields: [
|
|
27
|
+
{ name: 'id', type: 'integer', interface: 'number' },
|
|
28
|
+
{ name: 'title', type: 'string', interface: 'input' },
|
|
29
|
+
],
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
return engine.createModel<TableBlockModel>({
|
|
33
|
+
uid: `posts-table-${options.isMobileLayout ? 'mobile' : 'desktop'}`,
|
|
34
|
+
use: 'TableBlockModel',
|
|
35
|
+
stepParams: {
|
|
36
|
+
resourceSettings: {
|
|
37
|
+
init: {
|
|
38
|
+
dataSourceKey: 'main',
|
|
39
|
+
collectionName: 'posts',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function getSettingsButton(element: React.ReactElement) {
|
|
47
|
+
return element.props.children as React.ReactElement;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
describe('TableBlockModel mobile settings buttons', () => {
|
|
51
|
+
it('renders table actions and fields settings as icon-only buttons in mobile layouts', () => {
|
|
52
|
+
const model = createTableModel({ isMobileLayout: true, flowSettingsEnabled: true });
|
|
53
|
+
const actionButton = getSettingsButton(model.renderConfigureActions() as React.ReactElement);
|
|
54
|
+
const addColumn = model.getColumns().find((column) => column.key === 'addColumn');
|
|
55
|
+
const fieldsButton = getSettingsButton(
|
|
56
|
+
(addColumn?.title as React.ReactElement).type({ model }) as React.ReactElement,
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
expect(actionButton.props.children).toBeNull();
|
|
60
|
+
expect(actionButton.props['aria-label']).toBe('Actions');
|
|
61
|
+
expect(fieldsButton.props.children).toBeNull();
|
|
62
|
+
expect(fieldsButton.props['aria-label']).toBe('Fields');
|
|
63
|
+
expect(addColumn?.width).toBeUndefined();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('keeps table actions and fields settings labels outside mobile layouts', () => {
|
|
67
|
+
const model = createTableModel({ flowSettingsEnabled: true });
|
|
68
|
+
const actionButton = getSettingsButton(model.renderConfigureActions() as React.ReactElement);
|
|
69
|
+
const addColumn = model.getColumns().find((column) => column.key === 'addColumn');
|
|
70
|
+
const fieldsButton = getSettingsButton(
|
|
71
|
+
(addColumn?.title as React.ReactElement).type({ model }) as React.ReactElement,
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
expect(actionButton.props.children).toBe('Actions');
|
|
75
|
+
expect(fieldsButton.props.children).toBe('Fields');
|
|
76
|
+
expect(addColumn?.width).toBe(100);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -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,
|
|
@@ -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, { useEffect, useMemo, useRef } from 'react';
|
|
12
12
|
import { Input } from 'antd';
|
|
13
13
|
import { FieldModel } from '../base/FieldModel';
|
|
@@ -398,16 +398,7 @@ JSEditableFieldModel.registerFlow({
|
|
|
398
398
|
get: () => isReadOnlyMode(ctx.model),
|
|
399
399
|
cache: false,
|
|
400
400
|
});
|
|
401
|
-
|
|
402
|
-
await ctx.runjs(
|
|
403
|
-
code,
|
|
404
|
-
{
|
|
405
|
-
window: createSafeWindow({ navigator }),
|
|
406
|
-
document: createSafeDocument(),
|
|
407
|
-
navigator,
|
|
408
|
-
},
|
|
409
|
-
{ version },
|
|
410
|
-
);
|
|
401
|
+
await ctx.runjs(code, undefined, { version });
|
|
411
402
|
});
|
|
412
403
|
},
|
|
413
404
|
},
|
|
@@ -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, { useEffect } from 'react';
|
|
12
12
|
import { FieldModel } from '../base/FieldModel';
|
|
13
13
|
import { resolveRunJsParams } from '../utils/resolveRunJsParams';
|
|
@@ -211,12 +211,7 @@ JSFieldModel.registerFlow({
|
|
|
211
211
|
get: () => ctx.model.props?.value,
|
|
212
212
|
cache: false,
|
|
213
213
|
});
|
|
214
|
-
|
|
215
|
-
await ctx.runjs(
|
|
216
|
-
code,
|
|
217
|
-
{ window: createSafeWindow({ navigator }), document: createSafeDocument(), navigator },
|
|
218
|
-
{ version },
|
|
219
|
-
);
|
|
214
|
+
await ctx.runjs(code, undefined, { version });
|
|
220
215
|
});
|
|
221
216
|
},
|
|
222
217
|
},
|
|
@@ -7,14 +7,7 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import {
|
|
11
|
-
ElementProxy,
|
|
12
|
-
FormItem,
|
|
13
|
-
createSafeDocument,
|
|
14
|
-
createSafeWindow,
|
|
15
|
-
createSafeNavigator,
|
|
16
|
-
tExpr,
|
|
17
|
-
} from '@nocobase/flow-engine';
|
|
10
|
+
import { ElementProxy, FormItem, tExpr } from '@nocobase/flow-engine';
|
|
18
11
|
import React from 'react';
|
|
19
12
|
import { CodeEditor } from '../../components/code-editor';
|
|
20
13
|
import { CommonItemModel } from '../base/CommonItemModel';
|
|
@@ -150,12 +143,7 @@ ctx.render(<JsItem />);
|
|
|
150
143
|
ctx.defineProperty('element', {
|
|
151
144
|
get: () => new ElementProxy(element),
|
|
152
145
|
});
|
|
153
|
-
|
|
154
|
-
await ctx.runjs(
|
|
155
|
-
code,
|
|
156
|
-
{ window: createSafeWindow({ navigator }), document: createSafeDocument(), navigator },
|
|
157
|
-
{ version },
|
|
158
|
-
);
|
|
146
|
+
await ctx.runjs(code, undefined, { version });
|
|
159
147
|
});
|
|
160
148
|
},
|
|
161
149
|
},
|
|
@@ -14,8 +14,9 @@ import { Button, Dropdown, theme, Tooltip, type ButtonProps, type MenuProps } fr
|
|
|
14
14
|
import React, { useEffect, useMemo, useState } from 'react';
|
|
15
15
|
import { useHotkeys } from 'react-hotkeys-hook';
|
|
16
16
|
import { useTranslation } from 'react-i18next';
|
|
17
|
-
import { Link } from 'react-router-dom';
|
|
17
|
+
import { Link, useLocation } from 'react-router-dom';
|
|
18
18
|
import { useACLRoleContext } from '../../../acl';
|
|
19
|
+
import type { BaseApplication } from '../../../BaseApplication';
|
|
19
20
|
import type { PluginSettingsPageType } from '../../../PluginSettingsManager';
|
|
20
21
|
import { useApp } from '../../../hooks/useApp';
|
|
21
22
|
import {
|
|
@@ -64,6 +65,89 @@ const topbarActionTriggerClassName = css`
|
|
|
64
65
|
height: 100%;
|
|
65
66
|
`;
|
|
66
67
|
|
|
68
|
+
type TopbarSettingsAppLike = Pick<BaseApplication<any>, 'router' | 'getPublicPath'>;
|
|
69
|
+
|
|
70
|
+
const normalizeTopbarPath = (pathname?: string) => {
|
|
71
|
+
const trimmed = pathname?.trim();
|
|
72
|
+
if (!trimmed || trimmed === '/') {
|
|
73
|
+
return '/';
|
|
74
|
+
}
|
|
75
|
+
return `/${trimmed.replace(/^\/+/, '')}`;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const normalizeTopbarBasePath = (pathname?: string) => {
|
|
79
|
+
const normalized = normalizeTopbarPath(pathname).replace(/\/+$/, '');
|
|
80
|
+
return normalized === '' || normalized === '/' ? '' : normalized;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const getTopbarRouterBasePath = (app: TopbarSettingsAppLike | undefined) => {
|
|
84
|
+
return app?.router?.getBasename?.() || app?.router?.basename || app?.getPublicPath?.() || '';
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const stripTopbarRouterBasePath = (pathname: string, basename?: string) => {
|
|
88
|
+
const normalizedPath = normalizeTopbarPath(pathname);
|
|
89
|
+
const normalizedBase = normalizeTopbarBasePath(basename);
|
|
90
|
+
|
|
91
|
+
if (!normalizedBase) {
|
|
92
|
+
return normalizedPath;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (normalizedPath === normalizedBase) {
|
|
96
|
+
return '/';
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (normalizedPath.startsWith(`${normalizedBase}/`)) {
|
|
100
|
+
return normalizeTopbarPath(normalizedPath.slice(normalizedBase.length));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return normalizedPath;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const isAdminRuntimePath = (pathname: string) => {
|
|
107
|
+
return pathname === '/admin' || pathname.startsWith('/admin/');
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const buildTopbarDocumentHref = (targetPath: string, basename?: string) => {
|
|
111
|
+
const normalizedTarget = normalizeTopbarPath(targetPath);
|
|
112
|
+
const normalizedBase = normalizeTopbarBasePath(basename);
|
|
113
|
+
|
|
114
|
+
if (!normalizedBase || normalizedTarget === normalizedBase || normalizedTarget.startsWith(`${normalizedBase}/`)) {
|
|
115
|
+
return normalizedTarget;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return `${normalizedBase}${normalizedTarget}`;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
function TopbarExternalSettingsLabel(props: { title: React.ReactNode; link: string }) {
|
|
122
|
+
return (
|
|
123
|
+
<div
|
|
124
|
+
onClick={() => {
|
|
125
|
+
window.open(props.link, '_blank', 'noopener,noreferrer');
|
|
126
|
+
}}
|
|
127
|
+
>
|
|
128
|
+
{props.title}
|
|
129
|
+
</div>
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function TopbarInternalSettingsLabel(props: { title: React.ReactNode; path?: string }) {
|
|
134
|
+
const app = useApp();
|
|
135
|
+
const location = useLocation();
|
|
136
|
+
const targetPath = props.path || '/admin/settings';
|
|
137
|
+
const basename = getTopbarRouterBasePath(app);
|
|
138
|
+
const currentPath = stripTopbarRouterBasePath(location.pathname, basename);
|
|
139
|
+
|
|
140
|
+
if (isAdminRuntimePath(currentPath)) {
|
|
141
|
+
return <Link to={targetPath}>{props.title}</Link>;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return (
|
|
145
|
+
<a href={buildTopbarDocumentHref(targetPath, basename)} target="_blank" rel="noopener noreferrer">
|
|
146
|
+
{props.title}
|
|
147
|
+
</a>
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
67
151
|
/**
|
|
68
152
|
* 将 settings 顶部菜单转换成右上角 dropdown items。
|
|
69
153
|
*
|
|
@@ -112,15 +196,9 @@ export function getTopbarPluginSettingsItems(options: {
|
|
|
112
196
|
title: targetTitle,
|
|
113
197
|
icon: item.icon,
|
|
114
198
|
label: targetLink ? (
|
|
115
|
-
<
|
|
116
|
-
onClick={() => {
|
|
117
|
-
window.open(targetLink, '_blank', 'noopener,noreferrer');
|
|
118
|
-
}}
|
|
119
|
-
>
|
|
120
|
-
{targetTitle}
|
|
121
|
-
</div>
|
|
199
|
+
<TopbarExternalSettingsLabel title={targetTitle} link={targetLink} />
|
|
122
200
|
) : (
|
|
123
|
-
<
|
|
201
|
+
<TopbarInternalSettingsLabel title={targetTitle} path={targetPath} />
|
|
124
202
|
),
|
|
125
203
|
};
|
|
126
204
|
});
|
|
@@ -131,7 +209,12 @@ export function getTopbarPluginSettingsItems(options: {
|
|
|
131
209
|
items.push({
|
|
132
210
|
key: pluginManagerSetting.key,
|
|
133
211
|
icon: pluginManagerSetting.icon || <ApiOutlined />,
|
|
134
|
-
label:
|
|
212
|
+
label: (
|
|
213
|
+
<TopbarInternalSettingsLabel
|
|
214
|
+
title={pluginManagerSetting.title || t('Plugin manager')}
|
|
215
|
+
path={pluginManagerSetting.path}
|
|
216
|
+
/>
|
|
217
|
+
),
|
|
135
218
|
});
|
|
136
219
|
}
|
|
137
220
|
|
|
@@ -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
|
}
|