@nocobase/flow-engine 2.2.0-beta.14 → 2.2.0-beta.16
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/lib/acl/Acl.d.ts +2 -1
- package/lib/acl/Acl.js +28 -0
- package/lib/components/FlowContextSelector.js +55 -12
- package/lib/components/FormItem.js +11 -7
- package/lib/components/MobilePopup.js +14 -3
- package/lib/components/subModel/LazyDropdown.js +41 -26
- package/lib/components/variables/VariableHybridInput.d.ts +9 -0
- package/lib/components/variables/VariableHybridInput.js +146 -17
- package/lib/components/variables/VariableInput.js +19 -7
- package/lib/components/variables/VariableTag.js +48 -36
- package/lib/components/variables/types.d.ts +21 -0
- package/lib/flowI18n.js +3 -3
- package/lib/locale/en-US.json +2 -0
- package/lib/locale/index.d.ts +4 -0
- package/lib/locale/zh-CN.json +2 -0
- package/lib/types.d.ts +3 -1
- package/lib/types.js +1 -0
- package/package.json +4 -4
- package/src/__tests__/flowI18n.test.ts +11 -0
- package/src/acl/Acl.tsx +36 -1
- package/src/acl/__tests__/Acl.test.tsx +70 -0
- package/src/components/FlowContextSelector.tsx +66 -11
- package/src/components/FormItem.tsx +12 -7
- package/src/components/MobilePopup.tsx +16 -4
- package/src/components/__tests__/FormItem.test.tsx +17 -2
- package/src/components/__tests__/MobilePopup.test.tsx +42 -1
- package/src/components/subModel/LazyDropdown.tsx +44 -26
- package/src/components/subModel/__tests__/AddSubModelButton.test.tsx +85 -2
- package/src/components/variables/VariableHybridInput.tsx +185 -14
- package/src/components/variables/VariableInput.tsx +32 -7
- package/src/components/variables/VariableTag.tsx +51 -37
- package/src/components/variables/__tests__/FlowContextSelector.test.tsx +60 -3
- package/src/components/variables/__tests__/VariableHybridInput.test.tsx +212 -0
- package/src/components/variables/__tests__/VariableInput.test.tsx +202 -6
- package/src/components/variables/__tests__/VariableTag.test.tsx +80 -0
- package/src/components/variables/types.ts +21 -0
- package/src/flowI18n.ts +8 -3
- package/src/locale/__tests__/index.test.ts +21 -0
- package/src/locale/en-US.json +2 -0
- package/src/locale/zh-CN.json +2 -0
- package/src/types.ts +2 -0
|
@@ -17,6 +17,17 @@ describe('FlowI18n', () => {
|
|
|
17
17
|
expect(i18n.translate("{{ t('Hello') }}")).toBe('你好');
|
|
18
18
|
});
|
|
19
19
|
|
|
20
|
+
it('keeps embedded quotes of a different type inside the key', () => {
|
|
21
|
+
// A single-quoted key whose text contains double quotes (and vice versa) must not be truncated at the first inner
|
|
22
|
+
// quote.
|
|
23
|
+
const key = 'Unlike "Post-action event", it listens for data changes.';
|
|
24
|
+
const table: Record<string, string> = { [key]: '与“操作后事件”不同,它监听数据变动。' };
|
|
25
|
+
const i18n = new FlowI18n({ i18n: { t: (k: string) => table[k] ?? k } });
|
|
26
|
+
|
|
27
|
+
expect(i18n.translate(`{{t('${key}', { ns: "workflow" })}}`)).toBe(table[key]);
|
|
28
|
+
expect(i18n.translate(`{{t("It's here", { ns: "workflow" })}}`)).toBe("It's here");
|
|
29
|
+
});
|
|
30
|
+
|
|
20
31
|
it('template compile ignores malformed options', () => {
|
|
21
32
|
const spy = vi.spyOn(console, 'warn').mockImplementation(() => undefined);
|
|
22
33
|
const i18n = new FlowI18n({ i18n: { t: (k: string) => k } });
|
package/src/acl/Acl.tsx
CHANGED
|
@@ -16,7 +16,7 @@ interface CheckOptions {
|
|
|
16
16
|
actionName: string;
|
|
17
17
|
fields?: string[];
|
|
18
18
|
recordPkValue?: string | number;
|
|
19
|
-
allowedActions
|
|
19
|
+
allowedActions?: Record<string, Array<string | number>>;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export class ACL {
|
|
@@ -149,6 +149,41 @@ export class ACL {
|
|
|
149
149
|
return allowed;
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
+
can(options: CheckOptions): boolean {
|
|
153
|
+
const { allowAll } = this.data;
|
|
154
|
+
if (allowAll) {
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const { actionName, allowedActions, recordPkValue } = options;
|
|
159
|
+
const hasRecordPkValue = recordPkValue !== undefined && recordPkValue !== null;
|
|
160
|
+
const recordPermission =
|
|
161
|
+
hasRecordPkValue && allowedActions ? this.verifyScope(actionName, recordPkValue, allowedActions) : null;
|
|
162
|
+
if (hasRecordPkValue && allowedActions && recordPermission !== true) {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const params = this.parseAction(options);
|
|
167
|
+
if (!params) {
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
if (!_.isEmpty(params.filter) && recordPermission !== true) {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
if (!options.fields?.length) {
|
|
174
|
+
return true;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const allowedFields: string[] = []
|
|
178
|
+
.concat(params.whitelist || [])
|
|
179
|
+
.concat(params.fields || [])
|
|
180
|
+
.concat(params.appends || []);
|
|
181
|
+
if (!allowedFields.length) {
|
|
182
|
+
return true;
|
|
183
|
+
}
|
|
184
|
+
return options.fields.every((field) => allowedFields.includes(field));
|
|
185
|
+
}
|
|
186
|
+
|
|
152
187
|
async aclCheck(options: CheckOptions): Promise<boolean> {
|
|
153
188
|
// await this.load();
|
|
154
189
|
const { allowAll } = this.data;
|
|
@@ -71,6 +71,76 @@ describe('ACL', () => {
|
|
|
71
71
|
expect(notOk).toBe(false);
|
|
72
72
|
});
|
|
73
73
|
|
|
74
|
+
it('checks record update scope before field permission', () => {
|
|
75
|
+
const payload = {
|
|
76
|
+
data: {
|
|
77
|
+
allowAll: false,
|
|
78
|
+
actionAlias: {},
|
|
79
|
+
resources: ['posts'],
|
|
80
|
+
actions: { 'posts:update': { whitelist: ['title'] } },
|
|
81
|
+
strategy: { actions: [] },
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
const engine = makeEngine(payload);
|
|
85
|
+
const acl = new ACL(engine);
|
|
86
|
+
acl.setData(payload.data);
|
|
87
|
+
|
|
88
|
+
const options = {
|
|
89
|
+
dataSourceKey: 'main',
|
|
90
|
+
resourceName: 'posts',
|
|
91
|
+
actionName: 'update',
|
|
92
|
+
allowedActions: {
|
|
93
|
+
update: [1],
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
expect(acl.can({ ...options, recordPkValue: 1, fields: ['title'] })).toBe(true);
|
|
98
|
+
expect(acl.can({ ...options, recordPkValue: 2, fields: ['title'] })).toBe(false);
|
|
99
|
+
expect(acl.can({ ...options, recordPkValue: 1, fields: ['body'] })).toBe(false);
|
|
100
|
+
expect(acl.can({ ...options, recordPkValue: 0, fields: ['title'] })).toBe(false);
|
|
101
|
+
expect(
|
|
102
|
+
acl.can({
|
|
103
|
+
dataSourceKey: 'main',
|
|
104
|
+
resourceName: 'posts',
|
|
105
|
+
actionName: 'update',
|
|
106
|
+
fields: ['title'],
|
|
107
|
+
}),
|
|
108
|
+
).toBe(true);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('allows every field when a scoped action has no field restriction', () => {
|
|
112
|
+
const payload = {
|
|
113
|
+
data: {
|
|
114
|
+
allowAll: false,
|
|
115
|
+
actionAlias: {},
|
|
116
|
+
resources: ['posts'],
|
|
117
|
+
actions: {
|
|
118
|
+
'posts:update': {
|
|
119
|
+
filter: { createdById: '{{ ctx.state.currentUser.id }}' },
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
strategy: { actions: [] },
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
const engine = makeEngine(payload);
|
|
126
|
+
const acl = new ACL(engine);
|
|
127
|
+
acl.setData(payload.data);
|
|
128
|
+
|
|
129
|
+
const options = {
|
|
130
|
+
dataSourceKey: 'main',
|
|
131
|
+
resourceName: 'posts',
|
|
132
|
+
actionName: 'update',
|
|
133
|
+
allowedActions: {
|
|
134
|
+
update: [1],
|
|
135
|
+
},
|
|
136
|
+
fields: ['title'],
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
expect(acl.can({ ...options, recordPkValue: 1 })).toBe(true);
|
|
140
|
+
expect(acl.can({ ...options, recordPkValue: 2 })).toBe(false);
|
|
141
|
+
expect(acl.can({ ...options, allowedActions: undefined, recordPkValue: undefined })).toBe(false);
|
|
142
|
+
});
|
|
143
|
+
|
|
74
144
|
it('reloads permissions when auth token changes', async () => {
|
|
75
145
|
const payload1 = {
|
|
76
146
|
data: {
|
|
@@ -40,6 +40,18 @@ type SelectedPathInfo = {
|
|
|
40
40
|
meta?: ContextSelectorItem['meta'];
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
+
type MetaNodeTooltipOptions = { tooltip?: React.ReactNode };
|
|
44
|
+
|
|
45
|
+
function getMetaNodeTooltip(meta?: ContextSelectorItem['meta']): React.ReactNode {
|
|
46
|
+
if (!meta) {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const metaWithTooltip = meta as ContextSelectorItem['meta'] & MetaNodeTooltipOptions;
|
|
51
|
+
const options = meta.options as MetaNodeTooltipOptions | undefined;
|
|
52
|
+
return metaWithTooltip.tooltip ?? options?.tooltip;
|
|
53
|
+
}
|
|
54
|
+
|
|
43
55
|
const normalizePath = (path: unknown): string[] | undefined => {
|
|
44
56
|
if (!Array.isArray(path)) {
|
|
45
57
|
return undefined;
|
|
@@ -85,6 +97,7 @@ const FlowContextSelectorComponent: React.FC<FlowContextSelectorProps> = ({
|
|
|
85
97
|
value,
|
|
86
98
|
onChange,
|
|
87
99
|
children,
|
|
100
|
+
active,
|
|
88
101
|
metaTree,
|
|
89
102
|
showSearch = false,
|
|
90
103
|
parseValueToPath: customParseValueToPath = parseValueToPath,
|
|
@@ -92,6 +105,7 @@ const FlowContextSelectorComponent: React.FC<FlowContextSelectorProps> = ({
|
|
|
92
105
|
open,
|
|
93
106
|
onlyLeafSelectable = false,
|
|
94
107
|
ignoreFieldNames,
|
|
108
|
+
dropdownFooter,
|
|
95
109
|
...cascaderProps
|
|
96
110
|
}) => {
|
|
97
111
|
const { token } = theme.useToken();
|
|
@@ -119,17 +133,28 @@ const FlowContextSelectorComponent: React.FC<FlowContextSelectorProps> = ({
|
|
|
119
133
|
|
|
120
134
|
// 文本国际化:仅当 label 为字符串时进行翻译
|
|
121
135
|
const baseLabel = typeof o.label === 'string' ? flowCtx.t(o.label) : o.label;
|
|
136
|
+
const labelText = typeof baseLabel === 'string' ? baseLabel : String(o.value);
|
|
137
|
+
const tooltip = getMetaNodeTooltip(meta);
|
|
138
|
+
const tooltipTitle = disabled
|
|
139
|
+
? disabledReason || tooltip || flowCtx.t('This variable is not available')
|
|
140
|
+
: tooltip;
|
|
122
141
|
|
|
123
|
-
const label =
|
|
142
|
+
const label = tooltipTitle ? (
|
|
124
143
|
<span>
|
|
125
144
|
{baseLabel}
|
|
126
145
|
<Tooltip
|
|
127
|
-
title={
|
|
128
|
-
placement="
|
|
129
|
-
|
|
146
|
+
title={typeof tooltipTitle === 'string' ? flowCtx.t(tooltipTitle) : tooltipTitle}
|
|
147
|
+
placement="top"
|
|
148
|
+
classNames={{ root: 'flow-variable-tip' }}
|
|
130
149
|
destroyTooltipOnHide
|
|
131
150
|
>
|
|
132
|
-
<QuestionCircleOutlined
|
|
151
|
+
<QuestionCircleOutlined
|
|
152
|
+
aria-label={`${labelText} tooltip`}
|
|
153
|
+
style={{
|
|
154
|
+
marginLeft: token.marginXXS,
|
|
155
|
+
color: disabled ? token.colorTextDisabled : token.colorTextDescription,
|
|
156
|
+
}}
|
|
157
|
+
/>
|
|
133
158
|
</Tooltip>
|
|
134
159
|
</span>
|
|
135
160
|
) : (
|
|
@@ -144,7 +169,7 @@ const FlowContextSelectorComponent: React.FC<FlowContextSelectorProps> = ({
|
|
|
144
169
|
};
|
|
145
170
|
});
|
|
146
171
|
},
|
|
147
|
-
[flowCtx],
|
|
172
|
+
[flowCtx, token.colorTextDescription, token.colorTextDisabled, token.marginXXS],
|
|
148
173
|
);
|
|
149
174
|
|
|
150
175
|
// 用于强制重新渲染的状态
|
|
@@ -265,13 +290,13 @@ const FlowContextSelectorComponent: React.FC<FlowContextSelectorProps> = ({
|
|
|
265
290
|
|
|
266
291
|
// 默认按钮组件
|
|
267
292
|
const defaultChildren = useMemo(() => {
|
|
268
|
-
const hasSelected = currentPath && currentPath.length > 0;
|
|
293
|
+
const hasSelected = active ?? Boolean(currentPath && currentPath.length > 0);
|
|
269
294
|
return (
|
|
270
|
-
<Button type={hasSelected ? 'primary' : 'default'} style={defaultButtonStyle}>
|
|
295
|
+
<Button type={hasSelected ? 'primary' : 'default'} style={defaultButtonStyle} disabled={cascaderProps.disabled}>
|
|
271
296
|
x
|
|
272
297
|
</Button>
|
|
273
298
|
);
|
|
274
|
-
}, [currentPath]);
|
|
299
|
+
}, [active, cascaderProps.disabled, currentPath]);
|
|
275
300
|
|
|
276
301
|
// 处理选择变化事件
|
|
277
302
|
const handleChange = useCallback(
|
|
@@ -360,12 +385,41 @@ const FlowContextSelectorComponent: React.FC<FlowContextSelectorProps> = ({
|
|
|
360
385
|
[cascaderOnDropdownVisibleChange, open],
|
|
361
386
|
);
|
|
362
387
|
|
|
388
|
+
// Footer hint at the bottom of the dropdown. Defaults to the "double click to choose entire object" hint whenever
|
|
389
|
+
// non-leaf selection is allowed (double-clicking a non-leaf selects the whole object). Callers can override with
|
|
390
|
+
// their own node, or pass `null` to hide it.
|
|
391
|
+
const footerNode = useMemo(() => {
|
|
392
|
+
if (dropdownFooter !== undefined) {
|
|
393
|
+
return dropdownFooter;
|
|
394
|
+
}
|
|
395
|
+
if (onlyLeafSelectable) {
|
|
396
|
+
return null;
|
|
397
|
+
}
|
|
398
|
+
return (
|
|
399
|
+
<div
|
|
400
|
+
className={css`
|
|
401
|
+
padding: 6px 12px;
|
|
402
|
+
color: ${token.colorTextDescription};
|
|
403
|
+
border-top: 1px solid ${token.colorSplit};
|
|
404
|
+
font-size: ${token.fontSizeSM}px;
|
|
405
|
+
`}
|
|
406
|
+
>
|
|
407
|
+
{flowCtx.t('Double click to choose entire object')}
|
|
408
|
+
</div>
|
|
409
|
+
);
|
|
410
|
+
}, [dropdownFooter, onlyLeafSelectable, token, flowCtx]);
|
|
411
|
+
|
|
363
412
|
const renderDropdown = useCallback(
|
|
364
413
|
(menu: React.ReactElement) => {
|
|
365
414
|
const cascaderMenuNode = cascaderDropdownRender ? cascaderDropdownRender(menu) : menu;
|
|
366
415
|
const cascaderMenu = React.isValidElement(cascaderMenuNode) ? cascaderMenuNode : <>{cascaderMenuNode}</>;
|
|
367
416
|
if (!isSearchEnabled || children === null) {
|
|
368
|
-
return
|
|
417
|
+
return (
|
|
418
|
+
<>
|
|
419
|
+
{cascaderMenu}
|
|
420
|
+
{footerNode}
|
|
421
|
+
</>
|
|
422
|
+
);
|
|
369
423
|
}
|
|
370
424
|
|
|
371
425
|
return (
|
|
@@ -381,10 +435,11 @@ const FlowContextSelectorComponent: React.FC<FlowContextSelectorProps> = ({
|
|
|
381
435
|
/>
|
|
382
436
|
</div>
|
|
383
437
|
{cascaderMenu}
|
|
438
|
+
{footerNode}
|
|
384
439
|
</>
|
|
385
440
|
);
|
|
386
441
|
},
|
|
387
|
-
[cascaderDropdownRender, cascaderSearchInputClassName, children, flowCtx, isSearchEnabled, searchText],
|
|
442
|
+
[cascaderDropdownRender, cascaderSearchInputClassName, children, flowCtx, isSearchEnabled, searchText, footerNode],
|
|
388
443
|
);
|
|
389
444
|
|
|
390
445
|
const inlinePlaceholder =
|
|
@@ -54,15 +54,20 @@ const formItemPropKeys: (keyof ExtendedFormItemProps)[] = [
|
|
|
54
54
|
'showLabel',
|
|
55
55
|
];
|
|
56
56
|
|
|
57
|
+
const modelInternalPropKeys = ['globalSort'];
|
|
58
|
+
|
|
57
59
|
export const FormItem = ({
|
|
58
60
|
children,
|
|
59
61
|
showLabel = true,
|
|
60
62
|
labelWidth,
|
|
61
63
|
...rest
|
|
62
64
|
}: ExtendedFormItemProps & ChildExtraProps) => {
|
|
65
|
+
const forwardedRest = Object.fromEntries(
|
|
66
|
+
Object.entries(rest).filter(([key]) => !modelInternalPropKeys.includes(key)),
|
|
67
|
+
) as ExtendedFormItemProps & ChildExtraProps;
|
|
63
68
|
// 过滤掉 Form.Item 专用 props,只保留要传给子组件的
|
|
64
69
|
const childProps = Object.fromEntries(
|
|
65
|
-
Object.entries(
|
|
70
|
+
Object.entries(forwardedRest).filter(([key]) => !formItemPropKeys.includes(key as keyof ExtendedFormItemProps)),
|
|
66
71
|
);
|
|
67
72
|
|
|
68
73
|
const processedChildren =
|
|
@@ -74,7 +79,7 @@ export const FormItem = ({
|
|
|
74
79
|
}
|
|
75
80
|
return child;
|
|
76
81
|
});
|
|
77
|
-
const { label, labelWrap, colon = true, layout } =
|
|
82
|
+
const { label, labelWrap, colon = true, layout } = forwardedRest;
|
|
78
83
|
const effectiveLabelWrap = !layout || layout === 'vertical' ? true : labelWrap;
|
|
79
84
|
const labelColStyle =
|
|
80
85
|
layout === 'vertical' ? { width: labelWidth, ...verticalFormItemLabelStyle } : { width: labelWidth };
|
|
@@ -122,17 +127,17 @@ export const FormItem = ({
|
|
|
122
127
|
};
|
|
123
128
|
return (
|
|
124
129
|
<Form.Item
|
|
125
|
-
{...
|
|
126
|
-
style={{ ...formItemStyle, ...
|
|
130
|
+
{...forwardedRest}
|
|
131
|
+
style={{ ...formItemStyle, ...forwardedRest.style }}
|
|
127
132
|
labelCol={{ style: labelColStyle }}
|
|
128
133
|
layout={layout}
|
|
129
134
|
label={renderLabel()}
|
|
130
135
|
colon={false}
|
|
131
|
-
extra={
|
|
136
|
+
extra={forwardedRest.extra && <span style={{ whiteSpace: 'pre-wrap' }}>{forwardedRest.extra}</span>}
|
|
132
137
|
tooltip={
|
|
133
|
-
|
|
138
|
+
forwardedRest.tooltip &&
|
|
134
139
|
({
|
|
135
|
-
title:
|
|
140
|
+
title: forwardedRest.tooltip,
|
|
136
141
|
overlayInnerStyle: { whiteSpace: 'pre-line' },
|
|
137
142
|
} as TooltipProps)
|
|
138
143
|
}
|
|
@@ -26,26 +26,38 @@ interface MobilePopupProps {
|
|
|
26
26
|
footer?: ReactNode;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
const getMobilePopupMaxHeight = () => {
|
|
30
|
+
if (typeof CSS !== 'undefined' && CSS.supports?.('height', '100dvh')) {
|
|
31
|
+
return 'calc(100dvh - var(--nb-mobile-page-header-height, 46px))';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return 'calc(100vh - var(--nb-mobile-page-header-height, 46px))';
|
|
35
|
+
};
|
|
36
|
+
|
|
29
37
|
export const MobilePopup: FC<MobilePopupProps> = (props) => {
|
|
30
38
|
const { title, visible, onClose: closePopup, children, minHeight, className, footer } = props;
|
|
31
39
|
const { t } = useTranslation();
|
|
32
40
|
const { componentCls, hashId } = useMobileActionDrawerStyle();
|
|
33
41
|
|
|
34
42
|
const bodyStyles = (props as MobilePopupProps & { styles?: { body?: React.CSSProperties } }).styles?.body;
|
|
43
|
+
const defaultMaxHeight = getMobilePopupMaxHeight();
|
|
35
44
|
const popupStyle = useMemo(() => {
|
|
36
45
|
return {
|
|
37
46
|
minHeight: bodyStyles?.minHeight ?? minHeight,
|
|
38
47
|
height: bodyStyles?.height,
|
|
39
|
-
maxHeight: bodyStyles?.maxHeight,
|
|
48
|
+
maxHeight: bodyStyles?.maxHeight ?? defaultMaxHeight,
|
|
40
49
|
};
|
|
41
|
-
}, [bodyStyles?.height, bodyStyles?.maxHeight, bodyStyles?.minHeight, minHeight]);
|
|
50
|
+
}, [bodyStyles?.height, bodyStyles?.maxHeight, bodyStyles?.minHeight, defaultMaxHeight, minHeight]);
|
|
42
51
|
|
|
43
|
-
const bodyStyle = useMemo(() => {
|
|
52
|
+
const bodyStyle = useMemo<React.CSSProperties>(() => {
|
|
44
53
|
return {
|
|
45
54
|
padding: 0,
|
|
55
|
+
maxHeight: defaultMaxHeight,
|
|
56
|
+
overflowY: 'auto',
|
|
57
|
+
overflowX: 'hidden',
|
|
46
58
|
...bodyStyles,
|
|
47
59
|
};
|
|
48
|
-
}, [bodyStyles]);
|
|
60
|
+
}, [bodyStyles, defaultMaxHeight]);
|
|
49
61
|
|
|
50
62
|
const handleCloseKeyDown = useCallback(
|
|
51
63
|
(event: React.KeyboardEvent<HTMLSpanElement>) => {
|
|
@@ -7,8 +7,10 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import {
|
|
11
|
-
import
|
|
10
|
+
import { render } from '@testing-library/react';
|
|
11
|
+
import React from 'react';
|
|
12
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
13
|
+
import { FormItem, formItemStyle, verticalFormItemLabelStyle } from '../FormItem';
|
|
12
14
|
|
|
13
15
|
describe('FormItem', () => {
|
|
14
16
|
it('keeps vertical label-to-value spacing consistent with v1', () => {
|
|
@@ -22,4 +24,17 @@ describe('FormItem', () => {
|
|
|
22
24
|
marginBottom: 12,
|
|
23
25
|
});
|
|
24
26
|
});
|
|
27
|
+
|
|
28
|
+
it('does not forward model-internal globalSort props to field children', () => {
|
|
29
|
+
const Field = vi.fn(() => <input aria-label="field" />);
|
|
30
|
+
|
|
31
|
+
render(
|
|
32
|
+
<FormItem globalSort={['title']} placeholder="Title">
|
|
33
|
+
<Field />
|
|
34
|
+
</FormItem>,
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
expect(Field).toHaveBeenCalledWith(expect.not.objectContaining({ globalSort: expect.anything() }), {});
|
|
38
|
+
expect(Field).toHaveBeenCalledWith(expect.objectContaining({ placeholder: 'Title' }), {});
|
|
39
|
+
});
|
|
25
40
|
});
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
import React from 'react';
|
|
11
11
|
import { fireEvent, render, screen } from '@testing-library/react';
|
|
12
|
-
import { describe, expect, it, vi } from 'vitest';
|
|
12
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
13
13
|
import { MobilePopup } from '../MobilePopup';
|
|
14
14
|
|
|
15
15
|
vi.mock('react-i18next', () => ({
|
|
@@ -61,6 +61,47 @@ describe('MobilePopup', () => {
|
|
|
61
61
|
React.ComponentProps<typeof MobilePopup> & { styles?: { body?: React.CSSProperties } }
|
|
62
62
|
>;
|
|
63
63
|
|
|
64
|
+
afterEach(() => {
|
|
65
|
+
vi.unstubAllGlobals();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('constrains the default popup to the dynamic viewport and keeps the body scrollable', () => {
|
|
69
|
+
vi.stubGlobal('CSS', {
|
|
70
|
+
supports: vi.fn((property: string, value: string) => property === 'height' && value === '100dvh'),
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
render(
|
|
74
|
+
<MobilePopup visible title="Title" onClose={vi.fn()}>
|
|
75
|
+
body
|
|
76
|
+
</MobilePopup>,
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
const maxHeight = 'calc(100dvh - var(--nb-mobile-page-header-height, 46px))';
|
|
80
|
+
|
|
81
|
+
expect(screen.getByTestId('mobile-popup')).toHaveStyle({ maxHeight });
|
|
82
|
+
expect(screen.getByTestId('mobile-popup-body')).toHaveStyle({
|
|
83
|
+
maxHeight,
|
|
84
|
+
overflowY: 'auto',
|
|
85
|
+
overflowX: 'hidden',
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('falls back to the layout viewport when dynamic viewport units are unavailable', () => {
|
|
90
|
+
vi.stubGlobal('CSS', {
|
|
91
|
+
supports: vi.fn(() => false),
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
render(
|
|
95
|
+
<MobilePopup visible title="Title" onClose={vi.fn()}>
|
|
96
|
+
body
|
|
97
|
+
</MobilePopup>,
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
expect(screen.getByTestId('mobile-popup-body')).toHaveStyle({
|
|
101
|
+
maxHeight: 'calc(100vh - var(--nb-mobile-page-header-height, 46px))',
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
64
105
|
it('applies drawer body styles as max bounds without forcing fixed half-window height', () => {
|
|
65
106
|
render(
|
|
66
107
|
<MobilePopupWithDrawerStyles visible title="Title" styles={{ body: { maxHeight: '50vh' } }} onClose={vi.fn()}>
|