@nocobase/client-v2 2.2.0-beta.9 → 2.2.0

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.
Files changed (224) hide show
  1. package/es/APIClient.d.ts +13 -3
  2. package/es/BaseApplication.d.ts +1 -0
  3. package/es/collection-field-interface/CollectionFieldInterface.d.ts +1 -0
  4. package/es/collection-field-interface/CollectionFieldInterfaceManager.d.ts +1 -0
  5. package/es/components/category-tabs/SortableCategoryTabs.d.ts +55 -0
  6. package/es/components/category-tabs/index.d.ts +9 -0
  7. package/es/components/form/ScanInput/useCodeScanner.d.ts +3 -2
  8. package/es/components/form/TypedVariableInput.d.ts +31 -5
  9. package/es/components/form/filter/CollectionFilter.d.ts +2 -0
  10. package/es/components/form/filter/CollectionFilterItem.d.ts +11 -1
  11. package/es/components/form/filter/CollectionFilterPanel.d.ts +2 -0
  12. package/es/components/form/filter/index.d.ts +2 -0
  13. package/es/components/form/filter/useFilterActionProps.d.ts +2 -0
  14. package/es/components/index.d.ts +1 -0
  15. package/es/flow/actions/index.d.ts +1 -1
  16. package/es/flow/actions/linkageRules.d.ts +27 -0
  17. package/es/flow/admin-shell/admin-layout/AdminLayoutMenuModels.d.ts +1 -0
  18. package/es/flow/components/FieldAssignExactDatePicker.d.ts +1 -0
  19. package/es/flow/components/FieldAssignValueInput.d.ts +7 -24
  20. package/es/flow/components/FlowRoute.d.ts +2 -2
  21. package/es/flow/components/RunJSValueEditor.d.ts +1 -0
  22. package/es/flow/components/field-value-variable/DateVariableEditor.d.ts +24 -0
  23. package/es/flow/components/field-value-variable/FieldValueVariableInput.d.ts +31 -0
  24. package/es/flow/components/field-value-variable/dateValue.d.ts +36 -0
  25. package/es/flow/components/field-value-variable/index.d.ts +11 -0
  26. package/es/flow/components/filter/FilterGroup.d.ts +1 -0
  27. package/es/flow/components/filter/VariableFilterItem.d.ts +6 -1
  28. package/es/flow/components/placeholders/BlockPlaceholder.d.ts +1 -0
  29. package/es/flow/index.d.ts +1 -0
  30. package/es/flow/internal/registerDeviceTypeContext.d.ts +10 -0
  31. package/es/flow/internal/utils/operatorSchemaHelper.d.ts +2 -2
  32. package/es/flow/models/actions/UpdateRecordActionUtils.d.ts +8 -2
  33. package/es/flow/models/base/ActionModelCore.d.ts +4 -2
  34. package/es/flow/models/base/BlockGridModel.d.ts +3 -0
  35. package/es/flow/models/base/CollectionBlockModel.d.ts +3 -0
  36. package/es/flow/models/base/PageModel/PageModel.d.ts +12 -0
  37. package/es/flow/models/base/PageModel/PageModelTabBar.d.ts +22 -0
  38. package/es/flow/models/base/PageModel/PageTabModel.d.ts +12 -0
  39. package/es/flow/models/blocks/details/DetailsBlockModel.d.ts +3 -0
  40. package/es/flow/models/blocks/filter-form/FilterFormGridModel.d.ts +1 -0
  41. package/es/flow/models/blocks/filter-form/FilterFormSubmitActionModel.d.ts +3 -1
  42. package/es/flow/models/blocks/form/FormBlockModel.d.ts +7 -0
  43. package/es/flow/models/blocks/form/FormGridModel.d.ts +6 -0
  44. package/es/flow/models/blocks/form/QuickEditFormModel.d.ts +17 -2
  45. package/es/flow/models/blocks/form/value-runtime/rules.d.ts +1 -0
  46. package/es/flow/models/blocks/table/JSColumnModel.d.ts +2 -0
  47. package/es/flow/models/blocks/table/TableBlockModel.d.ts +1 -0
  48. package/es/flow/models/blocks/table/TableColumnModel.d.ts +12 -0
  49. package/es/flow/models/blocks/table/utils.d.ts +1 -0
  50. package/es/flow/models/fields/AssociationFieldModel/RecordPickerFieldModel.d.ts +2 -1
  51. package/es/flow/models/fields/AssociationFieldModel/RecordSelectFieldModel.d.ts +0 -17
  52. package/es/flow/models/fields/AssociationFieldModel/recordSelectShared.d.ts +41 -0
  53. package/es/flow/models/fields/DateTimeFieldModel/dateLimit.d.ts +15 -7
  54. package/es/flow-compat/fieldValidationConstants.d.ts +1 -1
  55. package/es/flow-compat/passwordUtils.d.ts +1 -1
  56. package/es/flow-compat/routeTypes.d.ts +1 -0
  57. package/es/index.d.ts +5 -0
  58. package/es/index.mjs +199 -161
  59. package/es/ui-operation/index.d.ts +15 -0
  60. package/es/ui-operation/ui-operation-codec.d.ts +10 -0
  61. package/es/utils/getRouteRuntimeVersion.d.ts +23 -0
  62. package/es/utils/index.d.ts +1 -0
  63. package/lib/index.js +215 -177
  64. package/lib/locale/languageCodes.js +3 -1
  65. package/package.json +9 -7
  66. package/src/APIClient.ts +90 -7
  67. package/src/Application.tsx +7 -1
  68. package/src/BaseApplication.tsx +11 -6
  69. package/src/__tests__/APIClient.test.tsx +58 -0
  70. package/src/__tests__/app.test.tsx +73 -0
  71. package/src/__tests__/browserChecker.test.ts +61 -0
  72. package/src/__tests__/getRouteRuntimeVersion.test.ts +68 -0
  73. package/src/__tests__/nocobase-buildin-plugin-auth.test.tsx +35 -2
  74. package/src/__tests__/settings-center.test.tsx +270 -6
  75. package/src/acl/ACLProvider.tsx +2 -0
  76. package/src/acl/__tests__/ACLProvider.test.tsx +92 -0
  77. package/src/collection-field-interface/CollectionFieldInterface.ts +1 -0
  78. package/src/collection-field-interface/CollectionFieldInterfaceManager.ts +1 -0
  79. package/src/collection-manager/field-validation.ts +1 -1
  80. package/src/components/README.md +7 -1
  81. package/src/components/README.zh-CN.md +6 -1
  82. package/src/components/category-tabs/SortableCategoryTabs.tsx +210 -0
  83. package/src/components/category-tabs/index.ts +10 -0
  84. package/src/components/form/JsonTextArea.tsx +4 -0
  85. package/src/components/form/ScanInput/CodeScanner.tsx +79 -35
  86. package/src/components/form/ScanInput/__tests__/CodeScanner.test.tsx +101 -0
  87. package/src/components/form/ScanInput/__tests__/useCodeScanner.test.tsx +284 -11
  88. package/src/components/form/ScanInput/useCodeScanner.ts +332 -24
  89. package/src/components/form/TypedVariableInput.tsx +452 -101
  90. package/src/components/form/__tests__/TypedVariableInput.test.tsx +364 -12
  91. package/src/components/form/filter/CollectionFilter.tsx +4 -0
  92. package/src/components/form/filter/CollectionFilterItem.tsx +36 -9
  93. package/src/components/form/filter/CollectionFilterPanel.tsx +4 -0
  94. package/src/components/form/filter/__tests__/CollectionFilterItem.test.tsx +55 -0
  95. package/src/components/form/filter/__tests__/useFilterActionProps.test.tsx +95 -0
  96. package/src/components/form/filter/index.ts +2 -0
  97. package/src/components/form/filter/useFilterActionProps.ts +37 -6
  98. package/src/components/form/table/Table.tsx +81 -6
  99. package/src/components/form/table/__tests__/Table.columnWidth.test.tsx +433 -0
  100. package/src/components/index.ts +1 -0
  101. package/src/flow/FlowPage.tsx +9 -1
  102. package/src/flow/__tests__/FlowPage.test.tsx +50 -3
  103. package/src/flow/__tests__/FlowRoute.test.tsx +128 -10
  104. package/src/flow/__tests__/PluginFlowEngine.test.ts +58 -0
  105. package/src/flow/actions/__tests__/actionLinkageRules.forkProps.test.ts +314 -0
  106. package/src/flow/actions/__tests__/dataScopeFormValueClear.test.ts +102 -0
  107. package/src/flow/actions/__tests__/linkageRules.actionStates.test.ts +33 -0
  108. package/src/flow/actions/__tests__/linkageRules.subFormSetFieldProps.test.ts +72 -0
  109. package/src/flow/actions/__tests__/linkageRules.tab.test.ts +171 -0
  110. package/src/flow/actions/__tests__/linkageRulesRefresh.test.ts +7 -3
  111. package/src/flow/actions/index.ts +2 -0
  112. package/src/flow/actions/linkageRules.tsx +144 -26
  113. package/src/flow/actions/linkageRulesRefresh.tsx +2 -6
  114. package/src/flow/admin-shell/admin-layout/AdminLayoutComponent.tsx +0 -1
  115. package/src/flow/admin-shell/admin-layout/AdminLayoutMenuUtils.tsx +78 -59
  116. package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutComponent.test.tsx +253 -6
  117. package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutMenuModels.test.ts +228 -0
  118. package/src/flow/common/Markdown/style.ts +4 -0
  119. package/src/flow/components/BlockItemCard.tsx +2 -2
  120. package/src/flow/components/FieldAssignExactDatePicker.tsx +25 -11
  121. package/src/flow/components/FieldAssignValueInput.tsx +72 -584
  122. package/src/flow/components/FlowRoute.tsx +78 -32
  123. package/src/flow/components/RunJSValueEditor.tsx +9 -1
  124. package/src/flow/components/__tests__/FieldAssignValueInput.context.test.tsx +216 -0
  125. package/src/flow/components/field-value-variable/DateVariableEditor.tsx +181 -0
  126. package/src/flow/components/field-value-variable/FieldValueVariableInput.tsx +326 -0
  127. package/src/flow/components/field-value-variable/__tests__/FieldValueVariableInput.test.tsx +380 -0
  128. package/src/flow/components/field-value-variable/dateValue.ts +223 -0
  129. package/src/flow/components/field-value-variable/index.ts +12 -0
  130. package/src/flow/components/filter/FilterGroup.tsx +33 -5
  131. package/src/flow/components/filter/VariableFilterItem.tsx +170 -13
  132. package/src/flow/components/filter/__tests__/FilterGroup.test.tsx +45 -0
  133. package/src/flow/components/filter/__tests__/VariableFilterItem.leftMetaTree.test.tsx +9 -0
  134. package/src/flow/components/filter/__tests__/VariableFilterItem.test.tsx +195 -1
  135. package/src/flow/components/placeholders/BlockPlaceholder.tsx +70 -23
  136. package/src/flow/components/placeholders/__tests__/BlockPlaceholder.test.tsx +57 -7
  137. package/src/flow/index.ts +3 -0
  138. package/src/flow/internal/registerDeviceTypeContext.ts +39 -0
  139. package/src/flow/internal/utils/operatorSchemaHelper.ts +3 -2
  140. package/src/flow/models/actions/UpdateRecordActionModel.tsx +18 -1
  141. package/src/flow/models/actions/UpdateRecordActionUtils.ts +18 -6
  142. package/src/flow/models/actions/__tests__/UpdateRecordActionModel.test.ts +76 -4
  143. package/src/flow/models/base/ActionModelCore.tsx +11 -2
  144. package/src/flow/models/base/BlockGridModel.tsx +26 -0
  145. package/src/flow/models/base/CollectionBlockModel.tsx +38 -3
  146. package/src/flow/models/base/PageModel/PageModel.tsx +387 -53
  147. package/src/flow/models/base/PageModel/PageModelTabBar.tsx +114 -0
  148. package/src/flow/models/base/PageModel/PageTabModel.tsx +249 -18
  149. package/src/flow/models/base/PageModel/__tests__/PageModel.test.ts +790 -10
  150. package/src/flow/models/base/PageModel/__tests__/PageModelTabBar.module-isolation.test.tsx +130 -0
  151. package/src/flow/models/base/PageModel/__tests__/PageModelTabBar.test.tsx +118 -0
  152. package/src/flow/models/base/PageModel/__tests__/PageTabModel.test.ts +1075 -7
  153. package/src/flow/models/base/__tests__/ActionModelCore.render.test.tsx +49 -0
  154. package/src/flow/models/base/__tests__/BlockGridModel.selectSceneActivation.test.ts +124 -0
  155. package/src/flow/models/base/__tests__/CollectionBlockModel.addAppends.test.ts +41 -0
  156. package/src/flow/models/base/__tests__/CollectionBlockModel.initialBeforeRenderRefresh.test.ts +125 -9
  157. package/src/flow/models/blocks/assign-form/AssignFormItemModel.tsx +28 -53
  158. package/src/flow/models/blocks/details/DetailsBlockModel.tsx +8 -3
  159. package/src/flow/models/blocks/details/__tests__/DetailsBlockModel.initialPaginationChangeRefresh.test.ts +32 -1
  160. package/src/flow/models/blocks/filter-form/FilterFormBlockModel.tsx +28 -3
  161. package/src/flow/models/blocks/filter-form/FilterFormGridModel.tsx +36 -5
  162. package/src/flow/models/blocks/filter-form/FilterFormItemModel.tsx +155 -25
  163. package/src/flow/models/blocks/filter-form/FilterFormSubmitActionModel.tsx +57 -4
  164. package/src/flow/models/blocks/filter-form/__tests__/FilterFormGridModel.onModelCreated.test.ts +174 -1
  165. package/src/flow/models/blocks/filter-form/__tests__/FilterFormItemModel.defineChildren.test.ts +395 -1
  166. package/src/flow/models/blocks/filter-form/__tests__/FilterFormItemModel.getFilterValue.test.ts +72 -0
  167. package/src/flow/models/blocks/filter-form/__tests__/FilterFormSubmitActionModel.lifecycle.test.ts +90 -0
  168. package/src/flow/models/blocks/filter-form/__tests__/defaultValues.wiring.test.ts +66 -4
  169. package/src/flow/models/blocks/filter-manager/FilterManager.ts +5 -0
  170. package/src/flow/models/blocks/filter-manager/__tests__/FilterManager.test.ts +40 -0
  171. package/src/flow/models/blocks/form/FormBlockModel.tsx +47 -0
  172. package/src/flow/models/blocks/form/FormGridModel.tsx +4 -0
  173. package/src/flow/models/blocks/form/QuickEditFormModel.tsx +189 -36
  174. package/src/flow/models/blocks/form/__tests__/FormBlockModel.test.tsx +8 -2
  175. package/src/flow/models/blocks/form/__tests__/QuickEditFormModel.quickEdit.test.ts +350 -2
  176. package/src/flow/models/blocks/form/__tests__/runJsFormSubmit.test.ts +131 -0
  177. package/src/flow/models/blocks/form/value-runtime/__tests__/runtime.test.ts +435 -0
  178. package/src/flow/models/blocks/form/value-runtime/rules.ts +67 -14
  179. package/src/flow/models/blocks/form/value-runtime/runtime.ts +43 -19
  180. package/src/flow/models/blocks/js-block/JSBlock.tsx +1 -1
  181. package/src/flow/models/blocks/table/JSColumnModel.tsx +10 -1
  182. package/src/flow/models/blocks/table/TableActionsColumnModel.tsx +2 -1
  183. package/src/flow/models/blocks/table/TableBlockModel.tsx +29 -3
  184. package/src/flow/models/blocks/table/TableColumnModel.tsx +48 -9
  185. package/src/flow/models/blocks/table/__tests__/JSColumnModel.test.tsx +52 -5
  186. package/src/flow/models/blocks/table/__tests__/TableBlockModel.filterReset.test.ts +78 -0
  187. package/src/flow/models/blocks/table/__tests__/TableBlockModel.quickEditRefresh.test.ts +12 -0
  188. package/src/flow/models/blocks/table/__tests__/TableColumnModel.test.tsx +33 -0
  189. package/src/flow/models/blocks/table/utils.ts +7 -0
  190. package/src/flow/models/fields/AssociationFieldModel/CascadeSelectFieldModel.tsx +33 -1
  191. package/src/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/PopupSubTableFieldModel.tsx +10 -1
  192. package/src/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/__tests__/popupContext.test.ts +120 -0
  193. package/src/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/actions/PopupSubTableEditActionModel.tsx +10 -2
  194. package/src/flow/models/fields/AssociationFieldModel/RecordPickerFieldModel.tsx +24 -1
  195. package/src/flow/models/fields/AssociationFieldModel/RecordSelectFieldModel.tsx +9 -136
  196. package/src/flow/models/fields/AssociationFieldModel/__tests__/RecordPickerFieldModel.itemContext.test.ts +167 -3
  197. package/src/flow/models/fields/AssociationFieldModel/recordSelectShared.tsx +156 -0
  198. package/src/flow/models/fields/DateTimeFieldModel/__tests__/DateTimeNoTzFieldModel.dateLimit.test.tsx +149 -0
  199. package/src/flow/models/fields/DateTimeFieldModel/dateLimit.ts +149 -113
  200. package/src/flow/models/fields/DisplayNumberFieldModel.tsx +1 -1
  201. package/src/flow/models/fields/JsonFieldModel.tsx +31 -8
  202. package/src/flow/models/fields/NumberFieldModel.tsx +1 -1
  203. package/src/flow/models/fields/VariableFieldFormModel.tsx +3 -3
  204. package/src/flow/models/fields/__tests__/DisplayNumberFieldModel.test.ts +33 -0
  205. package/src/flow/models/fields/__tests__/JsonFieldModel.test.ts +82 -0
  206. package/src/flow/models/fields/__tests__/NumberFieldModel.test.tsx +47 -0
  207. package/src/flow/models/fields/__tests__/VariableFieldFormModel.test.tsx +51 -0
  208. package/src/flow/models/fields/mobile-components/MobileLazySelect.tsx +26 -10
  209. package/src/flow/models/fields/mobile-components/MobileSelect.tsx +51 -14
  210. package/src/flow/models/fields/mobile-components/__tests__/MobileSelect.test.tsx +139 -13
  211. package/src/flow/utils/dataScopeFormValueClear.ts +4 -3
  212. package/src/flow-compat/fieldValidationConstants.ts +1 -1
  213. package/src/flow-compat/routeTypes.ts +1 -0
  214. package/src/index.ts +5 -0
  215. package/src/layout-manager/LayoutContentRoute.tsx +2 -1
  216. package/src/layout-manager/LayoutRoute.tsx +2 -1
  217. package/src/layout-manager/__tests__/LayoutRoute.test.tsx +87 -1
  218. package/src/locale/languageCodes.ts +3 -1
  219. package/src/nocobase-buildin-plugin/index.tsx +12 -0
  220. package/src/settings-center/AdminSettingsLayout.tsx +23 -2
  221. package/src/ui-operation/index.ts +33 -0
  222. package/src/ui-operation/ui-operation-codec.ts +54 -0
  223. package/src/utils/getRouteRuntimeVersion.ts +185 -0
  224. package/src/utils/index.tsx +1 -0
@@ -0,0 +1,95 @@
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, FlowEngineProvider, type Collection } from '@nocobase/flow-engine';
11
+ import { renderHook } from '@testing-library/react';
12
+ import React from 'react';
13
+ import { describe, expect, it, vi } from 'vitest';
14
+ import { useFilterActionProps } from '../useFilterActionProps';
15
+
16
+ vi.mock('../../../flow/components/filter/useFilterOptions', () => ({
17
+ useFilterOptions: () => [],
18
+ }));
19
+
20
+ vi.mock('../CollectionFilterItem', () => ({
21
+ createCollectionFilterItem: () => undefined,
22
+ }));
23
+
24
+ function makeCollection(): Collection {
25
+ return {
26
+ getFields: () => [{ name: 'title' }, { name: 'type' }],
27
+ } as unknown as Collection;
28
+ }
29
+
30
+ function makeWrapper() {
31
+ const engine = new FlowEngine();
32
+ const Wrapper: React.FC = ({ children }) => <FlowEngineProvider engine={engine}>{children}</FlowEngineProvider>;
33
+ return Wrapper;
34
+ }
35
+
36
+ describe('useFilterActionProps', () => {
37
+ it('seeds the editable group from defaultValue when initialValue is missing', () => {
38
+ const { result } = renderHook(
39
+ () =>
40
+ useFilterActionProps({
41
+ collection: makeCollection(),
42
+ defaultValue: { $and: [{ title: { $includes: '' } }, { type: { $eq: undefined } }] },
43
+ onApply: () => undefined,
44
+ }),
45
+ { wrapper: makeWrapper() },
46
+ );
47
+
48
+ expect(result.current.value).toMatchObject({
49
+ logic: '$and',
50
+ items: [
51
+ { path: 'title', operator: '$includes', value: '' },
52
+ { path: 'type', operator: '$eq', value: undefined },
53
+ ],
54
+ });
55
+ });
56
+
57
+ it('reset restores defaultValue and emits its compiled filter', () => {
58
+ const onApply = vi.fn();
59
+ const { result } = renderHook(
60
+ () =>
61
+ useFilterActionProps({
62
+ collection: makeCollection(),
63
+ defaultValue: { $and: [{ title: { $includes: '' } }, { type: { $eq: undefined } }] },
64
+ initialValue: { $and: [{ title: { $includes: 'abc' } }] },
65
+ onApply,
66
+ }),
67
+ { wrapper: makeWrapper() },
68
+ );
69
+
70
+ result.current.onReset();
71
+
72
+ expect(result.current.value).toMatchObject({
73
+ logic: '$and',
74
+ items: [
75
+ { path: 'title', operator: '$includes', value: '' },
76
+ { path: 'type', operator: '$eq', value: undefined },
77
+ ],
78
+ });
79
+ expect(onApply).toHaveBeenCalledWith(undefined, 'reset');
80
+ });
81
+
82
+ it('counts only effective compiled conditions, so empty default rows do not highlight the button', () => {
83
+ const { result } = renderHook(
84
+ () =>
85
+ useFilterActionProps({
86
+ collection: makeCollection(),
87
+ defaultValue: { $and: [{ title: { $includes: '' } }, { type: { $eq: undefined } }] },
88
+ onApply: () => undefined,
89
+ }),
90
+ { wrapper: makeWrapper() },
91
+ );
92
+
93
+ expect(result.current.conditionCount).toBe(0);
94
+ });
95
+ });
@@ -11,5 +11,7 @@
11
11
  export { CollectionFilter } from './CollectionFilter';
12
12
  export type { CollectionFilterProps } from './CollectionFilter';
13
13
  export { CollectionFilterPanel } from './CollectionFilterPanel';
14
+ export { CollectionFilterItem } from './CollectionFilterItem';
15
+ export type { CollectionFilterItemValue } from './CollectionFilterItem';
14
16
  export type { CollectionFilterPanelProps, CollectionFilterPanelRef } from './CollectionFilterPanel';
15
17
  export type { CompiledFilter } from './useFilterActionProps';
@@ -43,6 +43,14 @@ const isCondition = (item: FilterGroupItem): item is CollectionFilterItemValue =
43
43
  typeof (item as CollectionFilterItemValue).path === 'string' &&
44
44
  Object.prototype.hasOwnProperty.call(item, 'operator');
45
45
 
46
+ const cloneFilterGroupItem = (item: FilterGroupItem): FilterGroupItem =>
47
+ isGroup(item) ? { logic: item.logic, items: item.items.map((child) => cloneFilterGroupItem(child)) } : { ...item };
48
+
49
+ const cloneFilterGroup = (group: FilterGroupValue): FilterGroupValue => ({
50
+ logic: group.logic,
51
+ items: group.items.map((item) => cloneFilterGroupItem(item)),
52
+ });
53
+
46
54
  /**
47
55
  * `true` when the rhs of a condition is "no real value yet" — covers `undefined` / `null` / empty string / empty array / empty plain object. Mirrors v1's `removeNullCondition` `isEmpty` predicate so half-filled rows ("Locked time → is → (no date picked yet)") get dropped on Submit instead of being sent to the server as `{lockedTs:{}}` and triggering a 500.
48
56
  */
@@ -164,6 +172,8 @@ export interface UseFilterActionPropsArgs extends UseFilterOptionsArgs {
164
172
  collection: Collection | undefined;
165
173
  /** Previously compiled filter param used to seed the editable filter group. */
166
174
  initialValue?: CompiledFilter;
175
+ /** Default compiled filter used both for initial empty state and Reset. */
176
+ defaultValue?: CompiledFilter;
167
177
  /**
168
178
  * Called when the user submits or resets the filter popover. Receives the compiled filter param (`undefined` when cleared) and which footer button triggered the call. Typical implementation: `(filter, action) => { listRequest.run(filter); if (action === 'submit') closePopover(); }`.
169
179
  */
@@ -216,12 +226,23 @@ export interface UseFilterActionPropsResult {
216
226
  * ```
217
227
  */
218
228
  export function useFilterActionProps(args: UseFilterActionPropsArgs): UseFilterActionPropsResult {
219
- const { collection, initialValue, onApply, filterableFieldNames, nonfilterableFieldNames, noIgnore, t } = args;
229
+ const {
230
+ collection,
231
+ initialValue,
232
+ defaultValue,
233
+ onApply,
234
+ filterableFieldNames,
235
+ nonfilterableFieldNames,
236
+ noIgnore,
237
+ t,
238
+ } = args;
239
+ const seedValue = initialValue ?? defaultValue;
240
+ const defaultGroup = decompileFilterGroup(defaultValue) || createEmptyGroup();
220
241
 
221
242
  // Held in a ref so the group object identity is stable for the lifetime of the host component — `<FilterContent>` mutates this object directly (push/splice on `items`, swap `logic`), and a fresh observable on every render would reset that internal state.
222
243
  const valueRef = useRef<FilterGroupValue>();
223
244
  if (!valueRef.current) {
224
- valueRef.current = observable(decompileFilterGroup(initialValue) || createEmptyGroup()) as FilterGroupValue;
245
+ valueRef.current = observable(decompileFilterGroup(seedValue) || createEmptyGroup()) as FilterGroupValue;
225
246
  }
226
247
  const value = valueRef.current;
227
248
 
@@ -240,9 +261,10 @@ export function useFilterActionProps(args: UseFilterActionPropsArgs): UseFilterA
240
261
  });
241
262
 
242
263
  const onReset = useMemoizedFn(() => {
243
- value.logic = '$and';
244
- value.items = [];
245
- onApply(undefined, 'reset');
264
+ const next = cloneFilterGroup(defaultGroup);
265
+ value.logic = next.logic;
266
+ value.items = next.items;
267
+ onApply(compileFilterGroup(value), 'reset');
246
268
  });
247
269
 
248
270
  const translate = useMemoizedFn((key: string) => (t ? t(key) : key));
@@ -261,7 +283,16 @@ export function useFilterActionProps(args: UseFilterActionPropsArgs): UseFilterA
261
283
  );
262
284
 
263
285
  // Re-read on each render so `observer`-wrapped hosts re-render when the reactive `items` array length changes. No useMemo needed — the `value` object's identity is stable (held in a ref), but its observable `items.length` is what we actually care about, and the eslint exhaustive-deps rule rightly complains about depending on a mutable property of a stable ref.
264
- const conditionCount = value.items.length;
286
+ const conditionCount = (() => {
287
+ const compiled = compileFilterGroup(value);
288
+ if (compiled?.$and && Array.isArray(compiled.$and)) {
289
+ return compiled.$and.length;
290
+ }
291
+ if (compiled?.$or && Array.isArray(compiled.$or)) {
292
+ return compiled.$or.length;
293
+ }
294
+ return 0;
295
+ })();
265
296
 
266
297
  return { value, options, FilterItem, ctx, onSubmit, onReset, conditionCount };
267
298
  }
@@ -9,11 +9,11 @@
9
9
 
10
10
  import { DragOverlay, type DragEndEvent, type DragStartEvent } from '@dnd-kit/core';
11
11
  import { SortableContext, verticalListSortingStrategy } from '@dnd-kit/sortable';
12
- import { cx } from '@emotion/css';
12
+ import { css, cx, injectGlobal } from '@emotion/css';
13
13
  import { DndProvider } from '@nocobase/flow-engine';
14
14
  import { useMemoizedFn } from 'ahooks';
15
- import { Table as AntdTable, type TableProps as AntdTableProps } from 'antd';
16
- import type { ColumnsType, ColumnType, GetRowKey } from 'antd/es/table/interface';
15
+ import { Table as AntdTable, theme, type TableProps as AntdTableProps } from 'antd';
16
+ import type { ColumnsType, ColumnGroupType, ColumnType, GetRowKey } from 'antd/es/table/interface';
17
17
  import type { RenderedCell } from 'rc-table/lib/interface';
18
18
  import React, { useMemo, useState } from 'react';
19
19
  import { SortableRow, SortHandle } from './dnd/SortableRow';
@@ -24,6 +24,20 @@ import { readRowKey, snapshotSourceRow, type RowKey, type RowSnapshot } from './
24
24
 
25
25
  type RowSelectionRenderCellResult<RecordType> = React.ReactNode | RenderedCell<RecordType>;
26
26
 
27
+ const DEFAULT_COLUMN_CONTENT_CLASS_NAME = 'nb-table-default-column-content';
28
+ const DEFAULT_COLUMN_CONTENT_MAX_WIDTH_PROPERTY = '--nb-table-default-column-content-max-width';
29
+
30
+ // Zero specificity lets caller classes remain authoritative regardless of stylesheet insertion order. The max-width
31
+ // value itself comes from a token-derived private CSS variable set by each Table instance.
32
+ injectGlobal`
33
+ :where(.${DEFAULT_COLUMN_CONTENT_CLASS_NAME}) {
34
+ max-width: var(${DEFAULT_COLUMN_CONTENT_MAX_WIDTH_PROPERTY});
35
+ white-space: normal;
36
+ overflow-wrap: anywhere;
37
+ word-break: break-word;
38
+ }
39
+ `;
40
+
27
41
  /**
28
42
  * Default initial page size for `Table`. Exposed so consumers can seed their
29
43
  * controlled `pageSize` state with the same value the component would use if
@@ -50,6 +64,54 @@ function isRenderedCell<RecordType>(value: unknown): value is RenderedCell<Recor
50
64
  return typeof value === 'object' && value !== null && !React.isValidElement(value) && 'children' in value;
51
65
  }
52
66
 
67
+ function isColumnGroup<RecordType>(
68
+ column: ColumnGroupType<RecordType> | ColumnType<RecordType>,
69
+ ): column is ColumnGroupType<RecordType> {
70
+ return 'children' in column && Array.isArray(column.children) && column.children.length > 0;
71
+ }
72
+
73
+ function addDefaultColumnContentClassName<RecordType>(
74
+ columns: ColumnsType<RecordType>,
75
+ defaultClassName: string,
76
+ ): ColumnsType<RecordType> {
77
+ return columns.map((column) => {
78
+ if (column === AntdTable.EXPAND_COLUMN || column === AntdTable.SELECTION_COLUMN) {
79
+ return column;
80
+ }
81
+
82
+ if (isColumnGroup(column)) {
83
+ return {
84
+ ...column,
85
+ children: addDefaultColumnContentClassName(column.children, defaultClassName),
86
+ };
87
+ }
88
+
89
+ if (column.width !== undefined || column.ellipsis || column.fixed) {
90
+ return column;
91
+ }
92
+
93
+ const originalOnCell = column.onCell;
94
+ const originalOnHeaderCell = column.onHeaderCell;
95
+ return {
96
+ ...column,
97
+ onCell: (record, index) => {
98
+ const cellProps = originalOnCell?.(record, index) ?? {};
99
+ return {
100
+ ...cellProps,
101
+ className: cx(defaultClassName, cellProps.className),
102
+ };
103
+ },
104
+ onHeaderCell: (headerColumn) => {
105
+ const cellProps = originalOnHeaderCell?.(headerColumn) ?? {};
106
+ return {
107
+ ...cellProps,
108
+ className: cx(defaultClassName, cellProps.className),
109
+ };
110
+ },
111
+ };
112
+ });
113
+ }
114
+
53
115
  export interface TableProps<RecordType extends object = any> extends AntdTableProps<RecordType> {
54
116
  /**
55
117
  * Required so drag-sort, hover-swap and row identity work. Accepts the same
@@ -108,6 +170,7 @@ export interface TableProps<RecordType extends object = any> extends AntdTablePr
108
170
  * plus the index swap, so it is safe as the default table on any page.
109
171
  */
110
172
  export function Table<RecordType extends object = any>(props: TableProps<RecordType>) {
173
+ const { token } = theme.useToken();
111
174
  const {
112
175
  rowKey,
113
176
  showIndex = true,
@@ -143,6 +206,17 @@ export function Table<RecordType extends object = any>(props: TableProps<RecordT
143
206
  const showHandleInSelection = isDraggable && showSortHandle && !!rowSelection;
144
207
  const showStandaloneHandleColumn = isDraggable && showSortHandle && !rowSelection;
145
208
 
209
+ const defaultColumnContentClassName = useMemo(
210
+ () =>
211
+ cx(
212
+ DEFAULT_COLUMN_CONTENT_CLASS_NAME,
213
+ css`
214
+ ${DEFAULT_COLUMN_CONTENT_MAX_WIDTH_PROPERTY}: ${token.screenXS - token.paddingXL * 3 + token.padding * 2}px;
215
+ `,
216
+ ),
217
+ [token.padding, token.paddingXL, token.screenXS],
218
+ );
219
+
146
220
  const itemKeys = useMemo<string[]>(() => {
147
221
  if (!isDraggable || !dataSource) return [];
148
222
  return dataSource
@@ -191,15 +265,16 @@ export function Table<RecordType extends object = any>(props: TableProps<RecordT
191
265
  // selection cell — see `augmentedRowSelection` below.
192
266
  const augmentedColumns = useMemo<ColumnsType<RecordType>>(() => {
193
267
  const baseColumns: ColumnsType<RecordType> = columns ?? [];
194
- if (!showStandaloneHandleColumn) return baseColumns;
268
+ const styledColumns = addDefaultColumnContentClassName(baseColumns, defaultColumnContentClassName);
269
+ if (!showStandaloneHandleColumn) return styledColumns;
195
270
  const handleColumn: ColumnType<RecordType> = {
196
271
  key: '__sort__',
197
272
  width: sortHandleColumnWidth,
198
273
  align: 'center',
199
274
  render: () => <SortHandle />,
200
275
  };
201
- return [handleColumn, ...baseColumns];
202
- }, [columns, showStandaloneHandleColumn, sortHandleColumnWidth]);
276
+ return [handleColumn, ...styledColumns];
277
+ }, [columns, defaultColumnContentClassName, showStandaloneHandleColumn, sortHandleColumnWidth]);
203
278
 
204
279
  const augmentedRowSelection = useMemo(() => {
205
280
  if (!rowSelection) return rowSelection;