@nocobase/client-v2 2.2.0-alpha.2 → 2.2.0-alpha.4
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/RouteRepository.d.ts +8 -0
- package/es/authRedirect.d.ts +1 -0
- package/es/components/form/TypedVariableInput.d.ts +9 -1
- package/es/components/form/filter/CollectionFilter.d.ts +2 -0
- package/es/components/form/filter/CollectionFilterPanel.d.ts +2 -0
- package/es/components/form/filter/useFilterActionProps.d.ts +2 -0
- 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/index.d.ts +2 -0
- package/es/index.mjs +148 -116
- package/es/utils/getRouteRuntimeVersion.d.ts +23 -0
- package/es/utils/index.d.ts +1 -0
- package/lib/index.js +149 -117
- package/package.json +7 -7
- package/src/RouteRepository.ts +25 -0
- package/src/__tests__/RouteRepository.test.ts +23 -0
- package/src/__tests__/authRedirect.test.ts +17 -0
- package/src/__tests__/getRouteRuntimeVersion.test.ts +68 -0
- package/src/authRedirect.ts +38 -0
- package/src/components/form/JsonTextArea.tsx +4 -0
- package/src/components/form/TypedVariableInput.tsx +58 -34
- package/src/components/form/__tests__/TypedVariableInput.test.tsx +54 -0
- package/src/components/form/filter/CollectionFilter.tsx +4 -0
- package/src/components/form/filter/CollectionFilterPanel.tsx +4 -0
- package/src/components/form/filter/__tests__/useFilterActionProps.test.tsx +95 -0
- package/src/components/form/filter/useFilterActionProps.ts +37 -6
- package/src/flow/actions/dateTimeFormat.tsx +2 -2
- package/src/flow/admin-shell/BaseLayoutModel.tsx +13 -0
- 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/__tests__/AdminLayoutModel.test.tsx +77 -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/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/TableColumnModel.tsx +6 -2
- package/src/flow/models/blocks/table/__tests__/TableColumnModel.test.tsx +51 -0
- package/src/flow/models/fields/AssociationFieldModel/RecordSelectFieldModel.tsx +45 -13
- package/src/flow/utils/__tests__/dateTimeFormat.test.ts +42 -0
- package/src/index.ts +2 -0
- package/src/utils/getRouteRuntimeVersion.ts +185 -0
- package/src/utils/index.tsx +1 -0
|
@@ -38,6 +38,11 @@ type FormBlockModel = FlowModel & {
|
|
|
38
38
|
getAclActionName?: () => string;
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
+
export type FormValuePatch = {
|
|
42
|
+
path: NamePath;
|
|
43
|
+
value: unknown;
|
|
44
|
+
};
|
|
45
|
+
|
|
41
46
|
export class FormValueRuntime {
|
|
42
47
|
private readonly model: FormBlockModel;
|
|
43
48
|
private readonly getForm: () => FormInstance;
|
|
@@ -142,6 +147,49 @@ export class FormValueRuntime {
|
|
|
142
147
|
return this.getForm().getFieldsValue(true);
|
|
143
148
|
}
|
|
144
149
|
|
|
150
|
+
getUserEditedValuePatches(): FormValuePatch[] {
|
|
151
|
+
const snapshot = this.getFormValuesSnapshot();
|
|
152
|
+
if (!snapshot || typeof snapshot !== 'object') {
|
|
153
|
+
return [];
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const patches: FormValuePatch[] = [];
|
|
157
|
+
const pathKeys = Array.from(this.userEditedSet).sort(
|
|
158
|
+
(a, b) => pathKeyToNamePath(a).length - pathKeyToNamePath(b).length,
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
for (const pathKey of pathKeys) {
|
|
162
|
+
if (!this.isCurrentUserEditedPath(pathKey)) {
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const namePath = pathKeyToNamePath(pathKey);
|
|
167
|
+
if (!namePath.length || !_.has(snapshot, namePath as any)) {
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const value = _.get(snapshot, namePath as any);
|
|
172
|
+
if (typeof value === 'undefined') {
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
patches.push({
|
|
177
|
+
path: namePath,
|
|
178
|
+
value: this.omitNonUserDescendantValues(pathKey, this.toMirrorSnapshot(value)),
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return patches;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
getUserEditedValuesSnapshot(): Record<string, unknown> {
|
|
186
|
+
const values: Record<string, unknown> = {};
|
|
187
|
+
for (const patch of this.getUserEditedValuePatches()) {
|
|
188
|
+
_.set(values, patch.path as any, patch.value);
|
|
189
|
+
}
|
|
190
|
+
return values;
|
|
191
|
+
}
|
|
192
|
+
|
|
145
193
|
private toMirrorSnapshot(value: any) {
|
|
146
194
|
const raw = isObservable(value) ? toJS(value) : value;
|
|
147
195
|
return _.cloneDeepWith(raw, (item) => {
|
|
@@ -1453,6 +1501,49 @@ export class FormValueRuntime {
|
|
|
1453
1501
|
return null;
|
|
1454
1502
|
}
|
|
1455
1503
|
|
|
1504
|
+
private findLatestWriteMeta(pathKey: string): FormValueWriteMeta | undefined {
|
|
1505
|
+
let latest: FormValueWriteMeta | undefined;
|
|
1506
|
+
const namePath = pathKeyToNamePath(pathKey);
|
|
1507
|
+
const prefix: NamePath = [];
|
|
1508
|
+
|
|
1509
|
+
for (let i = 0; i < namePath.length; i++) {
|
|
1510
|
+
prefix.push(namePath[i]);
|
|
1511
|
+
const meta = this.lastWriteMetaByPathKey.get(namePathToPathKey(prefix as any));
|
|
1512
|
+
if (!meta) {
|
|
1513
|
+
continue;
|
|
1514
|
+
}
|
|
1515
|
+
if (!latest || meta.writeSeq >= latest.writeSeq) {
|
|
1516
|
+
latest = meta;
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
|
|
1520
|
+
return latest;
|
|
1521
|
+
}
|
|
1522
|
+
|
|
1523
|
+
private isCurrentUserEditedPath(pathKey: string) {
|
|
1524
|
+
const lastWrite = this.findLatestWriteMeta(pathKey);
|
|
1525
|
+
return !lastWrite || lastWrite.source === 'user';
|
|
1526
|
+
}
|
|
1527
|
+
|
|
1528
|
+
private omitNonUserDescendantValues(pathKey: string, value: unknown) {
|
|
1529
|
+
if (!value || typeof value !== 'object') {
|
|
1530
|
+
return value;
|
|
1531
|
+
}
|
|
1532
|
+
|
|
1533
|
+
const namePath = pathKeyToNamePath(pathKey);
|
|
1534
|
+
for (const childKey of this.lastWriteMetaByPathKey.keys()) {
|
|
1535
|
+
if (!this.isDescendantPathKey(childKey, pathKey)) {
|
|
1536
|
+
continue;
|
|
1537
|
+
}
|
|
1538
|
+
if (this.isCurrentUserEditedPath(childKey)) {
|
|
1539
|
+
continue;
|
|
1540
|
+
}
|
|
1541
|
+
_.unset(value as Record<string, unknown>, pathKeyToNamePath(childKey).slice(namePath.length) as any);
|
|
1542
|
+
}
|
|
1543
|
+
|
|
1544
|
+
return value;
|
|
1545
|
+
}
|
|
1546
|
+
|
|
1456
1547
|
private isDescendantPathKey(candidateKey: string, parentKey: string) {
|
|
1457
1548
|
if (!candidateKey || !parentKey || candidateKey === parentKey) return false;
|
|
1458
1549
|
const candidatePath = pathKeyToNamePath(candidateKey);
|
|
@@ -16,24 +16,238 @@ import { CodeEditor } from '../../../components/code-editor';
|
|
|
16
16
|
|
|
17
17
|
const NAMESPACE = 'client';
|
|
18
18
|
|
|
19
|
+
const getRootElement = (element: HTMLElement | null) => {
|
|
20
|
+
if (!element) return document.documentElement;
|
|
21
|
+
return (
|
|
22
|
+
(element.closest('.nb-block-grid') as HTMLElement | null) ||
|
|
23
|
+
(element.closest('.nb-page-wrapper') as HTMLElement | null) ||
|
|
24
|
+
(element.closest('.nb-page') as HTMLElement | null) ||
|
|
25
|
+
document.documentElement
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const getOuterHeight = (element?: HTMLElement | null) => {
|
|
30
|
+
if (!element) return 0;
|
|
31
|
+
const rect = element.getBoundingClientRect();
|
|
32
|
+
const style = window.getComputedStyle(element);
|
|
33
|
+
const marginTop = parseFloat(style.marginTop) || 0;
|
|
34
|
+
const marginBottom = parseFloat(style.marginBottom) || 0;
|
|
35
|
+
return rect.height + marginTop + marginBottom;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const getPadding = (element: HTMLElement | null) => {
|
|
39
|
+
if (!element || element === document.documentElement) {
|
|
40
|
+
return { top: 0, bottom: 0 };
|
|
41
|
+
}
|
|
42
|
+
const style = window.getComputedStyle(element);
|
|
43
|
+
return {
|
|
44
|
+
top: parseFloat(style.paddingTop) || 0,
|
|
45
|
+
bottom: parseFloat(style.paddingBottom) || 0,
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const getPageHeader = (root: HTMLElement) => {
|
|
50
|
+
const page = root.closest('.nb-page') as HTMLElement | null;
|
|
51
|
+
if (!page) return null;
|
|
52
|
+
return (
|
|
53
|
+
(page.querySelector('.ant-page-header') as HTMLElement | null) ||
|
|
54
|
+
(page.querySelector('.pageHeaderCss') as HTMLElement | null)
|
|
55
|
+
);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const getAddBlockContainer = (root: HTMLElement) => {
|
|
59
|
+
const button = root.querySelector('[data-flow-add-block]') as HTMLElement | null;
|
|
60
|
+
if (!button) return null;
|
|
61
|
+
return (button.parentElement as HTMLElement | null) || button;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
function getValidPageTop(a: number, b: number) {
|
|
65
|
+
const aValid = a > 0;
|
|
66
|
+
const bValid = b > 0;
|
|
67
|
+
|
|
68
|
+
if (aValid) return a;
|
|
69
|
+
if (bValid) return b;
|
|
70
|
+
return 0;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const usePlainHostHeight = ({
|
|
74
|
+
height,
|
|
75
|
+
heightMode,
|
|
76
|
+
hostRef,
|
|
77
|
+
marginBlock,
|
|
78
|
+
}: {
|
|
79
|
+
height?: number;
|
|
80
|
+
heightMode?: string;
|
|
81
|
+
hostRef: React.RefObject<HTMLDivElement>;
|
|
82
|
+
marginBlock: number;
|
|
83
|
+
}) => {
|
|
84
|
+
const [fullHeight, setFullHeight] = React.useState<number>();
|
|
85
|
+
const updateFullHeight = React.useCallback(() => {
|
|
86
|
+
if (heightMode !== 'fullHeight' || typeof window === 'undefined') {
|
|
87
|
+
setFullHeight((prev) => (prev === undefined ? prev : undefined));
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const hostEl = hostRef.current;
|
|
91
|
+
if (!hostEl) return;
|
|
92
|
+
const root = getRootElement(hostEl);
|
|
93
|
+
const hostRect = hostEl.getBoundingClientRect();
|
|
94
|
+
const rootRect = root === document.documentElement ? { top: 0 } : root.getBoundingClientRect();
|
|
95
|
+
const padding = getPadding(root);
|
|
96
|
+
const addBlockContainer = getAddBlockContainer(root);
|
|
97
|
+
const pageTop = rootRect.top + padding.top;
|
|
98
|
+
const topOffset = Math.max(0, hostRect.top - pageTop);
|
|
99
|
+
let bottomOffset = padding.bottom + marginBlock;
|
|
100
|
+
if (addBlockContainer) {
|
|
101
|
+
const gapBetween = marginBlock;
|
|
102
|
+
bottomOffset = gapBetween + getOuterHeight(addBlockContainer) + padding.bottom;
|
|
103
|
+
}
|
|
104
|
+
const nextHeight = Math.max(
|
|
105
|
+
0,
|
|
106
|
+
Math.floor(window.innerHeight - getValidPageTop(pageTop, 110) - topOffset - bottomOffset - 1),
|
|
107
|
+
);
|
|
108
|
+
setFullHeight((prev) => (prev === nextHeight ? prev : nextHeight));
|
|
109
|
+
}, [heightMode, hostRef, marginBlock]);
|
|
110
|
+
|
|
111
|
+
React.useLayoutEffect(() => {
|
|
112
|
+
updateFullHeight();
|
|
113
|
+
}, [updateFullHeight]);
|
|
114
|
+
|
|
115
|
+
React.useEffect(() => {
|
|
116
|
+
if (heightMode !== 'fullHeight' || typeof window === 'undefined') return;
|
|
117
|
+
const hostEl = hostRef.current;
|
|
118
|
+
if (!hostEl || typeof ResizeObserver === 'undefined') return;
|
|
119
|
+
const root = getRootElement(hostEl);
|
|
120
|
+
const pageHeader = getPageHeader(root);
|
|
121
|
+
const addBlockContainer = getAddBlockContainer(root);
|
|
122
|
+
const observer = new ResizeObserver(() => updateFullHeight());
|
|
123
|
+
observer.observe(hostEl);
|
|
124
|
+
if (root instanceof HTMLElement) {
|
|
125
|
+
observer.observe(root);
|
|
126
|
+
}
|
|
127
|
+
if (pageHeader) observer.observe(pageHeader);
|
|
128
|
+
if (addBlockContainer) observer.observe(addBlockContainer);
|
|
129
|
+
window.addEventListener('resize', updateFullHeight);
|
|
130
|
+
return () => {
|
|
131
|
+
observer.disconnect();
|
|
132
|
+
window.removeEventListener('resize', updateFullHeight);
|
|
133
|
+
};
|
|
134
|
+
}, [heightMode, hostRef, updateFullHeight]);
|
|
135
|
+
|
|
136
|
+
if (heightMode === 'specifyValue') {
|
|
137
|
+
return height;
|
|
138
|
+
}
|
|
139
|
+
if (heightMode === 'fullHeight') {
|
|
140
|
+
return fullHeight;
|
|
141
|
+
}
|
|
142
|
+
return null;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
const JSBlockPlainHost = ({
|
|
146
|
+
uid,
|
|
147
|
+
className,
|
|
148
|
+
heightMode,
|
|
149
|
+
height,
|
|
150
|
+
style,
|
|
151
|
+
beforeContent,
|
|
152
|
+
afterContent,
|
|
153
|
+
contentRef,
|
|
154
|
+
marginBlock,
|
|
155
|
+
...rest
|
|
156
|
+
}: React.HTMLAttributes<HTMLDivElement> & {
|
|
157
|
+
uid: string;
|
|
158
|
+
heightMode?: string;
|
|
159
|
+
height?: number;
|
|
160
|
+
beforeContent?: React.ReactNode;
|
|
161
|
+
afterContent?: React.ReactNode;
|
|
162
|
+
contentRef: React.RefObject<HTMLDivElement>;
|
|
163
|
+
marginBlock: number;
|
|
164
|
+
}) => {
|
|
165
|
+
const hostRef = React.useRef<HTMLDivElement | null>(null);
|
|
166
|
+
const resolvedHeight = usePlainHostHeight({ height, heightMode, hostRef, marginBlock });
|
|
167
|
+
|
|
168
|
+
return (
|
|
169
|
+
<div
|
|
170
|
+
{...rest}
|
|
171
|
+
ref={hostRef}
|
|
172
|
+
id={`model-${uid}`}
|
|
173
|
+
className={className}
|
|
174
|
+
style={{
|
|
175
|
+
display: 'flex',
|
|
176
|
+
flexDirection: 'column',
|
|
177
|
+
height: resolvedHeight ?? undefined,
|
|
178
|
+
minHeight: 0,
|
|
179
|
+
overflow: 'auto',
|
|
180
|
+
...(style || {}),
|
|
181
|
+
}}
|
|
182
|
+
>
|
|
183
|
+
{beforeContent}
|
|
184
|
+
<div ref={contentRef} />
|
|
185
|
+
{afterContent}
|
|
186
|
+
</div>
|
|
187
|
+
);
|
|
188
|
+
};
|
|
189
|
+
|
|
19
190
|
export class JSBlockModel extends BlockModel {
|
|
20
191
|
// Avoid double-run on first mount; only rerun after remounts
|
|
21
192
|
private _mountedOnce = false;
|
|
193
|
+
|
|
194
|
+
get showBlockCard() {
|
|
195
|
+
return this.getStepParams('jsSettings', 'showBlockCard')?.showBlockCard !== false;
|
|
196
|
+
}
|
|
197
|
+
|
|
22
198
|
renderComponent(): React.ReactNode {
|
|
23
199
|
return <div ref={this.context.ref} />;
|
|
24
200
|
}
|
|
25
201
|
render() {
|
|
26
202
|
const decoratorProps = this.decoratorProps || {};
|
|
27
|
-
const {
|
|
203
|
+
const {
|
|
204
|
+
className,
|
|
205
|
+
id: _ignoredId,
|
|
206
|
+
title,
|
|
207
|
+
description,
|
|
208
|
+
showCard: _ignoredShowCard,
|
|
209
|
+
heightMode,
|
|
210
|
+
height,
|
|
211
|
+
style,
|
|
212
|
+
beforeContent,
|
|
213
|
+
afterContent,
|
|
214
|
+
...rest
|
|
215
|
+
} = decoratorProps;
|
|
28
216
|
const mergedClassName = ['code-block', className].filter(Boolean).join(' ');
|
|
29
217
|
|
|
218
|
+
if (!this.showBlockCard) {
|
|
219
|
+
return (
|
|
220
|
+
<JSBlockPlainHost
|
|
221
|
+
{...rest}
|
|
222
|
+
uid={this.uid}
|
|
223
|
+
className={mergedClassName}
|
|
224
|
+
heightMode={heightMode}
|
|
225
|
+
height={height}
|
|
226
|
+
style={style}
|
|
227
|
+
beforeContent={beforeContent}
|
|
228
|
+
afterContent={afterContent}
|
|
229
|
+
contentRef={this.context.ref}
|
|
230
|
+
marginBlock={this.context.themeToken?.marginBlock ?? 0}
|
|
231
|
+
/>
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const cardProps = {
|
|
236
|
+
...rest,
|
|
237
|
+
height,
|
|
238
|
+
style,
|
|
239
|
+
...(beforeContent === undefined ? {} : { beforeContent }),
|
|
240
|
+
...(afterContent === undefined ? {} : { afterContent }),
|
|
241
|
+
};
|
|
242
|
+
|
|
30
243
|
return (
|
|
31
244
|
<BlockItemCard
|
|
32
245
|
id={`model-${this.uid}`}
|
|
33
246
|
className={mergedClassName}
|
|
34
247
|
title={title}
|
|
35
248
|
description={description}
|
|
36
|
-
{
|
|
249
|
+
heightMode={heightMode}
|
|
250
|
+
{...cardProps}
|
|
37
251
|
>
|
|
38
252
|
<div ref={this.context.ref} />
|
|
39
253
|
</BlockItemCard>
|
|
@@ -61,6 +275,13 @@ JSBlockModel.registerFlow({
|
|
|
61
275
|
key: 'jsSettings',
|
|
62
276
|
title: 'JavaScript settings',
|
|
63
277
|
steps: {
|
|
278
|
+
showBlockCard: {
|
|
279
|
+
title: tExpr('Show block card'),
|
|
280
|
+
uiMode: { type: 'switch', key: 'showBlockCard' },
|
|
281
|
+
defaultParams: {
|
|
282
|
+
showBlockCard: true,
|
|
283
|
+
},
|
|
284
|
+
},
|
|
64
285
|
runJs: {
|
|
65
286
|
title: tExpr('Write JavaScript'),
|
|
66
287
|
useRawParams: true,
|
|
@@ -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
|
+
});
|
|
@@ -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
|
|
@@ -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);
|
|
@@ -198,6 +198,48 @@ const useFieldPermissionMessage = (model, allowEdit) => {
|
|
|
198
198
|
return messageValue;
|
|
199
199
|
};
|
|
200
200
|
|
|
201
|
+
const recordSelectClassName = css`
|
|
202
|
+
min-width: 0;
|
|
203
|
+
|
|
204
|
+
.ant-select-selector {
|
|
205
|
+
min-width: 0;
|
|
206
|
+
overflow: hidden;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
.ant-select-selection-search,
|
|
210
|
+
.ant-select-selection-item,
|
|
211
|
+
.ant-select-selection-placeholder,
|
|
212
|
+
.ant-select-selection-overflow,
|
|
213
|
+
.ant-select-selection-overflow-item {
|
|
214
|
+
min-width: 0;
|
|
215
|
+
max-width: 100%;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
.ant-select-selection-item,
|
|
219
|
+
.ant-select-selection-item-content {
|
|
220
|
+
overflow: hidden;
|
|
221
|
+
text-overflow: ellipsis;
|
|
222
|
+
white-space: nowrap;
|
|
223
|
+
}
|
|
224
|
+
`;
|
|
225
|
+
|
|
226
|
+
const recordSelectLabelClassName = css`
|
|
227
|
+
display: block;
|
|
228
|
+
min-width: 0;
|
|
229
|
+
max-width: 100%;
|
|
230
|
+
overflow: hidden;
|
|
231
|
+
text-overflow: ellipsis;
|
|
232
|
+
white-space: nowrap;
|
|
233
|
+
|
|
234
|
+
* {
|
|
235
|
+
min-width: 0;
|
|
236
|
+
max-width: 100%;
|
|
237
|
+
overflow: hidden;
|
|
238
|
+
text-overflow: ellipsis;
|
|
239
|
+
white-space: nowrap !important;
|
|
240
|
+
}
|
|
241
|
+
`;
|
|
242
|
+
|
|
201
243
|
const LazySelect = (props: Readonly<LazySelectProps>) => {
|
|
202
244
|
const {
|
|
203
245
|
fieldNames,
|
|
@@ -210,6 +252,7 @@ const LazySelect = (props: Readonly<LazySelectProps>) => {
|
|
|
210
252
|
onChange,
|
|
211
253
|
allowCreate = true,
|
|
212
254
|
allowEdit = true,
|
|
255
|
+
className,
|
|
213
256
|
...others
|
|
214
257
|
} = props;
|
|
215
258
|
const model: any = useFlowModel();
|
|
@@ -317,6 +360,7 @@ const LazySelect = (props: Readonly<LazySelectProps>) => {
|
|
|
317
360
|
<Select
|
|
318
361
|
style={{ width: '100%' }}
|
|
319
362
|
{...others}
|
|
363
|
+
className={[recordSelectClassName, className].filter(Boolean).join(' ')}
|
|
320
364
|
allowClear
|
|
321
365
|
showSearch
|
|
322
366
|
maxTagCount="responsive"
|
|
@@ -409,19 +453,7 @@ const LazySelect = (props: Readonly<LazySelectProps>) => {
|
|
|
409
453
|
}}
|
|
410
454
|
popupMatchSelectWidth
|
|
411
455
|
labelRender={(data) => {
|
|
412
|
-
return
|
|
413
|
-
<div
|
|
414
|
-
className={css`
|
|
415
|
-
div {
|
|
416
|
-
white-space: nowrap !important;
|
|
417
|
-
overflow: hidden;
|
|
418
|
-
text-overflow: ellipsis;
|
|
419
|
-
}
|
|
420
|
-
`}
|
|
421
|
-
>
|
|
422
|
-
{data.label}
|
|
423
|
-
</div>
|
|
424
|
-
);
|
|
456
|
+
return <div className={recordSelectLabelClassName}>{data.label}</div>;
|
|
425
457
|
}}
|
|
426
458
|
dropdownRender={(menu) => {
|
|
427
459
|
const isFullMatch = realOptions.some((v) => v[normalizedFieldNames.label] === others.searchText);
|