@nocobase/client-v2 2.2.0-beta.17 → 2.2.0-beta.18
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/APIClient.d.ts +12 -0
- package/es/flow/components/placeholders/BlockPlaceholder.d.ts +1 -0
- package/es/flow/internal/utils/operatorSchemaHelper.d.ts +2 -2
- package/es/flow/models/base/CollectionBlockModel.d.ts +3 -0
- package/es/flow/models/blocks/details/DetailsBlockModel.d.ts +3 -0
- package/es/flow/models/blocks/filter-form/FilterFormGridModel.d.ts +1 -0
- package/es/flow/models/blocks/filter-form/FilterFormSubmitActionModel.d.ts +3 -1
- package/es/flow/models/blocks/form/FormBlockModel.d.ts +1 -0
- package/es/flow/models/blocks/table/TableBlockModel.d.ts +1 -0
- package/es/flow/models/blocks/table/TableColumnModel.d.ts +11 -0
- package/es/flow/models/blocks/table/utils.d.ts +1 -0
- package/es/flow/models/fields/AssociationFieldModel/RecordPickerFieldModel.d.ts +2 -1
- package/es/flow/models/fields/AssociationFieldModel/RecordSelectFieldModel.d.ts +0 -17
- package/es/flow/models/fields/AssociationFieldModel/recordSelectShared.d.ts +41 -0
- package/es/flow-compat/passwordUtils.d.ts +1 -1
- package/es/index.mjs +125 -116
- package/lib/index.js +162 -153
- package/package.json +7 -7
- package/src/APIClient.ts +92 -0
- package/src/Application.tsx +3 -1
- package/src/__tests__/APIClient.test.tsx +58 -0
- package/src/__tests__/settings-center.test.tsx +270 -6
- package/src/acl/ACLProvider.tsx +2 -0
- package/src/acl/__tests__/ACLProvider.test.tsx +92 -0
- package/src/components/form/filter/CollectionFilterItem.tsx +4 -2
- package/src/components/form/filter/__tests__/CollectionFilterItem.test.tsx +17 -0
- package/src/components/form/table/Table.tsx +81 -6
- package/src/components/form/table/__tests__/Table.columnWidth.test.tsx +433 -0
- package/src/flow/actions/__tests__/linkageRules.subFormSetFieldProps.test.ts +72 -0
- package/src/flow/actions/linkageRules.tsx +8 -3
- package/src/flow/admin-shell/admin-layout/AdminLayoutMenuUtils.tsx +78 -59
- package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutMenuModels.test.ts +228 -0
- package/src/flow/components/filter/VariableFilterItem.tsx +12 -3
- package/src/flow/components/filter/__tests__/VariableFilterItem.test.tsx +125 -0
- package/src/flow/components/placeholders/BlockPlaceholder.tsx +70 -23
- package/src/flow/components/placeholders/__tests__/BlockPlaceholder.test.tsx +57 -7
- package/src/flow/internal/utils/operatorSchemaHelper.ts +3 -2
- package/src/flow/models/base/CollectionBlockModel.tsx +23 -1
- package/src/flow/models/base/__tests__/CollectionBlockModel.initialBeforeRenderRefresh.test.ts +65 -9
- package/src/flow/models/blocks/details/DetailsBlockModel.tsx +8 -3
- package/src/flow/models/blocks/details/__tests__/DetailsBlockModel.initialPaginationChangeRefresh.test.ts +32 -1
- package/src/flow/models/blocks/filter-form/FilterFormGridModel.tsx +36 -5
- package/src/flow/models/blocks/filter-form/FilterFormItemModel.tsx +129 -14
- package/src/flow/models/blocks/filter-form/FilterFormSubmitActionModel.tsx +57 -4
- package/src/flow/models/blocks/filter-form/__tests__/FilterFormGridModel.onModelCreated.test.ts +174 -1
- package/src/flow/models/blocks/filter-form/__tests__/FilterFormItemModel.defineChildren.test.ts +359 -1
- package/src/flow/models/blocks/filter-form/__tests__/FilterFormItemModel.getFilterValue.test.ts +72 -0
- package/src/flow/models/blocks/filter-form/__tests__/FilterFormSubmitActionModel.lifecycle.test.ts +90 -0
- package/src/flow/models/blocks/filter-manager/FilterManager.ts +5 -0
- package/src/flow/models/blocks/filter-manager/__tests__/FilterManager.test.ts +40 -0
- package/src/flow/models/blocks/form/FormBlockModel.tsx +43 -0
- package/src/flow/models/blocks/form/__tests__/runJsFormSubmit.test.ts +131 -0
- package/src/flow/models/blocks/table/TableBlockModel.tsx +25 -1
- package/src/flow/models/blocks/table/TableColumnModel.tsx +18 -8
- package/src/flow/models/blocks/table/__tests__/TableBlockModel.filterReset.test.ts +78 -0
- package/src/flow/models/blocks/table/utils.ts +7 -0
- package/src/flow/models/fields/AssociationFieldModel/CascadeSelectFieldModel.tsx +33 -1
- package/src/flow/models/fields/AssociationFieldModel/RecordPickerFieldModel.tsx +24 -1
- package/src/flow/models/fields/AssociationFieldModel/RecordSelectFieldModel.tsx +9 -136
- package/src/flow/models/fields/AssociationFieldModel/__tests__/RecordPickerFieldModel.itemContext.test.ts +121 -3
- package/src/flow/models/fields/AssociationFieldModel/recordSelectShared.tsx +156 -0
- package/src/flow/models/fields/DisplayNumberFieldModel.tsx +1 -1
- package/src/flow/models/fields/NumberFieldModel.tsx +1 -1
- package/src/flow/models/fields/__tests__/DisplayNumberFieldModel.test.ts +33 -0
- package/src/flow/models/fields/__tests__/NumberFieldModel.test.tsx +47 -0
- package/src/flow/models/fields/mobile-components/MobileLazySelect.tsx +5 -0
- package/src/flow/models/fields/mobile-components/MobileSelect.tsx +27 -2
- package/src/flow/models/fields/mobile-components/__tests__/MobileSelect.test.tsx +122 -14
- package/src/settings-center/AdminSettingsLayout.tsx +23 -2
|
@@ -120,11 +120,16 @@ const isActionFlowModel = (model: any): boolean => {
|
|
|
120
120
|
return false;
|
|
121
121
|
};
|
|
122
122
|
|
|
123
|
+
const isFormFieldModel = (model: unknown): model is FlowModel => {
|
|
124
|
+
if (!model || typeof model !== 'object') return false;
|
|
125
|
+
return !!(model as FlowModel).subModels?.field;
|
|
126
|
+
};
|
|
127
|
+
|
|
123
128
|
// 获取表单中所有字段的 model 实例的通用函数
|
|
124
129
|
const getFormFields = (ctx: any) => {
|
|
125
130
|
try {
|
|
126
131
|
const fieldModels = ctx.model?.subModels?.grid?.subModels?.items || [];
|
|
127
|
-
return fieldModels.map((model
|
|
132
|
+
return fieldModels.filter(isFormFieldModel).map((model) => ({
|
|
128
133
|
label: model.props.label || model.props.name,
|
|
129
134
|
value: model.uid,
|
|
130
135
|
model,
|
|
@@ -346,8 +351,8 @@ const FieldStateEditor = ({
|
|
|
346
351
|
const getFormFieldsByForkModel = (ctx: any) => {
|
|
347
352
|
try {
|
|
348
353
|
const fieldModels = ctx.model?.subModels?.grid?.subModels?.items || [];
|
|
349
|
-
return fieldModels.map((model
|
|
350
|
-
const forkModel = Array.from(model.forks)[0] as
|
|
354
|
+
return fieldModels.filter(isFormFieldModel).map((model) => {
|
|
355
|
+
const forkModel = Array.from(model.forks)[0] as FlowModel | undefined;
|
|
351
356
|
|
|
352
357
|
if (forkModel) {
|
|
353
358
|
return {
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
FlowSettingsButton,
|
|
18
18
|
observer,
|
|
19
19
|
} from '@nocobase/flow-engine';
|
|
20
|
-
import { Badge
|
|
20
|
+
import { Badge } from 'antd';
|
|
21
21
|
import qs from 'qs';
|
|
22
22
|
import React, { FC, useCallback, useContext, useEffect } from 'react';
|
|
23
23
|
import { Link, useLocation, type NavigateFunction } from 'react-router-dom';
|
|
@@ -153,6 +153,24 @@ const getLayoutRoutePathFromModel = (model: FlowModel): AdminLayoutRoutePathLike
|
|
|
153
153
|
};
|
|
154
154
|
|
|
155
155
|
const menuItemStyle = { display: 'flex', alignItems: 'center', justifyContent: 'space-between' };
|
|
156
|
+
const siderMenuItemStyle: React.CSSProperties = { ...menuItemStyle, width: '100%', minWidth: 0 };
|
|
157
|
+
const siderMenuItemContentStyle: React.CSSProperties = { flex: 1, minWidth: 0, overflow: 'hidden' };
|
|
158
|
+
const siderMenuItemLinkStyle: React.CSSProperties = {
|
|
159
|
+
display: 'block',
|
|
160
|
+
flex: 1,
|
|
161
|
+
width: '100%',
|
|
162
|
+
minWidth: 0,
|
|
163
|
+
overflow: 'hidden',
|
|
164
|
+
};
|
|
165
|
+
const getMenuItemText = (name: React.ReactNode) => {
|
|
166
|
+
if (typeof name === 'string' || typeof name === 'number') {
|
|
167
|
+
return String(name);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (React.isValidElement<{ title?: unknown }>(name) && typeof name.props.title === 'string') {
|
|
171
|
+
return name.props.title;
|
|
172
|
+
}
|
|
173
|
+
};
|
|
156
174
|
const groupLandingEntryStyle = {
|
|
157
175
|
display: 'inline-flex',
|
|
158
176
|
alignItems: 'center',
|
|
@@ -553,16 +571,16 @@ export function resolveAdminLayoutMenuDragMoveOptionsFromEvent(
|
|
|
553
571
|
|
|
554
572
|
const GroupItem: FC<{ item: AdminLayoutMenuNode; options?: AdminLayoutMenuRenderOptions }> = (props) => {
|
|
555
573
|
const { item } = props;
|
|
574
|
+
const { inHeader } = useContext(HeaderContext);
|
|
556
575
|
const badgeCount = useEvaluatedExpression(item._route.options?.badge?.count, item._model?.context);
|
|
557
576
|
const navigate = useNavigateNoUpdate();
|
|
558
577
|
const routerBasename = useRouterBasename();
|
|
559
578
|
const { closeMobileMenu } = useContext(MobileMenuControlContext);
|
|
560
579
|
const ariaLabel =
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
: undefined;
|
|
580
|
+
getMenuItemText(item.name) ??
|
|
581
|
+
(typeof item._route?.title === 'string' || typeof item._route?.title === 'number'
|
|
582
|
+
? String(item._route.title)
|
|
583
|
+
: undefined);
|
|
566
584
|
const runtimePath = item._runtimePath;
|
|
567
585
|
const spaRuntimePath = runtimePath ? toRouterNavigationPath(runtimePath, routerBasename) : runtimePath;
|
|
568
586
|
|
|
@@ -633,7 +651,12 @@ const GroupItem: FC<{ item: AdminLayoutMenuNode; options?: AdminLayoutMenuRender
|
|
|
633
651
|
return (
|
|
634
652
|
<ParentRouteContext.Provider value={item._parentRoute}>
|
|
635
653
|
<NocoBaseRouteContext.Provider value={item._route}>
|
|
636
|
-
<div
|
|
654
|
+
<div
|
|
655
|
+
aria-label={ariaLabel}
|
|
656
|
+
title={inHeader || item._route?.tooltip ? undefined : ariaLabel}
|
|
657
|
+
role="none"
|
|
658
|
+
style={inHeader ? menuItemStyle : siderMenuItemStyle}
|
|
659
|
+
>
|
|
637
660
|
{content}
|
|
638
661
|
{landingEntry}
|
|
639
662
|
{badgeCount != null && (
|
|
@@ -650,24 +673,9 @@ const GroupItem: FC<{ item: AdminLayoutMenuNode; options?: AdminLayoutMenuRender
|
|
|
650
673
|
);
|
|
651
674
|
};
|
|
652
675
|
|
|
653
|
-
const WithTooltip: FC<{ title: React.ReactNode; hidden: boolean; badgeProps: any }> = (props) => {
|
|
654
|
-
const { inHeader } = useContext(HeaderContext);
|
|
655
|
-
|
|
656
|
-
if (props.hidden || inHeader) {
|
|
657
|
-
return props.children;
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
return (
|
|
661
|
-
<Tooltip title={props.title} placement="right">
|
|
662
|
-
<Badge {...props.badgeProps} style={{ transform: 'none', maxWidth: '10em' }} dot={false}>
|
|
663
|
-
{props.children}
|
|
664
|
-
</Badge>
|
|
665
|
-
</Tooltip>
|
|
666
|
-
);
|
|
667
|
-
};
|
|
668
|
-
|
|
669
676
|
const MenuItem: FC<{ item: AdminLayoutMenuNode; options?: AdminLayoutMenuRenderOptions }> = (props) => {
|
|
670
677
|
const { item } = props;
|
|
678
|
+
const { inHeader } = useContext(HeaderContext);
|
|
671
679
|
const location = useLocation();
|
|
672
680
|
const badgeCount = useEvaluatedExpression(item._route.options?.badge?.count, item._model?.context);
|
|
673
681
|
const navigate = useNavigateNoUpdate();
|
|
@@ -677,7 +685,10 @@ const MenuItem: FC<{ item: AdminLayoutMenuNode; options?: AdminLayoutMenuRenderO
|
|
|
677
685
|
const runtimePath = item._runtimePath || path;
|
|
678
686
|
const spaRuntimePath = runtimePath ? toRouterNavigationPath(runtimePath, basenameOfCurrentRouter) : runtimePath;
|
|
679
687
|
const isDocumentNavigation = item._navigationMode === 'document';
|
|
680
|
-
const
|
|
688
|
+
const { textColor: badgeTextColor, ...antdBadgeOptions } = item._route.options?.badge || {};
|
|
689
|
+
const badgeProps = { ...antdBadgeOptions, count: badgeCount };
|
|
690
|
+
const menuItemText = getMenuItemText(item.name);
|
|
691
|
+
const nativeTitle = inHeader || item._route?.tooltip ? undefined : menuItemText;
|
|
681
692
|
|
|
682
693
|
const canUseNativeAnchor = !!runtimePath && isDocumentNavigation;
|
|
683
694
|
|
|
@@ -767,17 +778,25 @@ const MenuItem: FC<{ item: AdminLayoutMenuNode; options?: AdminLayoutMenuRenderO
|
|
|
767
778
|
return (
|
|
768
779
|
<ParentRouteContext.Provider value={item._parentRoute}>
|
|
769
780
|
<NocoBaseRouteContext.Provider value={item._route}>
|
|
770
|
-
<div role="none" style={menuItemStyle}>
|
|
771
|
-
<div onClick={handleClickLink}>
|
|
772
|
-
<Link
|
|
781
|
+
<div role="none" style={inHeader ? menuItemStyle : siderMenuItemStyle}>
|
|
782
|
+
<div onClick={handleClickLink} style={inHeader ? undefined : siderMenuItemContentStyle}>
|
|
783
|
+
<Link
|
|
784
|
+
to={location.pathname}
|
|
785
|
+
aria-label={menuItemText}
|
|
786
|
+
title={nativeTitle}
|
|
787
|
+
style={inHeader ? undefined : siderMenuItemLinkStyle}
|
|
788
|
+
>
|
|
773
789
|
{props.children}
|
|
774
790
|
</Link>
|
|
775
791
|
</div>
|
|
776
792
|
{badgeCount != null && (
|
|
777
793
|
<Badge
|
|
778
|
-
{...
|
|
779
|
-
|
|
780
|
-
|
|
794
|
+
{...badgeProps}
|
|
795
|
+
style={{
|
|
796
|
+
marginLeft: 4,
|
|
797
|
+
...(badgeTextColor == null ? {} : { color: badgeTextColor }),
|
|
798
|
+
maxWidth: '10em',
|
|
799
|
+
}}
|
|
781
800
|
dot={false}
|
|
782
801
|
></Badge>
|
|
783
802
|
)}
|
|
@@ -787,45 +806,45 @@ const MenuItem: FC<{ item: AdminLayoutMenuNode; options?: AdminLayoutMenuRenderO
|
|
|
787
806
|
);
|
|
788
807
|
}
|
|
789
808
|
|
|
790
|
-
const itemContent = (
|
|
791
|
-
<
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
}
|
|
796
|
-
|
|
809
|
+
const itemContent = canUseNativeAnchor ? (
|
|
810
|
+
<a
|
|
811
|
+
href={runtimePath}
|
|
812
|
+
aria-label={menuItemText}
|
|
813
|
+
title={nativeTitle}
|
|
814
|
+
onClick={handleClickMenuItem}
|
|
815
|
+
style={inHeader ? undefined : siderMenuItemLinkStyle}
|
|
797
816
|
>
|
|
798
|
-
{
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
) : (
|
|
815
|
-
<span aria-label={typeof item.name === 'string' ? item.name : undefined}>{props.children}</span>
|
|
816
|
-
)}
|
|
817
|
-
</WithTooltip>
|
|
817
|
+
{props.children}
|
|
818
|
+
</a>
|
|
819
|
+
) : runtimePath ? (
|
|
820
|
+
<Link
|
|
821
|
+
to={spaRuntimePath}
|
|
822
|
+
aria-label={menuItemText}
|
|
823
|
+
title={nativeTitle}
|
|
824
|
+
onClick={handleClickMenuItem}
|
|
825
|
+
style={inHeader ? undefined : siderMenuItemLinkStyle}
|
|
826
|
+
>
|
|
827
|
+
{props.children}
|
|
828
|
+
</Link>
|
|
829
|
+
) : (
|
|
830
|
+
<span aria-label={menuItemText} title={nativeTitle} style={inHeader ? undefined : siderMenuItemLinkStyle}>
|
|
831
|
+
{props.children}
|
|
832
|
+
</span>
|
|
818
833
|
);
|
|
819
834
|
|
|
820
835
|
return (
|
|
821
836
|
<ParentRouteContext.Provider value={item._parentRoute}>
|
|
822
837
|
<NocoBaseRouteContext.Provider value={item._route}>
|
|
823
|
-
<div role="none" style={menuItemStyle}>
|
|
838
|
+
<div role="none" style={inHeader ? menuItemStyle : siderMenuItemStyle}>
|
|
824
839
|
{itemContent}
|
|
825
840
|
{badgeCount != null && (
|
|
826
841
|
<Badge
|
|
827
842
|
{...badgeProps}
|
|
828
|
-
style={{
|
|
843
|
+
style={{
|
|
844
|
+
marginLeft: 4,
|
|
845
|
+
...(badgeTextColor == null ? {} : { color: badgeTextColor }),
|
|
846
|
+
maxWidth: '10em',
|
|
847
|
+
}}
|
|
829
848
|
dot={false}
|
|
830
849
|
></Badge>
|
|
831
850
|
)}
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
AdminLayoutMenuItemModel,
|
|
20
20
|
AdminLayoutModel,
|
|
21
21
|
ADMIN_LAYOUT_MODEL_UID,
|
|
22
|
+
buildMenuTitleWithIcon,
|
|
22
23
|
getAdminLayoutMenuMovePositionOptions,
|
|
23
24
|
normalizeAdminLayoutMenuLegacyVariables,
|
|
24
25
|
openAdminLayoutMenuLink,
|
|
@@ -119,6 +120,233 @@ describe('AdminLayoutModel menu items', () => {
|
|
|
119
120
|
...options,
|
|
120
121
|
});
|
|
121
122
|
|
|
123
|
+
type MenuTitleOptions = {
|
|
124
|
+
title: string;
|
|
125
|
+
collapsed: boolean;
|
|
126
|
+
name?: React.ReactNode;
|
|
127
|
+
routeTitle?: string;
|
|
128
|
+
renderType?: 'item' | 'group';
|
|
129
|
+
tooltip?: string;
|
|
130
|
+
badgeCount?: number;
|
|
131
|
+
badgeIndicatorColor?: string;
|
|
132
|
+
badgeTextColor?: string;
|
|
133
|
+
depth?: number;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const createMenuTitle = (options: MenuTitleOptions) => {
|
|
137
|
+
const {
|
|
138
|
+
title,
|
|
139
|
+
collapsed,
|
|
140
|
+
name = title,
|
|
141
|
+
routeTitle = title,
|
|
142
|
+
renderType = 'item',
|
|
143
|
+
tooltip,
|
|
144
|
+
badgeCount,
|
|
145
|
+
badgeIndicatorColor,
|
|
146
|
+
badgeTextColor,
|
|
147
|
+
depth = 1,
|
|
148
|
+
} = options;
|
|
149
|
+
|
|
150
|
+
return React.createElement(
|
|
151
|
+
FlowEngineProvider,
|
|
152
|
+
{ engine },
|
|
153
|
+
React.createElement(
|
|
154
|
+
MemoryRouter,
|
|
155
|
+
{ initialEntries: ['/admin/current-page'] },
|
|
156
|
+
React.createElement(AdminLayoutMenuItemRenderer, {
|
|
157
|
+
renderType,
|
|
158
|
+
item: {
|
|
159
|
+
name,
|
|
160
|
+
path: '/admin/menu-title',
|
|
161
|
+
_runtimePath: '/apps/demo/v2/admin/menu-title',
|
|
162
|
+
_navigationMode: 'spa',
|
|
163
|
+
_isLegacy: false,
|
|
164
|
+
_depth: depth,
|
|
165
|
+
_route: {
|
|
166
|
+
type: NocoBaseDesktopRouteType.flowPage,
|
|
167
|
+
title: routeTitle,
|
|
168
|
+
tooltip,
|
|
169
|
+
schemaUid: 'menu-title',
|
|
170
|
+
options:
|
|
171
|
+
badgeCount == null
|
|
172
|
+
? {}
|
|
173
|
+
: {
|
|
174
|
+
badge: {
|
|
175
|
+
count: badgeCount,
|
|
176
|
+
styles: badgeIndicatorColor ? { indicator: { color: badgeIndicatorColor } } : undefined,
|
|
177
|
+
textColor: badgeTextColor,
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
dom: React.createElement(
|
|
183
|
+
'span',
|
|
184
|
+
{ className: 'ant-pro-base-menu-inline-item-text' },
|
|
185
|
+
collapsed ? title.slice(0, 1) : title,
|
|
186
|
+
),
|
|
187
|
+
options: { isMobile: false, collapsed },
|
|
188
|
+
}),
|
|
189
|
+
),
|
|
190
|
+
);
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
const renderMenuTitle = (options: MenuTitleOptions) => render(createMenuTitle(options));
|
|
194
|
+
|
|
195
|
+
it.each([false, true])(
|
|
196
|
+
'should use a native title without an extra tooltip trigger when collapsed is %s',
|
|
197
|
+
async (collapsed) => {
|
|
198
|
+
vi.useFakeTimers();
|
|
199
|
+
const title = 'A complete menu title that may be truncated';
|
|
200
|
+
|
|
201
|
+
try {
|
|
202
|
+
const { container } = renderMenuTitle({ title, collapsed });
|
|
203
|
+
const link = screen.getByRole('link', { name: title });
|
|
204
|
+
const menuItem = link.closest<HTMLElement>('[role="none"]');
|
|
205
|
+
|
|
206
|
+
expect(link).toHaveAttribute('title', title);
|
|
207
|
+
expect(link.parentElement).toBe(menuItem);
|
|
208
|
+
expect(menuItem).toHaveStyle({ width: '100%', minWidth: 0 });
|
|
209
|
+
expect(link).toHaveStyle({ display: 'block', width: '100%', minWidth: 0, overflow: 'hidden' });
|
|
210
|
+
expect(container.querySelector('.ant-tooltip')).not.toBeInTheDocument();
|
|
211
|
+
|
|
212
|
+
await act(async () => {
|
|
213
|
+
fireEvent.mouseEnter(link);
|
|
214
|
+
await vi.advanceTimersByTimeAsync(500);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
expect(screen.queryByRole('tooltip')).not.toBeInTheDocument();
|
|
218
|
+
} finally {
|
|
219
|
+
vi.clearAllTimers();
|
|
220
|
+
vi.useRealTimers();
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
it('should use the translated native title for an icon-wrapped nested menu name', () => {
|
|
226
|
+
const title = 'A translated nested menu title';
|
|
227
|
+
const { name } = buildMenuTitleWithIcon(
|
|
228
|
+
{ title: 'menu.nested.title', icon: 'AppstoreOutlined' },
|
|
229
|
+
() => title,
|
|
230
|
+
true,
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
renderMenuTitle({ title, name, collapsed: true, depth: 2 });
|
|
234
|
+
|
|
235
|
+
expect(screen.getByRole('link', { name: title })).toHaveAttribute('title', title);
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it('should use the translated native title for an icon-wrapped nested group name', () => {
|
|
239
|
+
const title = 'A translated nested group title';
|
|
240
|
+
const { name } = buildMenuTitleWithIcon(
|
|
241
|
+
{ title: 'menu.nested.group', icon: 'AppstoreOutlined' },
|
|
242
|
+
() => title,
|
|
243
|
+
true,
|
|
244
|
+
);
|
|
245
|
+
const { container } = renderMenuTitle({
|
|
246
|
+
title,
|
|
247
|
+
name,
|
|
248
|
+
routeTitle: 'menu.nested.group',
|
|
249
|
+
renderType: 'group',
|
|
250
|
+
collapsed: true,
|
|
251
|
+
depth: 2,
|
|
252
|
+
});
|
|
253
|
+
const group = container.querySelector('[role="none"]');
|
|
254
|
+
|
|
255
|
+
expect(group).toHaveAttribute('title', title);
|
|
256
|
+
expect(group).toHaveAttribute('aria-label', title);
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it('should preserve a numeric group name as the native title', () => {
|
|
260
|
+
const { container } = renderMenuTitle({
|
|
261
|
+
title: '0',
|
|
262
|
+
name: 0,
|
|
263
|
+
routeTitle: 'menu.numeric.group',
|
|
264
|
+
renderType: 'group',
|
|
265
|
+
collapsed: true,
|
|
266
|
+
});
|
|
267
|
+
const group = container.querySelector('[role="none"]');
|
|
268
|
+
|
|
269
|
+
expect(group).toHaveAttribute('title', '0');
|
|
270
|
+
expect(group).toHaveAttribute('aria-label', '0');
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it.each(['item', 'group'] as const)(
|
|
274
|
+
'should let an explicit route tooltip own hover behavior for a sider %s',
|
|
275
|
+
(renderType) => {
|
|
276
|
+
const title = 'A menu title with an explicit description';
|
|
277
|
+
const { container } = renderMenuTitle({
|
|
278
|
+
title,
|
|
279
|
+
renderType,
|
|
280
|
+
collapsed: false,
|
|
281
|
+
tooltip: 'An explicitly configured menu description',
|
|
282
|
+
});
|
|
283
|
+
const titleTarget =
|
|
284
|
+
renderType === 'item' ? screen.getByRole('link', { name: title }) : container.querySelector('[role="none"]');
|
|
285
|
+
|
|
286
|
+
expect(titleTarget).not.toHaveAttribute('title');
|
|
287
|
+
expect(screen.getByRole('img', { name: 'question-circle' })).toBeInTheDocument();
|
|
288
|
+
},
|
|
289
|
+
);
|
|
290
|
+
|
|
291
|
+
it('should keep the same menu link when the sider expands', async () => {
|
|
292
|
+
vi.useFakeTimers();
|
|
293
|
+
const title = 'A title that fits after expanding';
|
|
294
|
+
|
|
295
|
+
try {
|
|
296
|
+
const { rerender } = renderMenuTitle({ title, collapsed: true });
|
|
297
|
+
const link = screen.getByRole('link', { name: title });
|
|
298
|
+
|
|
299
|
+
await act(async () => {
|
|
300
|
+
rerender(createMenuTitle({ title, collapsed: false }));
|
|
301
|
+
await vi.runOnlyPendingTimersAsync();
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
expect(screen.getByRole('link', { name: title })).toBe(link);
|
|
305
|
+
expect(link).toHaveAttribute('title', title);
|
|
306
|
+
} finally {
|
|
307
|
+
vi.clearAllTimers();
|
|
308
|
+
vi.useRealTimers();
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
it.each([true, false])(
|
|
313
|
+
'should render one badge indicator for a nested menu title when collapsed is %s',
|
|
314
|
+
(collapsed) => {
|
|
315
|
+
const title = 'A nested menu title with a badge';
|
|
316
|
+
const { container } = renderMenuTitle({ title, collapsed, badgeCount: 7 });
|
|
317
|
+
|
|
318
|
+
expect(container.querySelectorAll('.ant-badge-count')).toHaveLength(1);
|
|
319
|
+
},
|
|
320
|
+
);
|
|
321
|
+
|
|
322
|
+
it('should render one badge indicator for a top-level collapsed menu title', () => {
|
|
323
|
+
const title = 'A top-level collapsed menu title with a badge';
|
|
324
|
+
const { container } = renderMenuTitle({
|
|
325
|
+
title,
|
|
326
|
+
collapsed: true,
|
|
327
|
+
badgeCount: 7,
|
|
328
|
+
badgeTextColor: 'rgb(1, 2, 3)',
|
|
329
|
+
depth: 0,
|
|
330
|
+
});
|
|
331
|
+
const indicator = container.querySelector<HTMLElement>('.ant-badge-count');
|
|
332
|
+
|
|
333
|
+
expect(container.querySelectorAll('.ant-badge-count')).toHaveLength(1);
|
|
334
|
+
expect(indicator).toHaveStyle({ color: 'rgb(1, 2, 3)' });
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
it('should preserve the Ant Design indicator color when collapsed badge textColor is unset', () => {
|
|
338
|
+
const title = 'A top-level collapsed menu title with an indicator color';
|
|
339
|
+
const { container } = renderMenuTitle({
|
|
340
|
+
title,
|
|
341
|
+
collapsed: true,
|
|
342
|
+
badgeCount: 7,
|
|
343
|
+
badgeIndicatorColor: 'rgb(4, 5, 6)',
|
|
344
|
+
depth: 0,
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
expect(container.querySelector('.ant-badge-count')).toHaveStyle({ color: 'rgb(4, 5, 6)' });
|
|
348
|
+
});
|
|
349
|
+
|
|
122
350
|
it('should normalize legacy variables only inside template expressions', () => {
|
|
123
351
|
expect(normalizeAdminLayoutMenuLegacyVariables('https://a.com?id={{ $user.id }}')).toBe(
|
|
124
352
|
'https://a.com?id={{ ctx.user.id }}',
|
|
@@ -34,6 +34,8 @@ const { DateFilterDynamicComponent: DateFilterDynamicComponentLazy } = lazy(
|
|
|
34
34
|
'DateFilterDynamicComponent',
|
|
35
35
|
);
|
|
36
36
|
|
|
37
|
+
const fallbackInputComponents = new Set(['Input', 'Input.URL', 'NanoIDInput', 'DatePicker']);
|
|
38
|
+
|
|
37
39
|
// 简化的本地辅助:按需获取 ctx.collection 的字段树(MetaTreeNode[])
|
|
38
40
|
async function buildCollectionLeftMetaTreeLocal(ctx: any): Promise<MetaTreeNode[]> {
|
|
39
41
|
const resolve = async (sub: any): Promise<MetaTreeNode[]> => {
|
|
@@ -276,9 +278,9 @@ function createStaticInputRenderer(
|
|
|
276
278
|
onChange={(v: unknown) => onChange?.(v as VariableFilterItemValue['value'])}
|
|
277
279
|
/>
|
|
278
280
|
);
|
|
279
|
-
//
|
|
281
|
+
// 未直接处理的 x-component:尝试从 app 解析组件,可由筛选器接管的过渡组件查找失败时静默回退到 Input
|
|
280
282
|
if (xComp && app?.getComponent) {
|
|
281
|
-
const Comp = app.getComponent(xComp
|
|
283
|
+
const Comp = app.getComponent(xComp, !fallbackInputComponents.has(xComp));
|
|
282
284
|
if (Comp) {
|
|
283
285
|
return (
|
|
284
286
|
<Comp
|
|
@@ -595,8 +597,14 @@ export const VariableFilterItem: React.FC<VariableFilterItemProps> = observer(
|
|
|
595
597
|
|
|
596
598
|
const renderRightValueComponent = useCallback(() => {
|
|
597
599
|
// 文本类多关键词:优先使用操作符 schema 声明的组件
|
|
598
|
-
const resolved = resolveOperatorComponent(model.context.app, operator, operatorMetaList);
|
|
599
600
|
const supportKeyword = operator === '$in' || operator === '$notIn';
|
|
601
|
+
const operatorComponent = currentOpMeta?.schema?.['x-component'] as string | undefined;
|
|
602
|
+
const isLocallyRenderedComponent =
|
|
603
|
+
operatorComponent === 'Select' ||
|
|
604
|
+
(typeof operatorComponent === 'string' && fallbackInputComponents.has(operatorComponent));
|
|
605
|
+
const resolved = supportKeyword
|
|
606
|
+
? resolveOperatorComponent(model.context.app, operator, operatorMetaList, !isLocallyRenderedComponent)
|
|
607
|
+
: null;
|
|
600
608
|
if (resolved && supportKeyword) {
|
|
601
609
|
const { Comp, props: xProps } = resolved;
|
|
602
610
|
const nextProps = { ...xProps };
|
|
@@ -642,6 +650,7 @@ export const VariableFilterItem: React.FC<VariableFilterItemProps> = observer(
|
|
|
642
650
|
disabled,
|
|
643
651
|
operator,
|
|
644
652
|
operatorMetaList,
|
|
653
|
+
currentOpMeta,
|
|
645
654
|
rightValue,
|
|
646
655
|
staticInputRenderer,
|
|
647
656
|
model.context.app,
|
|
@@ -47,6 +47,10 @@ vi.mock('@nocobase/flow-engine', async () => {
|
|
|
47
47
|
return { ...actual, VariableInput: MockVariableInput };
|
|
48
48
|
});
|
|
49
49
|
|
|
50
|
+
vi.mock('../../../models/blocks/filter-form/fields/date-time/components/DateFilterDynamicComponent', () => ({
|
|
51
|
+
DateFilterDynamicComponent: () => <div data-testid="date-filter-dynamic-component" />,
|
|
52
|
+
}));
|
|
53
|
+
|
|
50
54
|
const getRenderedSelectTexts = (root: ParentNode = document.body) =>
|
|
51
55
|
Array.from(root.querySelectorAll('.ant-select-selection-item')).map((node) => (node.textContent || '').trim());
|
|
52
56
|
|
|
@@ -158,6 +162,127 @@ describe('VariableFilterItem', () => {
|
|
|
158
162
|
expect(value.value).toBe('abc');
|
|
159
163
|
});
|
|
160
164
|
|
|
165
|
+
it.each([
|
|
166
|
+
{ operator: '$includes', xComponent: 'Input' },
|
|
167
|
+
{ operator: '$eq', xComponent: 'Select' },
|
|
168
|
+
{ operator: '$in', xComponent: 'Select' },
|
|
169
|
+
])('uses a silent app registry lookup for the local $xComponent control', async ({ operator, xComponent }) => {
|
|
170
|
+
const value = observable({ path: '', operator: '', value: '' }) as VariableFilterItemValue;
|
|
171
|
+
const model = CreateModel();
|
|
172
|
+
const app = model.context.app as unknown as ReturnType<typeof createMockFlowApp>;
|
|
173
|
+
const getComponent = vi.spyOn(app, 'getComponent');
|
|
174
|
+
|
|
175
|
+
(globalThis as { __TEST_PATH__?: string }).__TEST_PATH__ = 'status';
|
|
176
|
+
(globalThis as { __TEST_META__?: MetaTreeNode }).__TEST_META__ = {
|
|
177
|
+
interface: 'input',
|
|
178
|
+
uiSchema: {
|
|
179
|
+
'x-component': xComponent,
|
|
180
|
+
enum: [{ label: 'Draft', value: 'draft' }],
|
|
181
|
+
'x-filter-operators': [
|
|
182
|
+
{
|
|
183
|
+
value: operator,
|
|
184
|
+
label: 'Operator',
|
|
185
|
+
selected: true,
|
|
186
|
+
schema: {
|
|
187
|
+
'x-component': xComponent,
|
|
188
|
+
'x-component-props': xComponent === 'Select' ? { mode: operator === '$in' ? 'tags' : null } : {},
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
],
|
|
192
|
+
},
|
|
193
|
+
paths: ['collection', 'status'],
|
|
194
|
+
name: 'status',
|
|
195
|
+
title: 'Status',
|
|
196
|
+
type: 'string',
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
render(<VariableFilterItem value={value} model={model} rightAsVariable={false} />);
|
|
200
|
+
fireEvent.click(screen.getByTestId('variable-input'));
|
|
201
|
+
|
|
202
|
+
await waitFor(() => {
|
|
203
|
+
expect(value.operator).toBe(operator);
|
|
204
|
+
});
|
|
205
|
+
if (xComponent === 'Select' && operator === '$eq') {
|
|
206
|
+
expect(getComponent).not.toHaveBeenCalled();
|
|
207
|
+
} else {
|
|
208
|
+
expect(getComponent).toHaveBeenCalledWith(xComponent, false);
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it('silently handles the DatePicker field schema before the date operator component takes over', async () => {
|
|
213
|
+
const value = observable({ path: '', operator: '', value: '' }) as VariableFilterItemValue;
|
|
214
|
+
const model = CreateModel();
|
|
215
|
+
const app = model.context.app as unknown as ReturnType<typeof createMockFlowApp>;
|
|
216
|
+
const getComponent = vi.spyOn(app, 'getComponent');
|
|
217
|
+
|
|
218
|
+
(globalThis as { __TEST_PATH__?: string }).__TEST_PATH__ = 'createdAt';
|
|
219
|
+
(globalThis as { __TEST_META__?: MetaTreeNode }).__TEST_META__ = {
|
|
220
|
+
interface: 'createdAt',
|
|
221
|
+
uiSchema: {
|
|
222
|
+
'x-component': 'DatePicker',
|
|
223
|
+
'x-filter-operators': [
|
|
224
|
+
{
|
|
225
|
+
value: '$dateOn',
|
|
226
|
+
label: 'Is',
|
|
227
|
+
selected: true,
|
|
228
|
+
schema: {
|
|
229
|
+
'x-component': 'DateFilterDynamicComponent',
|
|
230
|
+
'x-component-props': { isRange: false },
|
|
231
|
+
},
|
|
232
|
+
},
|
|
233
|
+
],
|
|
234
|
+
},
|
|
235
|
+
paths: ['collection', 'createdAt'],
|
|
236
|
+
name: 'createdAt',
|
|
237
|
+
title: 'Created at',
|
|
238
|
+
type: 'date',
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
render(<VariableFilterItem value={value} model={model} rightAsVariable={false} />);
|
|
242
|
+
fireEvent.click(screen.getByTestId('variable-input'));
|
|
243
|
+
|
|
244
|
+
await waitFor(() => {
|
|
245
|
+
expect(value.operator).toBe('$dateOn');
|
|
246
|
+
});
|
|
247
|
+
expect(getComponent).toHaveBeenCalledWith('DatePicker', false);
|
|
248
|
+
expect(await screen.findByTestId('date-filter-dynamic-component')).toBeInTheDocument();
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
it('continues resolving plugin-provided keyword controls from the app registry', async () => {
|
|
252
|
+
const value = observable({ path: '', operator: '', value: '' }) as VariableFilterItemValue;
|
|
253
|
+
const model = CreateModel();
|
|
254
|
+
const app = model.context.app as unknown as ReturnType<typeof createMockFlowApp>;
|
|
255
|
+
const MultipleKeywordsInput: React.FC = () => <div data-testid="multiple-keywords-input" />;
|
|
256
|
+
app.addComponents({ MultipleKeywordsInput });
|
|
257
|
+
const getComponent = vi.spyOn(app, 'getComponent');
|
|
258
|
+
|
|
259
|
+
(globalThis as { __TEST_PATH__?: string }).__TEST_PATH__ = 'name';
|
|
260
|
+
(globalThis as { __TEST_META__?: MetaTreeNode }).__TEST_META__ = {
|
|
261
|
+
interface: 'input',
|
|
262
|
+
uiSchema: {
|
|
263
|
+
'x-component': 'Input',
|
|
264
|
+
'x-filter-operators': [
|
|
265
|
+
{
|
|
266
|
+
value: '$in',
|
|
267
|
+
label: 'Is any of',
|
|
268
|
+
selected: true,
|
|
269
|
+
schema: { 'x-component': 'MultipleKeywordsInput' },
|
|
270
|
+
},
|
|
271
|
+
],
|
|
272
|
+
},
|
|
273
|
+
paths: ['collection', 'name'],
|
|
274
|
+
name: 'name',
|
|
275
|
+
title: 'Name',
|
|
276
|
+
type: 'string',
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
render(<VariableFilterItem value={value} model={model} rightAsVariable={false} />);
|
|
280
|
+
fireEvent.click(screen.getByTestId('variable-input'));
|
|
281
|
+
|
|
282
|
+
expect(await screen.findByTestId('multiple-keywords-input')).toBeTruthy();
|
|
283
|
+
expect(getComponent).toHaveBeenCalledWith('MultipleKeywordsInput');
|
|
284
|
+
});
|
|
285
|
+
|
|
161
286
|
it('passes disabled through to the left selector, operator select, and right variable input', async () => {
|
|
162
287
|
const value: VariableFilterItemValue = { path: '', operator: '', value: '' };
|
|
163
288
|
const model = CreateModel();
|