@nocobase/client-v2 2.2.0-beta.7 → 2.2.0-beta.9
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/BaseApplication.d.ts +2 -0
- package/es/RouteRepository.d.ts +8 -0
- package/es/RouterManager.d.ts +15 -0
- package/es/authRedirect.d.ts +1 -0
- package/es/entry-actions/EntryActionManager.d.ts +24 -0
- package/es/entry-actions/index.d.ts +9 -0
- package/es/flow/actions/afterSuccess.d.ts +8 -1
- package/es/flow/actions/index.d.ts +1 -1
- package/es/flow/admin-shell/BaseLayoutModel.d.ts +6 -0
- package/es/flow/admin-shell/BaseLayoutRouteCoordinator.d.ts +7 -0
- package/es/flow/admin-shell/admin-layout/AdminLayoutSlotModels.d.ts +1 -0
- package/es/flow/admin-shell/admin-layout/AppListRender.d.ts +2 -1
- package/es/flow/admin-shell/admin-layout/AppSwitcherActionPanelModel.d.ts +24 -0
- package/es/flow/admin-shell/admin-layout/index.d.ts +1 -0
- package/es/flow/admin-shell/admin-layout/useApplications.d.ts +7 -2
- package/es/flow/models/base/ActionModelCore.d.ts +2 -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/flow/routeTransientInputArgs.d.ts +14 -0
- package/es/index.d.ts +2 -0
- package/es/index.mjs +243 -141
- package/es/utils/markdownSanitize.d.ts +11 -0
- package/lib/index.js +232 -130
- package/package.json +7 -7
- package/src/BaseApplication.tsx +2 -0
- package/src/RouteRepository.ts +25 -0
- package/src/RouterManager.tsx +142 -1
- package/src/__tests__/RouteRepository.test.ts +23 -0
- package/src/__tests__/RouterManager.test.ts +125 -0
- package/src/__tests__/authRedirect.test.ts +17 -0
- package/src/authRedirect.ts +38 -0
- 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/entry-actions/EntryActionManager.ts +76 -0
- package/src/entry-actions/index.ts +10 -0
- package/src/flow/FlowPage.tsx +29 -2
- package/src/flow/__tests__/FlowPage.test.tsx +152 -25
- package/src/flow/__tests__/FlowRoute.test.tsx +547 -2
- 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 +62 -0
- package/src/flow/actions/__tests__/openView.defineProps.route.test.tsx +164 -0
- package/src/flow/actions/afterSuccess.tsx +142 -3
- package/src/flow/actions/dataScopeFilter.ts +10 -1
- package/src/flow/actions/dateTimeFormat.tsx +2 -2
- package/src/flow/actions/index.ts +1 -1
- package/src/flow/actions/openView.tsx +59 -5
- package/src/flow/admin-shell/BaseLayoutModel.tsx +149 -3
- package/src/flow/admin-shell/BaseLayoutRouteCoordinator.ts +187 -42
- package/src/flow/admin-shell/__tests__/AdminLayoutRouteCoordinator.test.ts +1020 -110
- package/src/flow/admin-shell/admin-layout/AdminLayoutComponent.tsx +42 -4
- package/src/flow/admin-shell/admin-layout/AdminLayoutEntryGuard.test.tsx +177 -1
- package/src/flow/admin-shell/admin-layout/AdminLayoutEntryGuard.tsx +20 -0
- package/src/flow/admin-shell/admin-layout/AdminLayoutSlotModels.tsx +5 -4
- package/src/flow/admin-shell/admin-layout/AppListRender.tsx +13 -2
- package/src/flow/admin-shell/admin-layout/AppSwitcherActionPanelModel.tsx +289 -0
- package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutModel.test.tsx +518 -2
- package/src/flow/admin-shell/admin-layout/__tests__/TopbarActionsBar.test.tsx +48 -0
- package/src/flow/admin-shell/admin-layout/index.ts +1 -0
- package/src/flow/admin-shell/admin-layout/useApplications.tsx +81 -12
- package/src/flow/common/Markdown/Display.tsx +14 -3
- package/src/flow/common/Markdown/Edit.tsx +19 -7
- package/src/flow/components/FlowRoute.tsx +128 -16
- package/src/flow/getViewDiffAndUpdateHidden.tsx +1 -0
- package/src/flow/internal/components/Markdown/util.ts +2 -1
- package/src/flow/models/base/ActionModel.tsx +10 -8
- package/src/flow/models/base/ActionModelCore.tsx +11 -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/TableColumnModel.tsx +6 -2
- 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/__tests__/TableColumnModel.test.tsx +51 -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/AssociationFieldModel/RecordSelectFieldModel.tsx +45 -13
- package/src/flow/models/fields/TextareaFieldModel.tsx +42 -19
- package/src/flow/models/fields/__tests__/TextareaFieldModel.test.tsx +32 -1
- package/src/flow/models/topbar/TopbarActionModel.tsx +78 -3
- package/src/flow/resolveViewParamsToViewList.tsx +11 -3
- package/src/flow/routeTransientInputArgs.ts +27 -0
- package/src/flow/utils/__tests__/dateTimeFormat.test.ts +42 -0
- package/src/index.ts +2 -0
- package/src/nocobase-buildin-plugin/index.tsx +7 -1
- package/src/settings-center/SystemSettingsPage.tsx +1 -1
- package/src/utils/markdownSanitize.ts +88 -0
|
@@ -0,0 +1,150 @@
|
|
|
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 React from 'react';
|
|
11
|
+
import { App, ConfigProvider } from 'antd';
|
|
12
|
+
import { render } from '@nocobase/test/client';
|
|
13
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
14
|
+
import { FlowEngine, FlowEngineProvider } from '@nocobase/flow-engine';
|
|
15
|
+
import { JSBlockModel } from '../JSBlock';
|
|
16
|
+
|
|
17
|
+
function createJSBlock(uid: string, showBlockCard?: boolean, decoratorProps?: Record<string, unknown>) {
|
|
18
|
+
const engine = new FlowEngine();
|
|
19
|
+
engine.registerModels({ JSBlockModel });
|
|
20
|
+
const model = engine.createModel<JSBlockModel>({
|
|
21
|
+
use: 'JSBlockModel',
|
|
22
|
+
uid,
|
|
23
|
+
stepParams:
|
|
24
|
+
typeof showBlockCard === 'boolean'
|
|
25
|
+
? {
|
|
26
|
+
jsSettings: {
|
|
27
|
+
showBlockCard: {
|
|
28
|
+
showBlockCard,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
}
|
|
32
|
+
: undefined,
|
|
33
|
+
});
|
|
34
|
+
model.setDecoratorProps({
|
|
35
|
+
className: 'custom-js-block-shell',
|
|
36
|
+
style: {
|
|
37
|
+
minHeight: 120,
|
|
38
|
+
},
|
|
39
|
+
...(decoratorProps || {}),
|
|
40
|
+
});
|
|
41
|
+
return { engine, model };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function renderBlock(engine: FlowEngine, model: JSBlockModel) {
|
|
45
|
+
return render(
|
|
46
|
+
<FlowEngineProvider engine={engine}>
|
|
47
|
+
<ConfigProvider>
|
|
48
|
+
<App>{model.render()}</App>
|
|
49
|
+
</ConfigProvider>
|
|
50
|
+
</FlowEngineProvider>,
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
describe('JSBlockModel', () => {
|
|
55
|
+
it('renders with the outer block card by default', () => {
|
|
56
|
+
const { engine, model } = createJSBlock('js-block-with-card');
|
|
57
|
+
const { container } = renderBlock(engine, model);
|
|
58
|
+
const host = container.querySelector('#model-js-block-with-card');
|
|
59
|
+
|
|
60
|
+
expect(host).toBeTruthy();
|
|
61
|
+
expect(host?.classList.contains('ant-card')).toBe(true);
|
|
62
|
+
expect(host?.classList.contains('code-block')).toBe(true);
|
|
63
|
+
expect(host?.classList.contains('custom-js-block-shell')).toBe(true);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('renders a plain host without the outer card when showBlockCard is false', () => {
|
|
67
|
+
const { engine, model } = createJSBlock('js-block-without-card', false, {
|
|
68
|
+
showCard: true,
|
|
69
|
+
});
|
|
70
|
+
const { container } = renderBlock(engine, model);
|
|
71
|
+
const host = container.querySelector('#model-js-block-without-card') as HTMLElement | null;
|
|
72
|
+
|
|
73
|
+
expect(container.querySelector('.ant-card')).toBeNull();
|
|
74
|
+
expect(host).toBeInstanceOf(HTMLDivElement);
|
|
75
|
+
expect(host?.classList.contains('code-block')).toBe(true);
|
|
76
|
+
expect(host?.classList.contains('custom-js-block-shell')).toBe(true);
|
|
77
|
+
expect(host?.style.minHeight).toBe('120px');
|
|
78
|
+
expect(model.context.ref.current).toBe(host?.firstElementChild);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('keeps cardless specified-height content scrollable inside the plain host', () => {
|
|
82
|
+
const { engine, model } = createJSBlock('js-block-without-card-height', false, {
|
|
83
|
+
heightMode: 'specifyValue',
|
|
84
|
+
height: 80,
|
|
85
|
+
style: undefined,
|
|
86
|
+
});
|
|
87
|
+
const { container } = renderBlock(engine, model);
|
|
88
|
+
const host = container.querySelector('#model-js-block-without-card-height') as HTMLElement | null;
|
|
89
|
+
const overflowContent = document.createElement('div');
|
|
90
|
+
overflowContent.style.height = '200px';
|
|
91
|
+
model.context.ref.current?.appendChild(overflowContent);
|
|
92
|
+
|
|
93
|
+
expect(host?.style.height).toBe('80px');
|
|
94
|
+
expect(host?.style.minHeight).toBe('0');
|
|
95
|
+
expect(host?.style.overflow).toBe('auto');
|
|
96
|
+
expect(model.context.ref.current?.firstElementChild).toBe(overflowContent);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('calculates cardless full-height on the plain host', () => {
|
|
100
|
+
const originalInnerHeight = window.innerHeight;
|
|
101
|
+
Object.defineProperty(window, 'innerHeight', {
|
|
102
|
+
configurable: true,
|
|
103
|
+
value: 500,
|
|
104
|
+
});
|
|
105
|
+
const rectSpy = vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockImplementation(function () {
|
|
106
|
+
if ((this as HTMLElement).id === 'model-js-block-without-card-full-height') {
|
|
107
|
+
return {
|
|
108
|
+
x: 0,
|
|
109
|
+
y: 150,
|
|
110
|
+
top: 150,
|
|
111
|
+
left: 0,
|
|
112
|
+
bottom: 150,
|
|
113
|
+
right: 0,
|
|
114
|
+
width: 0,
|
|
115
|
+
height: 0,
|
|
116
|
+
toJSON: () => ({}),
|
|
117
|
+
} as DOMRect;
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
x: 0,
|
|
121
|
+
y: 0,
|
|
122
|
+
top: 0,
|
|
123
|
+
left: 0,
|
|
124
|
+
bottom: 0,
|
|
125
|
+
right: 0,
|
|
126
|
+
width: 0,
|
|
127
|
+
height: 0,
|
|
128
|
+
toJSON: () => ({}),
|
|
129
|
+
} as DOMRect;
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
try {
|
|
133
|
+
const { engine, model } = createJSBlock('js-block-without-card-full-height', false, {
|
|
134
|
+
heightMode: 'fullHeight',
|
|
135
|
+
style: undefined,
|
|
136
|
+
});
|
|
137
|
+
const { container } = renderBlock(engine, model);
|
|
138
|
+
const host = container.querySelector('#model-js-block-without-card-full-height') as HTMLElement | null;
|
|
139
|
+
|
|
140
|
+
expect(parseInt(host?.style.height || '0', 10)).toBeGreaterThan(0);
|
|
141
|
+
expect(host?.style.overflow).toBe('auto');
|
|
142
|
+
} finally {
|
|
143
|
+
rectSpy.mockRestore();
|
|
144
|
+
Object.defineProperty(window, 'innerHeight', {
|
|
145
|
+
configurable: true,
|
|
146
|
+
value: originalInnerHeight,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
});
|
|
@@ -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
|
|
|
@@ -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
|
|
@@ -373,14 +373,18 @@ TableColumnModel.registerFlow({
|
|
|
373
373
|
currentProps: ctx.model.props,
|
|
374
374
|
})
|
|
375
375
|
: undefined;
|
|
376
|
+
const collectionFieldComponentProps = collectionField.getComponentProps();
|
|
376
377
|
const componentProps =
|
|
377
378
|
collectionField.isAssociationField() && titleField
|
|
378
379
|
? {
|
|
379
|
-
...
|
|
380
|
+
...collectionFieldComponentProps,
|
|
380
381
|
...targetCollectionField?.getComponentProps?.(),
|
|
381
382
|
...savedDateTimeDisplayProps,
|
|
382
383
|
}
|
|
383
|
-
:
|
|
384
|
+
: {
|
|
385
|
+
...collectionFieldComponentProps,
|
|
386
|
+
...savedDateTimeDisplayProps,
|
|
387
|
+
};
|
|
384
388
|
ctx.model.setProps('title', collectionField.title);
|
|
385
389
|
ctx.model.setProps('dataIndex', collectionField.name);
|
|
386
390
|
// for quick edit
|
|
@@ -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
|
+
});
|
|
@@ -327,6 +327,57 @@ describe('TableColumnModel sorter settings', () => {
|
|
|
327
327
|
);
|
|
328
328
|
});
|
|
329
329
|
|
|
330
|
+
it('keeps saved ordinary datetime format when table column initializes again', async () => {
|
|
331
|
+
const engine = new FlowEngine();
|
|
332
|
+
const model = new TableColumnModel({
|
|
333
|
+
uid: 'table-column-saved-datetime-format',
|
|
334
|
+
flowEngine: engine,
|
|
335
|
+
} as any);
|
|
336
|
+
const initStep = model.getFlow('tableColumnSettings')?.steps?.init as any;
|
|
337
|
+
const setProps = vi.fn();
|
|
338
|
+
|
|
339
|
+
await initStep.handler({
|
|
340
|
+
model: {
|
|
341
|
+
context: {
|
|
342
|
+
collectionField: {
|
|
343
|
+
title: 'Datetime',
|
|
344
|
+
name: 'datetime',
|
|
345
|
+
isAssociationField: () => false,
|
|
346
|
+
getComponentProps: () => ({
|
|
347
|
+
dateFormat: 'YYYY-MM-DD',
|
|
348
|
+
showTime: false,
|
|
349
|
+
}),
|
|
350
|
+
},
|
|
351
|
+
},
|
|
352
|
+
props: {},
|
|
353
|
+
subModels: {
|
|
354
|
+
field: {
|
|
355
|
+
getStepParams: (flowKey, stepKey) =>
|
|
356
|
+
flowKey === 'datetimeSettings' && stepKey === 'dateFormat'
|
|
357
|
+
? {
|
|
358
|
+
picker: 'date',
|
|
359
|
+
dateFormat: 'YYYY-MM-DD',
|
|
360
|
+
showTime: true,
|
|
361
|
+
timeFormat: 'HH:mm:ss',
|
|
362
|
+
}
|
|
363
|
+
: undefined,
|
|
364
|
+
},
|
|
365
|
+
},
|
|
366
|
+
applySubModelsBeforeRenderFlows: vi.fn(),
|
|
367
|
+
setProps,
|
|
368
|
+
},
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
expect(setProps).toHaveBeenCalledWith(
|
|
372
|
+
expect.objectContaining({
|
|
373
|
+
dateFormat: 'YYYY-MM-DD',
|
|
374
|
+
format: 'YYYY-MM-DD HH:mm:ss',
|
|
375
|
+
showTime: true,
|
|
376
|
+
timeFormat: 'HH:mm:ss',
|
|
377
|
+
}),
|
|
378
|
+
);
|
|
379
|
+
});
|
|
380
|
+
|
|
330
381
|
it('does not update field component setting when title field refresh fails', async () => {
|
|
331
382
|
const engine = new FlowEngine();
|
|
332
383
|
const model = new TableColumnModel({ uid: 'table-column-title-field-component-failed', flowEngine: engine } as any);
|