@nocobase/client-v2 2.2.0-beta.8 → 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.
- package/es/APIClient.d.ts +13 -3
- package/es/BaseApplication.d.ts +3 -0
- package/es/RouteRepository.d.ts +8 -0
- package/es/RouterManager.d.ts +15 -0
- package/es/authRedirect.d.ts +1 -0
- package/es/collection-field-interface/CollectionFieldInterface.d.ts +1 -0
- package/es/collection-field-interface/CollectionFieldInterfaceManager.d.ts +1 -0
- package/es/components/category-tabs/SortableCategoryTabs.d.ts +55 -0
- package/es/components/category-tabs/index.d.ts +9 -0
- package/es/components/form/ScanInput/useCodeScanner.d.ts +3 -2
- package/es/components/form/TypedVariableInput.d.ts +31 -5
- package/es/components/form/filter/CollectionFilter.d.ts +2 -0
- package/es/components/form/filter/CollectionFilterItem.d.ts +11 -1
- package/es/components/form/filter/CollectionFilterPanel.d.ts +2 -0
- package/es/components/form/filter/index.d.ts +2 -0
- package/es/components/form/filter/useFilterActionProps.d.ts +2 -0
- package/es/components/index.d.ts +1 -0
- package/es/entry-actions/EntryActionManager.d.ts +24 -0
- package/es/entry-actions/index.d.ts +9 -0
- package/es/flow/actions/index.d.ts +1 -1
- package/es/flow/actions/linkageRules.d.ts +27 -0
- package/es/flow/admin-shell/BaseLayoutModel.d.ts +6 -0
- package/es/flow/admin-shell/BaseLayoutRouteCoordinator.d.ts +7 -0
- package/es/flow/admin-shell/admin-layout/AdminLayoutMenuModels.d.ts +1 -0
- package/es/flow/admin-shell/admin-layout/AppListRender.d.ts +2 -1
- package/es/flow/admin-shell/admin-layout/AppSwitcherActionPanelModel.d.ts +24 -0
- package/es/flow/admin-shell/admin-layout/index.d.ts +1 -0
- package/es/flow/admin-shell/admin-layout/useApplications.d.ts +7 -2
- package/es/flow/components/FieldAssignExactDatePicker.d.ts +1 -0
- package/es/flow/components/FieldAssignValueInput.d.ts +7 -24
- package/es/flow/components/FlowRoute.d.ts +2 -2
- package/es/flow/components/RunJSValueEditor.d.ts +1 -0
- package/es/flow/components/field-value-variable/DateVariableEditor.d.ts +24 -0
- package/es/flow/components/field-value-variable/FieldValueVariableInput.d.ts +31 -0
- package/es/flow/components/field-value-variable/dateValue.d.ts +36 -0
- package/es/flow/components/field-value-variable/index.d.ts +11 -0
- package/es/flow/components/filter/FilterGroup.d.ts +1 -0
- package/es/flow/components/filter/VariableFilterItem.d.ts +6 -1
- package/es/flow/components/placeholders/BlockPlaceholder.d.ts +1 -0
- package/es/flow/index.d.ts +1 -0
- package/es/flow/internal/registerDeviceTypeContext.d.ts +10 -0
- package/es/flow/internal/utils/operatorSchemaHelper.d.ts +2 -2
- package/es/flow/models/actions/UpdateRecordActionUtils.d.ts +8 -2
- package/es/flow/models/base/ActionModelCore.d.ts +6 -2
- package/es/flow/models/base/BlockGridModel.d.ts +3 -0
- package/es/flow/models/base/CollectionBlockModel.d.ts +3 -0
- package/es/flow/models/base/PageModel/PageModel.d.ts +12 -0
- package/es/flow/models/base/PageModel/PageModelTabBar.d.ts +22 -0
- package/es/flow/models/base/PageModel/PageTabModel.d.ts +12 -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 +7 -0
- package/es/flow/models/blocks/form/FormGridModel.d.ts +6 -0
- package/es/flow/models/blocks/form/QuickEditFormModel.d.ts +17 -2
- package/es/flow/models/blocks/form/value-runtime/rules.d.ts +1 -0
- package/es/flow/models/blocks/table/JSColumnModel.d.ts +2 -0
- package/es/flow/models/blocks/table/TableBlockModel.d.ts +1 -0
- package/es/flow/models/blocks/table/TableColumnModel.d.ts +12 -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/models/fields/DateTimeFieldModel/dateLimit.d.ts +15 -7
- package/es/flow/routeTransientInputArgs.d.ts +14 -0
- package/es/flow-compat/fieldValidationConstants.d.ts +1 -1
- package/es/flow-compat/passwordUtils.d.ts +1 -1
- package/es/flow-compat/routeTypes.d.ts +1 -0
- package/es/index.d.ts +7 -0
- package/es/index.mjs +301 -177
- package/es/ui-operation/index.d.ts +15 -0
- package/es/ui-operation/ui-operation-codec.d.ts +10 -0
- package/es/utils/getRouteRuntimeVersion.d.ts +23 -0
- package/es/utils/index.d.ts +1 -0
- package/es/utils/markdownSanitize.d.ts +11 -0
- package/lib/index.js +313 -189
- package/lib/locale/languageCodes.js +3 -1
- package/package.json +9 -7
- package/src/APIClient.ts +90 -7
- package/src/Application.tsx +7 -1
- package/src/BaseApplication.tsx +13 -6
- package/src/RouteRepository.ts +25 -0
- package/src/RouterManager.tsx +142 -1
- package/src/__tests__/APIClient.test.tsx +58 -0
- package/src/__tests__/RouteRepository.test.ts +23 -0
- package/src/__tests__/RouterManager.test.ts +125 -0
- package/src/__tests__/app.test.tsx +73 -0
- package/src/__tests__/authRedirect.test.ts +17 -0
- package/src/__tests__/browserChecker.test.ts +61 -0
- package/src/__tests__/getRouteRuntimeVersion.test.ts +68 -0
- package/src/__tests__/nocobase-buildin-plugin-auth.test.tsx +35 -2
- 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/authRedirect.ts +38 -0
- package/src/collection-field-interface/CollectionFieldInterface.ts +1 -0
- package/src/collection-field-interface/CollectionFieldInterfaceManager.ts +1 -0
- package/src/collection-manager/field-validation.ts +1 -1
- package/src/components/README.md +7 -1
- package/src/components/README.zh-CN.md +6 -1
- package/src/components/category-tabs/SortableCategoryTabs.tsx +210 -0
- package/src/components/category-tabs/index.ts +10 -0
- package/src/components/form/JsonTextArea.tsx +4 -0
- package/src/components/form/ScanInput/CodeScanner.tsx +79 -35
- package/src/components/form/ScanInput/__tests__/CodeScanner.test.tsx +101 -0
- package/src/components/form/ScanInput/__tests__/useCodeScanner.test.tsx +284 -11
- package/src/components/form/ScanInput/useCodeScanner.ts +332 -24
- package/src/components/form/TypedVariableInput.tsx +452 -101
- package/src/components/form/__tests__/TypedVariableInput.test.tsx +364 -12
- package/src/components/form/filter/CollectionFilter.tsx +4 -0
- package/src/components/form/filter/CollectionFilterItem.tsx +36 -9
- package/src/components/form/filter/CollectionFilterPanel.tsx +4 -0
- package/src/components/form/filter/__tests__/CollectionFilterItem.test.tsx +55 -0
- package/src/components/form/filter/__tests__/useFilterActionProps.test.tsx +95 -0
- package/src/components/form/filter/index.ts +2 -0
- package/src/components/form/filter/useFilterActionProps.ts +37 -6
- package/src/components/form/table/Table.tsx +81 -6
- package/src/components/form/table/__tests__/Table.columnWidth.test.tsx +433 -0
- package/src/components/index.ts +1 -0
- package/src/entry-actions/EntryActionManager.ts +76 -0
- package/src/entry-actions/index.ts +10 -0
- package/src/flow/FlowPage.tsx +38 -3
- package/src/flow/__tests__/FlowPage.test.tsx +201 -27
- package/src/flow/__tests__/FlowRoute.test.tsx +675 -12
- package/src/flow/__tests__/PluginFlowEngine.test.ts +58 -0
- package/src/flow/actions/__tests__/actionLinkageRules.forkProps.test.ts +314 -0
- package/src/flow/actions/__tests__/dataScopeFilter.test.ts +62 -0
- package/src/flow/actions/__tests__/dataScopeFormValueClear.test.ts +102 -0
- package/src/flow/actions/__tests__/linkageRules.actionStates.test.ts +33 -0
- package/src/flow/actions/__tests__/linkageRules.subFormSetFieldProps.test.ts +72 -0
- package/src/flow/actions/__tests__/linkageRules.tab.test.ts +171 -0
- package/src/flow/actions/__tests__/linkageRulesRefresh.test.ts +7 -3
- package/src/flow/actions/__tests__/openView.defineProps.route.test.tsx +80 -20
- package/src/flow/actions/dataScopeFilter.ts +10 -1
- package/src/flow/actions/dateTimeFormat.tsx +2 -2
- package/src/flow/actions/index.ts +2 -0
- package/src/flow/actions/linkageRules.tsx +144 -26
- package/src/flow/actions/linkageRulesRefresh.tsx +2 -6
- package/src/flow/actions/openView.tsx +21 -1
- package/src/flow/admin-shell/BaseLayoutModel.tsx +124 -0
- package/src/flow/admin-shell/BaseLayoutRouteCoordinator.ts +184 -42
- package/src/flow/admin-shell/__tests__/AdminLayoutRouteCoordinator.test.ts +1016 -119
- package/src/flow/admin-shell/admin-layout/AdminLayoutComponent.tsx +41 -5
- 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/AdminLayoutMenuUtils.tsx +78 -59
- package/src/flow/admin-shell/admin-layout/AppListRender.tsx +13 -2
- package/src/flow/admin-shell/admin-layout/AppSwitcherActionPanelModel.tsx +289 -0
- package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutComponent.test.tsx +253 -6
- package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutMenuModels.test.ts +228 -0
- package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutModel.test.tsx +436 -2
- package/src/flow/admin-shell/admin-layout/__tests__/TopbarActionsBar.test.tsx +48 -0
- package/src/flow/admin-shell/admin-layout/index.ts +1 -0
- package/src/flow/admin-shell/admin-layout/useApplications.tsx +81 -12
- package/src/flow/common/Markdown/Display.tsx +14 -3
- package/src/flow/common/Markdown/Edit.tsx +19 -7
- package/src/flow/common/Markdown/style.ts +4 -0
- package/src/flow/components/BlockItemCard.tsx +2 -2
- package/src/flow/components/FieldAssignExactDatePicker.tsx +25 -11
- package/src/flow/components/FieldAssignValueInput.tsx +72 -584
- package/src/flow/components/FlowRoute.tsx +204 -46
- package/src/flow/components/RunJSValueEditor.tsx +9 -1
- package/src/flow/components/__tests__/FieldAssignValueInput.context.test.tsx +216 -0
- package/src/flow/components/field-value-variable/DateVariableEditor.tsx +181 -0
- package/src/flow/components/field-value-variable/FieldValueVariableInput.tsx +326 -0
- package/src/flow/components/field-value-variable/__tests__/FieldValueVariableInput.test.tsx +380 -0
- package/src/flow/components/field-value-variable/dateValue.ts +223 -0
- package/src/flow/components/field-value-variable/index.ts +12 -0
- package/src/flow/components/filter/FilterGroup.tsx +33 -5
- package/src/flow/components/filter/VariableFilterItem.tsx +170 -13
- package/src/flow/components/filter/__tests__/FilterGroup.test.tsx +45 -0
- package/src/flow/components/filter/__tests__/VariableFilterItem.leftMetaTree.test.tsx +9 -0
- package/src/flow/components/filter/__tests__/VariableFilterItem.test.tsx +195 -1
- package/src/flow/components/placeholders/BlockPlaceholder.tsx +70 -23
- package/src/flow/components/placeholders/__tests__/BlockPlaceholder.test.tsx +57 -7
- package/src/flow/index.ts +3 -0
- package/src/flow/internal/components/Markdown/util.ts +2 -1
- package/src/flow/internal/registerDeviceTypeContext.ts +39 -0
- package/src/flow/internal/utils/operatorSchemaHelper.ts +3 -2
- package/src/flow/models/actions/UpdateRecordActionModel.tsx +18 -1
- package/src/flow/models/actions/UpdateRecordActionUtils.ts +18 -6
- package/src/flow/models/actions/__tests__/UpdateRecordActionModel.test.ts +76 -4
- package/src/flow/models/base/ActionModel.tsx +10 -8
- package/src/flow/models/base/ActionModelCore.tsx +16 -2
- package/src/flow/models/base/BlockGridModel.tsx +26 -0
- package/src/flow/models/base/CollectionBlockModel.tsx +38 -3
- package/src/flow/models/base/PageModel/PageModel.tsx +387 -53
- package/src/flow/models/base/PageModel/PageModelTabBar.tsx +114 -0
- package/src/flow/models/base/PageModel/PageTabModel.tsx +249 -18
- package/src/flow/models/base/PageModel/__tests__/PageModel.test.ts +790 -10
- package/src/flow/models/base/PageModel/__tests__/PageModelTabBar.module-isolation.test.tsx +130 -0
- package/src/flow/models/base/PageModel/__tests__/PageModelTabBar.test.tsx +118 -0
- package/src/flow/models/base/PageModel/__tests__/PageTabModel.test.ts +1075 -7
- package/src/flow/models/base/__tests__/ActionModelCore.render.test.tsx +49 -0
- package/src/flow/models/base/__tests__/BlockGridModel.selectSceneActivation.test.ts +124 -0
- package/src/flow/models/base/__tests__/CollectionBlockModel.addAppends.test.ts +41 -0
- package/src/flow/models/base/__tests__/CollectionBlockModel.initialBeforeRenderRefresh.test.ts +125 -9
- package/src/flow/models/blocks/assign-form/AssignFormItemModel.tsx +28 -53
- 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/FilterFormBlockModel.tsx +28 -3
- package/src/flow/models/blocks/filter-form/FilterFormGridModel.tsx +36 -5
- package/src/flow/models/blocks/filter-form/FilterFormItemModel.tsx +155 -25
- 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 +395 -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-form/__tests__/defaultValues.wiring.test.ts +66 -4
- 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 +47 -0
- package/src/flow/models/blocks/form/FormGridModel.tsx +4 -0
- package/src/flow/models/blocks/form/QuickEditFormModel.tsx +189 -36
- package/src/flow/models/blocks/form/__tests__/FormBlockModel.test.tsx +8 -2
- package/src/flow/models/blocks/form/__tests__/QuickEditFormModel.quickEdit.test.ts +350 -2
- package/src/flow/models/blocks/form/__tests__/runJsFormSubmit.test.ts +131 -0
- package/src/flow/models/blocks/form/value-runtime/__tests__/runtime.test.ts +435 -0
- package/src/flow/models/blocks/form/value-runtime/rules.ts +67 -14
- package/src/flow/models/blocks/form/value-runtime/runtime.ts +43 -19
- package/src/flow/models/blocks/js-block/JSBlock.tsx +1 -1
- package/src/flow/models/blocks/table/JSColumnModel.tsx +10 -1
- package/src/flow/models/blocks/table/TableActionsColumnModel.tsx +2 -1
- package/src/flow/models/blocks/table/TableBlockModel.tsx +29 -3
- package/src/flow/models/blocks/table/TableColumnModel.tsx +54 -11
- package/src/flow/models/blocks/table/__tests__/JSColumnModel.test.tsx +52 -5
- package/src/flow/models/blocks/table/__tests__/TableBlockModel.filterReset.test.ts +78 -0
- package/src/flow/models/blocks/table/__tests__/TableBlockModel.quickEditRefresh.test.ts +12 -0
- package/src/flow/models/blocks/table/__tests__/TableColumnModel.test.tsx +84 -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/PopupSubTableFieldModel/PopupSubTableFieldModel.tsx +10 -1
- package/src/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/__tests__/popupContext.test.ts +120 -0
- package/src/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/actions/PopupSubTableEditActionModel.tsx +10 -2
- package/src/flow/models/fields/AssociationFieldModel/RecordPickerFieldModel.tsx +24 -1
- package/src/flow/models/fields/AssociationFieldModel/RecordSelectFieldModel.tsx +54 -149
- package/src/flow/models/fields/AssociationFieldModel/__tests__/RecordPickerFieldModel.itemContext.test.ts +167 -3
- package/src/flow/models/fields/AssociationFieldModel/recordSelectShared.tsx +156 -0
- package/src/flow/models/fields/DateTimeFieldModel/__tests__/DateTimeNoTzFieldModel.dateLimit.test.tsx +149 -0
- package/src/flow/models/fields/DateTimeFieldModel/dateLimit.ts +149 -113
- package/src/flow/models/fields/DisplayNumberFieldModel.tsx +1 -1
- package/src/flow/models/fields/JsonFieldModel.tsx +31 -8
- package/src/flow/models/fields/NumberFieldModel.tsx +1 -1
- package/src/flow/models/fields/TextareaFieldModel.tsx +42 -19
- package/src/flow/models/fields/VariableFieldFormModel.tsx +3 -3
- package/src/flow/models/fields/__tests__/DisplayNumberFieldModel.test.ts +33 -0
- package/src/flow/models/fields/__tests__/JsonFieldModel.test.ts +82 -0
- package/src/flow/models/fields/__tests__/NumberFieldModel.test.tsx +47 -0
- package/src/flow/models/fields/__tests__/TextareaFieldModel.test.tsx +32 -1
- package/src/flow/models/fields/__tests__/VariableFieldFormModel.test.tsx +51 -0
- package/src/flow/models/fields/mobile-components/MobileLazySelect.tsx +26 -10
- package/src/flow/models/fields/mobile-components/MobileSelect.tsx +51 -14
- package/src/flow/models/fields/mobile-components/__tests__/MobileSelect.test.tsx +139 -13
- package/src/flow/models/topbar/TopbarActionModel.tsx +78 -3
- package/src/flow/routeTransientInputArgs.ts +27 -0
- package/src/flow/utils/__tests__/dateTimeFormat.test.ts +42 -0
- package/src/flow/utils/dataScopeFormValueClear.ts +4 -3
- package/src/flow-compat/fieldValidationConstants.ts +1 -1
- package/src/flow-compat/routeTypes.ts +1 -0
- package/src/index.ts +7 -0
- package/src/layout-manager/LayoutContentRoute.tsx +2 -1
- package/src/layout-manager/LayoutRoute.tsx +2 -1
- package/src/layout-manager/__tests__/LayoutRoute.test.tsx +87 -1
- package/src/locale/languageCodes.ts +3 -1
- package/src/nocobase-buildin-plugin/index.tsx +19 -1
- package/src/settings-center/AdminSettingsLayout.tsx +23 -2
- package/src/ui-operation/index.ts +33 -0
- package/src/ui-operation/ui-operation-codec.ts +54 -0
- package/src/utils/getRouteRuntimeVersion.ts +185 -0
- package/src/utils/index.tsx +1 -0
- package/src/utils/markdownSanitize.ts +88 -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 {
|
|
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(
|
|
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
|
-
|
|
244
|
-
value.
|
|
245
|
-
|
|
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 =
|
|
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
|
-
|
|
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, ...
|
|
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;
|