@nocobase/client-v2 2.2.0-alpha.1 → 2.2.0-alpha.2
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/PluginSettingsManager.d.ts +33 -0
- package/es/RouteRepository.d.ts +21 -6
- package/es/components/category-tabs/SortableCategoryTabs.d.ts +55 -0
- package/es/components/category-tabs/index.d.ts +9 -0
- package/es/components/form/JsonTextArea.d.ts +2 -1
- package/es/components/form/TypedVariableInput.d.ts +22 -4
- package/es/components/form/VariableJsonTextArea.d.ts +19 -0
- package/es/components/form/filter/CollectionFilterItem.d.ts +11 -1
- package/es/components/form/filter/index.d.ts +2 -0
- package/es/components/form/index.d.ts +1 -0
- package/es/components/index.d.ts +2 -0
- package/es/flow/actions/afterSuccess.d.ts +8 -1
- package/es/flow/actions/index.d.ts +1 -1
- package/es/flow/admin-shell/admin-layout/AdminLayoutEntryGuard.d.ts +2 -0
- package/es/flow/admin-shell/admin-layout/AdminLayoutMenuFlowUtils.d.ts +2 -1
- package/es/flow/admin-shell/admin-layout/AdminLayoutMenuModels.d.ts +2 -0
- package/es/flow/admin-shell/admin-layout/AdminLayoutMenuUtils.d.ts +3 -2
- package/es/flow/admin-shell/admin-layout/AdminLayoutSlotModels.d.ts +5 -0
- package/es/flow/admin-shell/admin-layout/resolveAdminRouteRuntimeTarget.d.ts +6 -0
- package/es/flow/components/FieldAssignRulesEditor.d.ts +3 -1
- package/es/flow/components/FieldAssignValueInput.d.ts +2 -0
- package/es/flow/index.d.ts +1 -0
- package/es/flow/models/base/GridModel.d.ts +1 -1
- package/es/flow/models/blocks/filter-form/FilterFormBlockModel.d.ts +5 -0
- package/es/flow/models/blocks/form/FormBlockModel.d.ts +4 -0
- package/es/flow/models/blocks/form/submitHandler.d.ts +1 -1
- package/es/flow/models/blocks/form/value-runtime/rules.d.ts +21 -0
- package/es/flow/models/blocks/form/value-runtime/runtime.d.ts +21 -0
- package/es/flow/models/blocks/form/value-runtime/types.d.ts +2 -2
- package/es/flow/models/blocks/table/TableActionsColumnModel.d.ts +1 -0
- package/es/flow/models/blocks/table/TableBlockModel.d.ts +1 -0
- package/es/flow/models/blocks/table/dragSort/dragSortHooks.d.ts +1 -1
- package/es/flow/models/blocks/table/dragSort/dragSortSettings.d.ts +2 -1
- package/es/flow/models/blocks/table/dragSort/dragSortUtils.d.ts +6 -4
- package/es/flow/models/fields/AssociationFieldModel/RecordSelectFieldModel.d.ts +2 -0
- package/es/flow/models/fields/AssociationFieldModel/SubTableFieldModel/SubTableColumnModel.d.ts +6 -0
- package/es/flow/resolveViewParamsToViewList.d.ts +1 -1
- package/es/flow/utils/dataScopeRowSnapshot.d.ts +59 -0
- package/es/flow/utils/dateTimeDisplayProps.d.ts +49 -0
- package/es/flow/utils/formValueDeps.d.ts +32 -0
- package/es/flow-compat/FieldValidation.d.ts +2 -1
- package/es/index.d.ts +2 -1
- package/es/index.mjs +233 -137
- package/lib/index.js +234 -138
- package/package.json +7 -7
- package/src/PluginSettingsManager.ts +53 -0
- package/src/RouteRepository.ts +126 -24
- package/src/__tests__/PluginSettingsManager.test.ts +13 -0
- package/src/__tests__/RouteRepository.test.ts +216 -0
- package/src/__tests__/browserChecker.test.ts +61 -0
- package/src/__tests__/exports.test.ts +16 -0
- package/src/__tests__/nocobase-buildin-plugin-auth.test.tsx +199 -0
- package/src/__tests__/plugin-manager.test.tsx +44 -2
- package/src/__tests__/settings-center.test.tsx +40 -1
- package/src/collection-manager/field-configure.ts +1 -1
- package/src/collection-manager/interfaces/id.ts +1 -1
- package/src/collection-manager/interfaces/m2m.tsx +2 -2
- package/src/collection-manager/interfaces/m2o.tsx +2 -2
- package/src/collection-manager/interfaces/nanoid.ts +1 -1
- package/src/collection-manager/interfaces/o2m.tsx +2 -2
- package/src/collection-manager/interfaces/obo.tsx +2 -2
- package/src/collection-manager/interfaces/oho.tsx +2 -2
- package/src/collection-manager/interfaces/properties/index.ts +2 -2
- package/src/collection-manager/interfaces/uuid.ts +1 -1
- package/src/components/AppComponents.tsx +19 -3
- 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 +21 -11
- package/src/components/form/TypedVariableInput.tsx +416 -93
- package/src/components/form/VariableJsonTextArea.tsx +175 -0
- package/src/components/form/__tests__/JsonTextArea.test.tsx +43 -0
- package/src/components/form/__tests__/TypedVariableInput.test.tsx +266 -9
- package/src/components/form/__tests__/VariableJsonTextArea.test.tsx +86 -0
- package/src/components/form/filter/CollectionFilterItem.tsx +32 -7
- package/src/components/form/filter/__tests__/CollectionFilterItem.test.tsx +38 -0
- package/src/components/form/filter/index.ts +2 -0
- package/src/components/form/index.tsx +1 -0
- package/src/components/index.ts +2 -0
- package/src/flow/__tests__/FlowRoute.test.tsx +443 -5
- package/src/flow/__tests__/getKey.test.ts +7 -0
- package/src/flow/__tests__/resolveViewParamsToViewList.test.ts +34 -0
- package/src/flow/actions/__tests__/afterSuccess.test.ts +73 -0
- package/src/flow/actions/__tests__/dataScopeFilter.test.ts +58 -0
- package/src/flow/actions/__tests__/dataScopeFormValueClear.test.ts +1022 -0
- package/src/flow/actions/__tests__/fieldLinkageRules.scopeDepth.test.ts +150 -1
- package/src/flow/actions/__tests__/linkageAssignField.legacy.test.ts +135 -0
- package/src/flow/actions/__tests__/linkageRules.hiddenSync.restore.test.ts +19 -5
- package/src/flow/actions/__tests__/linkageRules.subFormSetFieldProps.test.ts +92 -0
- package/src/flow/actions/__tests__/openView.defineProps.route.test.tsx +104 -0
- package/src/flow/actions/__tests__/subFormFieldLinkageRules.inputArgs.test.ts +2 -2
- package/src/flow/actions/afterSuccess.tsx +142 -3
- package/src/flow/actions/customVariable.tsx +1 -2
- package/src/flow/actions/dataScopeFilter.ts +10 -0
- package/src/flow/actions/dateTimeFormat.tsx +42 -28
- package/src/flow/actions/index.ts +1 -1
- package/src/flow/actions/linkageRules.tsx +123 -35
- package/src/flow/actions/linkageRulesFormValueRefresh.ts +22 -130
- package/src/flow/actions/openView.tsx +38 -4
- package/src/flow/actions/runjs.tsx +2 -14
- package/src/flow/actions/validation.tsx +62 -30
- package/src/flow/admin-shell/BaseLayoutModel.tsx +25 -3
- package/src/flow/admin-shell/BaseLayoutRouteCoordinator.ts +5 -2
- package/src/flow/admin-shell/__tests__/AdminLayoutRouteCoordinator.test.ts +13 -0
- package/src/flow/admin-shell/admin-layout/AdminLayoutComponent.tsx +34 -10
- package/src/flow/admin-shell/admin-layout/AdminLayoutEntryGuard.test.tsx +310 -0
- package/src/flow/admin-shell/admin-layout/AdminLayoutEntryGuard.tsx +44 -8
- package/src/flow/admin-shell/admin-layout/AdminLayoutMenuFlowUtils.ts +5 -3
- package/src/flow/admin-shell/admin-layout/AdminLayoutMenuModels.tsx +61 -9
- package/src/flow/admin-shell/admin-layout/AdminLayoutMenuUtils.tsx +71 -8
- package/src/flow/admin-shell/admin-layout/AdminLayoutModel.tsx +1 -1
- package/src/flow/admin-shell/admin-layout/AdminLayoutSlotModels.tsx +23 -9
- package/src/flow/admin-shell/admin-layout/HelpLite.tsx +1 -3
- package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutComponent.test.tsx +188 -0
- package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutMenuModels.test.ts +99 -0
- package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutModel.test.tsx +82 -0
- package/src/flow/admin-shell/admin-layout/__tests__/TopbarActionsBar.test.tsx +166 -2
- package/src/flow/admin-shell/admin-layout/resolveAdminRouteRuntimeTarget.test.ts +20 -0
- package/src/flow/admin-shell/admin-layout/resolveAdminRouteRuntimeTarget.ts +33 -5
- package/src/flow/components/DefaultValue.tsx +1 -2
- package/src/flow/components/DynamicFlowsIcon.tsx +447 -126
- package/src/flow/components/FieldAssignRulesEditor.tsx +128 -21
- package/src/flow/components/FieldAssignValueInput.tsx +10 -5
- package/src/flow/components/FlowRoute.tsx +56 -11
- package/src/flow/components/__tests__/DynamicFlowsIcon.test.tsx +148 -2
- package/src/flow/components/__tests__/FieldAssignRulesEditor.test.tsx +508 -4
- package/src/flow/components/__tests__/fieldAssignOptions.test.ts +151 -3
- package/src/flow/components/code-editor/__tests__/useCodeRunner.test.tsx +2 -17
- package/src/flow/components/code-editor/hooks/useCodeRunner.ts +2 -14
- package/src/flow/components/code-editor/runjsDiagnostics.ts +8 -45
- package/src/flow/components/fieldAssignOptions.ts +155 -27
- package/src/flow/flows/editMarkdownFlow.tsx +1 -1
- package/src/flow/getViewDiffAndUpdateHidden.tsx +1 -0
- package/src/flow/index.ts +2 -1
- package/src/flow/internal/utils/operatorSchemaHelper.ts +15 -1
- package/src/flow/models/actions/JSActionModel.tsx +2 -7
- package/src/flow/models/actions/JSCollectionActionModel.tsx +2 -7
- package/src/flow/models/actions/JSItemActionModel.tsx +2 -7
- package/src/flow/models/actions/JSRecordActionModel.tsx +2 -7
- package/src/flow/models/base/ActionModel.tsx +12 -1
- package/src/flow/models/base/GridModel.tsx +38 -7
- package/src/flow/models/base/PageModel/PageModel.tsx +4 -1
- package/src/flow/models/base/PageModel/__tests__/PageModel.test.ts +28 -4
- package/src/flow/models/base/__tests__/ActionModel.test.ts +83 -0
- package/src/flow/models/base/__tests__/GridModel.dragSnapshotContainer.test.ts +239 -1
- package/src/flow/models/base/__tests__/transformRowsToSingleColumn.test.ts +48 -0
- package/src/flow/models/blocks/filter-form/FilterFormBlockModel.tsx +31 -3
- package/src/flow/models/blocks/filter-form/FilterFormJSActionModel.tsx +2 -7
- package/src/flow/models/blocks/filter-form/__tests__/defaultValues.wiring.test.ts +77 -0
- package/src/flow/models/blocks/filter-form/fields/FilterFormCustomFieldModel.tsx +1 -1
- package/src/flow/models/blocks/filter-manager/flow-actions/__tests__/customizeFilterRender.test.tsx +56 -1
- package/src/flow/models/blocks/form/EditFormModel.tsx +1 -0
- package/src/flow/models/blocks/form/FormActionModel.tsx +1 -1
- package/src/flow/models/blocks/form/FormBlockModel.tsx +7 -0
- package/src/flow/models/blocks/form/JSFormActionModel.tsx +2 -7
- package/src/flow/models/blocks/form/__tests__/FormBlockModel.test.tsx +17 -0
- package/src/flow/models/blocks/form/__tests__/submitHandler.test.ts +54 -1
- package/src/flow/models/blocks/form/submitHandler.ts +17 -3
- package/src/flow/models/blocks/form/value-runtime/__tests__/runtime.test.ts +880 -102
- package/src/flow/models/blocks/form/value-runtime/rules.ts +445 -13
- package/src/flow/models/blocks/form/value-runtime/runtime.ts +257 -13
- package/src/flow/models/blocks/form/value-runtime/types.ts +2 -2
- package/src/flow/models/blocks/js-block/JSBlock.tsx +2 -7
- package/src/flow/models/blocks/table/JSColumnModel.tsx +1 -9
- package/src/flow/models/blocks/table/TableActionsColumnModel.tsx +36 -13
- package/src/flow/models/blocks/table/TableBlockModel.tsx +38 -17
- package/src/flow/models/blocks/table/TableColumnModel.tsx +36 -3
- package/src/flow/models/blocks/table/__tests__/TableActionsColumnModel.test.tsx +111 -1
- package/src/flow/models/blocks/table/__tests__/TableBlockModel.dragSort.test.ts +127 -0
- package/src/flow/models/blocks/table/__tests__/TableBlockModel.mobileSettingsButtons.test.tsx +78 -0
- package/src/flow/models/blocks/table/__tests__/TableBlockModel.rowSelection.test.tsx +1 -0
- package/src/flow/models/blocks/table/__tests__/TableColumnModel.test.tsx +159 -1
- package/src/flow/models/blocks/table/dragSort/dragSortHooks.tsx +28 -17
- package/src/flow/models/blocks/table/dragSort/dragSortSettings.ts +13 -6
- package/src/flow/models/blocks/table/dragSort/dragSortUtils.ts +15 -2
- package/src/flow/models/fields/AssociationFieldModel/AssociationFieldModel.tsx +1 -1
- package/src/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/PopupSubTableFieldModel.tsx +29 -6
- package/src/flow/models/fields/AssociationFieldModel/RecordSelectFieldModel.tsx +16 -4
- package/src/flow/models/fields/AssociationFieldModel/SubTableFieldModel/SubTableColumnModel.tsx +141 -19
- package/src/flow/models/fields/AssociationFieldModel/SubTableFieldModel/SubTableField.tsx +13 -1
- package/src/flow/models/fields/AssociationFieldModel/SubTableFieldModel/__tests__/SubTableColumnModel.rowRecord.test.ts +197 -0
- package/src/flow/models/fields/AssociationFieldModel/SubTableFieldModel/__tests__/SubTableFieldModel.reset.test.ts +180 -0
- package/src/flow/models/fields/AssociationFieldModel/SubTableFieldModel/index.tsx +6 -4
- package/src/flow/models/fields/AssociationFieldModel/__tests__/AssociationFieldModel.updateAssociation.test.ts +72 -0
- package/src/flow/models/fields/AssociationFieldModel/__tests__/RecordPickerFieldModel.itemContext.test.ts +23 -0
- package/src/flow/models/fields/ClickableFieldModel.tsx +5 -0
- package/src/flow/models/fields/DisplayDateTimeFieldModel.tsx +29 -1
- package/src/flow/models/fields/InputFieldModel.tsx +40 -2
- package/src/flow/models/fields/JSEditableFieldModel.tsx +2 -11
- package/src/flow/models/fields/JSFieldModel.tsx +2 -7
- package/src/flow/models/fields/JSItemModel.tsx +2 -14
- package/src/flow/models/fields/SelectFieldModel.tsx +6 -4
- package/src/flow/models/fields/TextareaFieldModel.tsx +49 -3
- package/src/flow/models/fields/__tests__/DisplayDateTimeFieldModel.test.tsx +96 -0
- package/src/flow/models/fields/__tests__/InputFieldModel.test.tsx +117 -1
- package/src/flow/models/fields/__tests__/SelectFieldModel.test.tsx +43 -0
- package/src/flow/models/fields/__tests__/TextareaFieldModel.test.tsx +100 -0
- package/src/flow/models/topbar/TopbarActionModel.tsx +93 -10
- package/src/flow/resolveViewParamsToViewList.tsx +11 -3
- package/src/flow/utils/__tests__/dateTimeFormat.test.ts +258 -0
- package/src/flow/utils/dataScopeFormValueClear.ts +218 -81
- package/src/flow/utils/dataScopeRowSnapshot.ts +616 -0
- package/src/flow/utils/dateTimeDisplayProps.ts +135 -0
- package/src/flow/utils/formValueDeps.ts +170 -0
- package/src/flow-compat/FieldValidation.tsx +122 -60
- package/src/flow-compat/Popover.tsx +43 -4
- package/src/flow-compat/__tests__/Popover.test.tsx +34 -0
- package/src/index.ts +8 -1
- package/src/layout-manager/__tests__/LayoutRoute.test.tsx +41 -1
- package/src/nocobase-buildin-plugin/index.tsx +44 -14
- package/src/settings-center/AdminSettingsLayout.tsx +10 -2
- package/src/settings-center/SystemSettingsPage.tsx +1 -2
- package/src/settings-center/plugin-manager/PluginCard.tsx +2 -2
- package/src/settings-center/plugin-manager/index.tsx +3 -0
- package/src/settings-center/utils.tsx +0 -6
|
@@ -55,6 +55,7 @@ import {
|
|
|
55
55
|
useDragSortRowComponent,
|
|
56
56
|
dragSortSettings,
|
|
57
57
|
dragSortBySettings,
|
|
58
|
+
hasSortField,
|
|
58
59
|
} from './dragSort';
|
|
59
60
|
|
|
60
61
|
const MemoizedTable = React.memo(Table);
|
|
@@ -179,11 +180,21 @@ const AddFieldColumn = ({ model }: { model: TableBlockModel }) => {
|
|
|
179
180
|
].filter(Boolean)}
|
|
180
181
|
keepDropdownOpen
|
|
181
182
|
>
|
|
182
|
-
|
|
183
|
+
{renderTableSettingsButton(model, 'Fields')}
|
|
183
184
|
</AddSubModelButton>
|
|
184
185
|
);
|
|
185
186
|
};
|
|
186
187
|
|
|
188
|
+
function renderTableSettingsButton(model: TableBlockModel, title: string) {
|
|
189
|
+
const label = model.translate(title);
|
|
190
|
+
|
|
191
|
+
return (
|
|
192
|
+
<FlowSettingsButton aria-label={label} icon={<SettingOutlined />}>
|
|
193
|
+
{model.context.isMobileLayout ? null : label}
|
|
194
|
+
</FlowSettingsButton>
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
|
|
187
198
|
type CustomTableBlockModelClassesEnum = {
|
|
188
199
|
CollectionActionGroupModel?: string;
|
|
189
200
|
RecordActionGroupModel?: string;
|
|
@@ -265,7 +276,7 @@ export class TableBlockModel extends CollectionBlockModel<TableBlockModelStructu
|
|
|
265
276
|
cols.push({
|
|
266
277
|
key: 'addColumn',
|
|
267
278
|
fixed: 'right',
|
|
268
|
-
width: 100,
|
|
279
|
+
...(this.context.isMobileLayout ? {} : { width: 100 }),
|
|
269
280
|
title: <AddFieldColumn model={this} />,
|
|
270
281
|
} as any);
|
|
271
282
|
}
|
|
@@ -419,9 +430,18 @@ export class TableBlockModel extends CollectionBlockModel<TableBlockModelStructu
|
|
|
419
430
|
return nextIndex;
|
|
420
431
|
}
|
|
421
432
|
|
|
433
|
+
getDragSortFieldName(): string | undefined {
|
|
434
|
+
const dragSortBy = this.props.dragSortBy;
|
|
435
|
+
if (!this.props.dragSort || typeof dragSortBy !== 'string' || !hasSortField(this.collection, dragSortBy)) {
|
|
436
|
+
return undefined;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
return dragSortBy;
|
|
440
|
+
}
|
|
441
|
+
|
|
422
442
|
getLeftAuxiliaryColumn() {
|
|
423
443
|
const showIndex = this.isShowIndexEnabled();
|
|
424
|
-
const showDragHandle = this.
|
|
444
|
+
const showDragHandle = !!this.getDragSortFieldName();
|
|
425
445
|
if (!showIndex && !showDragHandle) {
|
|
426
446
|
return null;
|
|
427
447
|
}
|
|
@@ -467,7 +487,7 @@ export class TableBlockModel extends CollectionBlockModel<TableBlockModelStructu
|
|
|
467
487
|
index = this.getRecordIndex(record, index);
|
|
468
488
|
const rowKey = getRowKey(record, this.collection.filterTargetKey);
|
|
469
489
|
const rowKeyString = rowKey == null ? rowKey : String(rowKey);
|
|
470
|
-
const showDragHandle = this.
|
|
490
|
+
const showDragHandle = !!this.getDragSortFieldName();
|
|
471
491
|
return (
|
|
472
492
|
<div
|
|
473
493
|
role="button"
|
|
@@ -508,7 +528,7 @@ export class TableBlockModel extends CollectionBlockModel<TableBlockModelStructu
|
|
|
508
528
|
subModelBaseClass={this.getModelClassName('CollectionActionGroupModel')}
|
|
509
529
|
subModelKey="actions"
|
|
510
530
|
>
|
|
511
|
-
|
|
531
|
+
{renderTableSettingsButton(this, 'Actions')}
|
|
512
532
|
</AddSubModelButton>
|
|
513
533
|
);
|
|
514
534
|
}
|
|
@@ -1072,11 +1092,13 @@ const HighPerformanceTable = React.memo(
|
|
|
1072
1092
|
};
|
|
1073
1093
|
}, [rowKeys]);
|
|
1074
1094
|
|
|
1095
|
+
const dragSortFieldName = model.getDragSortFieldName();
|
|
1096
|
+
|
|
1075
1097
|
// 拖拽相关的 Body Wrapper 组件
|
|
1076
|
-
const BodyWrapperComponent = useDragSortBodyWrapper(model, dataSourceRef, getRowKeyFunc);
|
|
1098
|
+
const BodyWrapperComponent = useDragSortBodyWrapper(model, dataSourceRef, getRowKeyFunc, dragSortFieldName);
|
|
1077
1099
|
|
|
1078
1100
|
// 行组件
|
|
1079
|
-
const RowComponent = useDragSortRowComponent(
|
|
1101
|
+
const RowComponent = useDragSortRowComponent(!!dragSortFieldName);
|
|
1080
1102
|
|
|
1081
1103
|
const components = useMemo(() => {
|
|
1082
1104
|
return {
|
|
@@ -1099,15 +1121,14 @@ const HighPerformanceTable = React.memo(
|
|
|
1099
1121
|
}
|
|
1100
1122
|
`;
|
|
1101
1123
|
|
|
1102
|
-
const selectionPaddingClass =
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
: undefined;
|
|
1124
|
+
const selectionPaddingClass = dragSortFieldName
|
|
1125
|
+
? css`
|
|
1126
|
+
.ant-table-thead > tr > th.ant-table-selection-column,
|
|
1127
|
+
.ant-table-tbody > tr > td.ant-table-selection-column {
|
|
1128
|
+
padding-left: 32px !important;
|
|
1129
|
+
}
|
|
1130
|
+
`
|
|
1131
|
+
: undefined;
|
|
1111
1132
|
|
|
1112
1133
|
const tableBodyMinHeightClass = tableScroll?.y
|
|
1113
1134
|
? css`
|
|
@@ -1118,7 +1139,7 @@ const HighPerformanceTable = React.memo(
|
|
|
1118
1139
|
: undefined;
|
|
1119
1140
|
|
|
1120
1141
|
return classNames(baseClass, selectionPaddingClass, tableBodyMinHeightClass);
|
|
1121
|
-
}, [
|
|
1142
|
+
}, [dragSortFieldName, tableScroll?.y]);
|
|
1122
1143
|
|
|
1123
1144
|
return (
|
|
1124
1145
|
<MemoizedTable
|
|
@@ -35,6 +35,7 @@ import { ErrorBoundary } from 'react-error-boundary';
|
|
|
35
35
|
import { getRowKey } from './utils';
|
|
36
36
|
import { getSavedAssociationTitleField, getTableColumnSortField } from './sortUtils';
|
|
37
37
|
import { getFieldBindingUse, rebuildFieldSubModel } from '../../../internal/utils/rebuildFieldSubModel';
|
|
38
|
+
import { getSavedDateTimeFormatParams, resolveDateTimeDisplayProps } from '../../../utils/dateTimeDisplayProps';
|
|
38
39
|
|
|
39
40
|
export function FieldDeletePlaceholder(props: any) {
|
|
40
41
|
const { t } = useTranslation();
|
|
@@ -128,6 +129,15 @@ export const CustomWidth = ({ setOpen, t, handleChange, defaultValue }) => {
|
|
|
128
129
|
);
|
|
129
130
|
};
|
|
130
131
|
|
|
132
|
+
const resetDateTimeDisplayProps = {
|
|
133
|
+
dateOnly: undefined,
|
|
134
|
+
dateFormat: undefined,
|
|
135
|
+
format: undefined,
|
|
136
|
+
picker: undefined,
|
|
137
|
+
showTime: undefined,
|
|
138
|
+
timeFormat: undefined,
|
|
139
|
+
};
|
|
140
|
+
|
|
131
141
|
export class TableColumnModel extends DisplayItemModel {
|
|
132
142
|
// 标记:该类的 render 返回函数, 避免错误的reactive封装
|
|
133
143
|
static renderMode: ModelRenderMode = ModelRenderMode.RenderFunction;
|
|
@@ -353,11 +363,22 @@ TableColumnModel.registerFlow({
|
|
|
353
363
|
return;
|
|
354
364
|
}
|
|
355
365
|
const titleField = getSavedAssociationTitleField(ctx.model);
|
|
366
|
+
const fieldModel = Array.isArray(ctx.model.subModels.field) ? undefined : ctx.model.subModels.field;
|
|
367
|
+
const targetCollectionField = collectionField.targetCollection?.getField?.(titleField);
|
|
368
|
+
const savedDateTimeDisplayProps = getSavedDateTimeFormatParams(fieldModel)
|
|
369
|
+
? resolveDateTimeDisplayProps({
|
|
370
|
+
model: fieldModel,
|
|
371
|
+
collectionField,
|
|
372
|
+
titleField,
|
|
373
|
+
currentProps: ctx.model.props,
|
|
374
|
+
})
|
|
375
|
+
: undefined;
|
|
356
376
|
const componentProps =
|
|
357
377
|
collectionField.isAssociationField() && titleField
|
|
358
378
|
? {
|
|
359
379
|
...collectionField.getComponentProps(),
|
|
360
|
-
...
|
|
380
|
+
...targetCollectionField?.getComponentProps?.(),
|
|
381
|
+
...savedDateTimeDisplayProps,
|
|
361
382
|
}
|
|
362
383
|
: collectionField.getComponentProps();
|
|
363
384
|
ctx.model.setProps('title', collectionField.title);
|
|
@@ -539,21 +560,33 @@ TableColumnModel.registerFlow({
|
|
|
539
560
|
typeof binding?.defaultProps === 'function'
|
|
540
561
|
? binding.defaultProps(ctx, targetCollectionField)
|
|
541
562
|
: binding?.defaultProps;
|
|
563
|
+
const componentProps = targetCollectionField.getComponentProps?.() || {};
|
|
564
|
+
const nextFieldProps = {
|
|
565
|
+
...(defaultProps || {}),
|
|
566
|
+
...componentProps,
|
|
567
|
+
titleField: params.label,
|
|
568
|
+
};
|
|
569
|
+
const nextColumnProps = {
|
|
570
|
+
...resetDateTimeDisplayProps,
|
|
571
|
+
...nextFieldProps,
|
|
572
|
+
};
|
|
542
573
|
if (targetUse && targetUse !== currentUse) {
|
|
543
574
|
await rebuildFieldSubModel({
|
|
544
575
|
parentModel: ctx.model as any,
|
|
545
576
|
targetUse,
|
|
546
|
-
defaultProps,
|
|
577
|
+
defaultProps: nextFieldProps,
|
|
547
578
|
fieldSettingsInit,
|
|
548
579
|
});
|
|
549
580
|
} else if (fieldModel) {
|
|
581
|
+
fieldModel.setProps(nextColumnProps);
|
|
550
582
|
fieldModel.setStepParams('fieldSettings', 'init', fieldSettingsInit);
|
|
551
583
|
await fieldModel.dispatchEvent('beforeRender', undefined, { useCache: false });
|
|
584
|
+
await fieldModel.save();
|
|
552
585
|
}
|
|
553
586
|
if (targetUse) {
|
|
554
587
|
ctx.model.setStepParams('tableColumnSettings', 'model', { use: targetUse });
|
|
555
588
|
}
|
|
556
|
-
ctx.model.setProps(
|
|
589
|
+
ctx.model.setProps(nextColumnProps);
|
|
557
590
|
},
|
|
558
591
|
defaultParams: (ctx: any) => {
|
|
559
592
|
const titleField = ctx.model?.context?.collectionField?.targetCollectionTitleFieldName;
|
|
@@ -13,17 +13,22 @@ import { App, ConfigProvider } from 'antd';
|
|
|
13
13
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
14
14
|
import { FlowEngine, FlowEngineProvider } from '@nocobase/flow-engine';
|
|
15
15
|
import { ActionModel } from '../../../base/ActionModel';
|
|
16
|
-
import { TableActionsColumnModel } from '../TableActionsColumnModel';
|
|
16
|
+
import { TableActionsColumnModel, tableRowActionsClassName } from '../TableActionsColumnModel';
|
|
17
17
|
|
|
18
18
|
const capturedDroppableUids: string[] = [];
|
|
19
19
|
const capturedRendererProps: any[] = [];
|
|
20
20
|
let latestOnDragEnd: ((event: any) => void) | undefined;
|
|
21
21
|
const capturedDndProviders: Array<{ persist: boolean }> = [];
|
|
22
|
+
const capturedAddSubModelButtonProps: any[] = [];
|
|
22
23
|
|
|
23
24
|
vi.mock('@nocobase/flow-engine', async () => {
|
|
24
25
|
const actual = await vi.importActual<any>('@nocobase/flow-engine');
|
|
25
26
|
return {
|
|
26
27
|
...actual,
|
|
28
|
+
AddSubModelButton: (props) => {
|
|
29
|
+
capturedAddSubModelButtonProps.push(props);
|
|
30
|
+
return <button data-testid="add-sub-model-button">{props.children}</button>;
|
|
31
|
+
},
|
|
27
32
|
DndProvider: ({ children, onDragEnd, persist = true, ...restProps }) => {
|
|
28
33
|
const engine = actual.useFlowEngine();
|
|
29
34
|
const handleDragEnd = (event: any) => {
|
|
@@ -50,6 +55,17 @@ vi.mock('@nocobase/flow-engine', async () => {
|
|
|
50
55
|
const ActualFlowModelRenderer = actual.FlowModelRenderer;
|
|
51
56
|
return <ActualFlowModelRenderer {...props} />;
|
|
52
57
|
},
|
|
58
|
+
FlowsFloatContextMenu: ({ children, extraToolbarItems = [], model }) => {
|
|
59
|
+
return (
|
|
60
|
+
<div data-test-flow-context-menu>
|
|
61
|
+
{children}
|
|
62
|
+
{extraToolbarItems.map((item) => {
|
|
63
|
+
const Component = item.component;
|
|
64
|
+
return <Component key={item.key} model={model} />;
|
|
65
|
+
})}
|
|
66
|
+
</div>
|
|
67
|
+
);
|
|
68
|
+
},
|
|
53
69
|
};
|
|
54
70
|
});
|
|
55
71
|
|
|
@@ -61,6 +77,10 @@ class TestAlwaysActionModel extends ActionModel {
|
|
|
61
77
|
defaultProps: any = { type: 'link', title: 'Always' };
|
|
62
78
|
}
|
|
63
79
|
|
|
80
|
+
class TestTextActionModel extends ActionModel {
|
|
81
|
+
defaultProps: any = { type: 'text', title: 'Text action' };
|
|
82
|
+
}
|
|
83
|
+
|
|
64
84
|
// 在 beforeRender 中,根据 inputArgs(即当前行 record)决定是否隐藏按钮
|
|
65
85
|
TestViewActionModel.registerFlow({
|
|
66
86
|
key: 'autoHideByPhone',
|
|
@@ -158,6 +178,58 @@ describe('TableActionsColumnModel: hidden action layout', () => {
|
|
|
158
178
|
expect(wrappers).toHaveLength(0);
|
|
159
179
|
expect(secondUid).toBeTruthy();
|
|
160
180
|
});
|
|
181
|
+
|
|
182
|
+
it('renders row link and text actions with compact button styles', async () => {
|
|
183
|
+
const engine = new FlowEngine();
|
|
184
|
+
engine.registerModels({ TableActionsColumnModel, TestViewActionModel, TestTextActionModel });
|
|
185
|
+
|
|
186
|
+
const actionsCol = engine.createModel<TableActionsColumnModel>({
|
|
187
|
+
use: 'TableActionsColumnModel',
|
|
188
|
+
props: { width: 200, title: 'Actions' },
|
|
189
|
+
subModels: { actions: [{ use: 'TestViewActionModel' }, { use: 'TestTextActionModel' }] },
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
const colProps = actionsCol.getColumnProps();
|
|
193
|
+
const record = { id: 1, phone: '000000' } as any;
|
|
194
|
+
|
|
195
|
+
const { container } = render(
|
|
196
|
+
<FlowEngineProvider engine={engine}>
|
|
197
|
+
<ConfigProvider>
|
|
198
|
+
<App>{colProps.render?.(undefined, record, 0) as any}</App>
|
|
199
|
+
</ConfigProvider>
|
|
200
|
+
</FlowEngineProvider>,
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
await waitFor(() => {
|
|
204
|
+
expect(screen.getByText('View')).toBeInTheDocument();
|
|
205
|
+
expect(screen.getByText('Text action')).toBeInTheDocument();
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
const actions = container.querySelector('.nb-table-row-actions');
|
|
209
|
+
expect(actions).toBeInTheDocument();
|
|
210
|
+
expect(actions).toHaveClass(tableRowActionsClassName);
|
|
211
|
+
|
|
212
|
+
const linkButton = actions?.querySelector('.ant-btn-link') as HTMLButtonElement;
|
|
213
|
+
const textButton = actions?.querySelector('.ant-btn-text') as HTMLButtonElement;
|
|
214
|
+
|
|
215
|
+
expect(linkButton).toBeInTheDocument();
|
|
216
|
+
expect(textButton).toBeInTheDocument();
|
|
217
|
+
expect(linkButton).toHaveClass('nb-table-row-action-button');
|
|
218
|
+
expect(textButton).toHaveClass('nb-table-row-action-button');
|
|
219
|
+
|
|
220
|
+
const actionButtonStyleText = Array.from(document.querySelectorAll('style'))
|
|
221
|
+
.map((style) => style.textContent || '')
|
|
222
|
+
.find((styleText) => styleText.includes('.nb-table-row-action-button.ant-btn-link'));
|
|
223
|
+
expect(actionButtonStyleText).toContain(tableRowActionsClassName);
|
|
224
|
+
expect(actionButtonStyleText).toContain('font:inherit');
|
|
225
|
+
expect(actionButtonStyleText).toContain('height:auto');
|
|
226
|
+
expect(actionButtonStyleText).toContain('line-height:inherit');
|
|
227
|
+
expect(actionButtonStyleText).toContain('padding:0');
|
|
228
|
+
expect(actionButtonStyleText).toContain('border:0');
|
|
229
|
+
expect(actionButtonStyleText).toContain('box-shadow:none');
|
|
230
|
+
expect(actionButtonStyleText).not.toContain('1.5714285714285714');
|
|
231
|
+
expect(actionButtonStyleText).not.toContain('!important');
|
|
232
|
+
});
|
|
161
233
|
});
|
|
162
234
|
|
|
163
235
|
describe('TableActionsColumnModel: drag integration', () => {
|
|
@@ -165,6 +237,7 @@ describe('TableActionsColumnModel: drag integration', () => {
|
|
|
165
237
|
capturedDroppableUids.length = 0;
|
|
166
238
|
capturedRendererProps.length = 0;
|
|
167
239
|
capturedDndProviders.length = 0;
|
|
240
|
+
capturedAddSubModelButtonProps.length = 0;
|
|
168
241
|
latestOnDragEnd = undefined;
|
|
169
242
|
});
|
|
170
243
|
|
|
@@ -177,6 +250,7 @@ describe('TableActionsColumnModel: drag integration', () => {
|
|
|
177
250
|
props: { width: 200, title: 'Actions' },
|
|
178
251
|
subModels: { actions: [{ use: 'TestViewActionModel' }, { use: 'TestViewActionModel' }] },
|
|
179
252
|
});
|
|
253
|
+
actionsCol.context.defineMethod('getModelClassName', (className: string) => className);
|
|
180
254
|
|
|
181
255
|
const colProps = actionsCol.getColumnProps();
|
|
182
256
|
const record = { id: 1, phone: '000000' } as any;
|
|
@@ -279,4 +353,40 @@ describe('TableActionsColumnModel: drag integration', () => {
|
|
|
279
353
|
|
|
280
354
|
expect(moveModelSpy).toHaveBeenCalledWith(firstUid, secondUid, { persist: true });
|
|
281
355
|
});
|
|
356
|
+
|
|
357
|
+
it('disables icon-only mode when adding row actions without icons', async () => {
|
|
358
|
+
const engine = new FlowEngine();
|
|
359
|
+
engine.registerModels({ TableActionsColumnModel, TestViewActionModel });
|
|
360
|
+
|
|
361
|
+
const actionsCol = engine.createModel<TableActionsColumnModel>({
|
|
362
|
+
use: 'TableActionsColumnModel',
|
|
363
|
+
props: { width: 200, title: 'Actions' },
|
|
364
|
+
});
|
|
365
|
+
actionsCol.context.defineMethod('getModelClassName', (className: string) => className);
|
|
366
|
+
|
|
367
|
+
render(
|
|
368
|
+
<FlowEngineProvider engine={engine}>
|
|
369
|
+
<ConfigProvider>
|
|
370
|
+
<App>{actionsCol.getColumnProps().title as React.ReactNode}</App>
|
|
371
|
+
</ConfigProvider>
|
|
372
|
+
</FlowEngineProvider>,
|
|
373
|
+
);
|
|
374
|
+
|
|
375
|
+
const addButtonProps = capturedAddSubModelButtonProps.find(
|
|
376
|
+
(props) => props.subModelKey === 'actions' && props.subModelBaseClass === 'RecordActionGroupModel',
|
|
377
|
+
);
|
|
378
|
+
expect(addButtonProps).toBeDefined();
|
|
379
|
+
expect(addButtonProps.afterSubModelInit).toBeTypeOf('function');
|
|
380
|
+
|
|
381
|
+
const actionModel = {
|
|
382
|
+
setStepParams: vi.fn(),
|
|
383
|
+
};
|
|
384
|
+
await addButtonProps.afterSubModelInit(actionModel);
|
|
385
|
+
|
|
386
|
+
expect(actionModel.setStepParams).toHaveBeenCalledWith('buttonSettings', 'general', {
|
|
387
|
+
type: 'link',
|
|
388
|
+
icon: null,
|
|
389
|
+
iconOnly: false,
|
|
390
|
+
});
|
|
391
|
+
});
|
|
282
392
|
});
|
|
@@ -0,0 +1,127 @@
|
|
|
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 } from '@nocobase/flow-engine';
|
|
11
|
+
import { describe, expect, it } from 'vitest';
|
|
12
|
+
import '@nocobase/client';
|
|
13
|
+
import { initDragSortParams } from '../dragSort';
|
|
14
|
+
import { TableBlockModel } from '../TableBlockModel';
|
|
15
|
+
|
|
16
|
+
function createTableModel() {
|
|
17
|
+
const engine = new FlowEngine();
|
|
18
|
+
engine.registerModels({ TableBlockModel });
|
|
19
|
+
|
|
20
|
+
const ds = engine.dataSourceManager.getDataSource('main');
|
|
21
|
+
ds.addCollection({
|
|
22
|
+
name: 'posts',
|
|
23
|
+
filterTargetKey: 'id',
|
|
24
|
+
fields: [
|
|
25
|
+
{ name: 'id', type: 'integer', interface: 'number' },
|
|
26
|
+
{ name: 'title', type: 'string', interface: 'input' },
|
|
27
|
+
{ name: 'sort', type: 'sort', interface: 'sort' },
|
|
28
|
+
],
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
return engine.createModel<TableBlockModel>({
|
|
32
|
+
uid: 'posts-table',
|
|
33
|
+
use: 'TableBlockModel',
|
|
34
|
+
stepParams: {
|
|
35
|
+
resourceSettings: {
|
|
36
|
+
init: {
|
|
37
|
+
dataSourceKey: 'main',
|
|
38
|
+
collectionName: 'posts',
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
describe('TableBlockModel drag sorting settings', () => {
|
|
46
|
+
it('does not keep a deleted drag sort field in resource sort', () => {
|
|
47
|
+
const model = createTableModel();
|
|
48
|
+
|
|
49
|
+
model.setProps('dragSort', true);
|
|
50
|
+
model.setProps('dragSortBy', 'sort');
|
|
51
|
+
model.setProps('globalSort', ['title']);
|
|
52
|
+
model.resource.setSort(['sort']);
|
|
53
|
+
model.collection.fields.delete('sort');
|
|
54
|
+
|
|
55
|
+
initDragSortParams(model);
|
|
56
|
+
|
|
57
|
+
expect(model.getDragSortFieldName()).toBeUndefined();
|
|
58
|
+
expect(model.resource.getSort()).toEqual(['title']);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('hides the drag handle when the configured sort field was deleted', () => {
|
|
62
|
+
const model = createTableModel();
|
|
63
|
+
|
|
64
|
+
model.setProps('enableRowSelection', false);
|
|
65
|
+
model.setProps('showIndex', false);
|
|
66
|
+
model.setProps('dragSort', true);
|
|
67
|
+
model.setProps('dragSortBy', 'sort');
|
|
68
|
+
model.collection.fields.delete('sort');
|
|
69
|
+
|
|
70
|
+
expect(model.getLeftAuxiliaryColumn()).toBeNull();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('allows clearing the configured drag sort field and restores default sorting', () => {
|
|
74
|
+
const model = createTableModel();
|
|
75
|
+
const dragSortByStep = model.getFlow('tableSettings')?.steps?.dragSortBy;
|
|
76
|
+
|
|
77
|
+
model.setProps('dragSort', true);
|
|
78
|
+
model.setProps('dragSortBy', 'sort');
|
|
79
|
+
model.setProps('globalSort', ['title']);
|
|
80
|
+
model.resource.setSort(['sort']);
|
|
81
|
+
|
|
82
|
+
const uiMode =
|
|
83
|
+
typeof dragSortByStep?.uiMode === 'function' ? dragSortByStep.uiMode({ model, t: (key: string) => key }) : null;
|
|
84
|
+
dragSortByStep?.handler({ model }, { dragSortBy: null });
|
|
85
|
+
|
|
86
|
+
expect(uiMode).toMatchObject({
|
|
87
|
+
type: 'select',
|
|
88
|
+
key: 'dragSortBy',
|
|
89
|
+
props: {
|
|
90
|
+
allowClear: true,
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
expect(model.props.dragSortBy).toBeNull();
|
|
94
|
+
expect(model.resource.getSort()).toEqual(['title']);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('ignores a deleted drag sort field submitted by settings', () => {
|
|
98
|
+
const model = createTableModel();
|
|
99
|
+
const dragSortByStep = model.getFlow('tableSettings')?.steps?.dragSortBy;
|
|
100
|
+
|
|
101
|
+
model.setProps('dragSort', true);
|
|
102
|
+
model.setProps('dragSortBy', 'sort');
|
|
103
|
+
model.setProps('globalSort', ['title']);
|
|
104
|
+
model.resource.setSort(['sort']);
|
|
105
|
+
model.collection.fields.delete('sort');
|
|
106
|
+
|
|
107
|
+
dragSortByStep?.handler({ model }, { dragSortBy: 'sort' });
|
|
108
|
+
|
|
109
|
+
expect(model.props.dragSortBy).toBeNull();
|
|
110
|
+
expect(model.resource.getSort()).toEqual(['title']);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('restores default sorting when drag sorting is disabled', () => {
|
|
114
|
+
const model = createTableModel();
|
|
115
|
+
const dragSortStep = model.getFlow('tableSettings')?.steps?.dragSort;
|
|
116
|
+
|
|
117
|
+
model.setProps('dragSort', true);
|
|
118
|
+
model.setProps('dragSortBy', 'sort');
|
|
119
|
+
model.setProps('globalSort', ['title']);
|
|
120
|
+
model.resource.setSort(['sort']);
|
|
121
|
+
|
|
122
|
+
dragSortStep?.handler({ model }, { dragSort: false });
|
|
123
|
+
|
|
124
|
+
expect(model.props.dragSort).toBe(false);
|
|
125
|
+
expect(model.resource.getSort()).toEqual(['title']);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
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 } from '@nocobase/flow-engine';
|
|
11
|
+
import '@nocobase/client';
|
|
12
|
+
import React from 'react';
|
|
13
|
+
import { describe, expect, it } from 'vitest';
|
|
14
|
+
import { TableBlockModel } from '../TableBlockModel';
|
|
15
|
+
|
|
16
|
+
function createTableModel(options: { isMobileLayout?: boolean; flowSettingsEnabled?: boolean } = {}) {
|
|
17
|
+
const engine = new FlowEngine();
|
|
18
|
+
engine.registerModels({ TableBlockModel });
|
|
19
|
+
engine.context.defineProperty('isMobileLayout', { value: !!options.isMobileLayout });
|
|
20
|
+
engine.context.defineProperty('flowSettingsEnabled', { value: !!options.flowSettingsEnabled });
|
|
21
|
+
|
|
22
|
+
const ds = engine.dataSourceManager.getDataSource('main');
|
|
23
|
+
ds.addCollection({
|
|
24
|
+
name: 'posts',
|
|
25
|
+
filterTargetKey: 'id',
|
|
26
|
+
fields: [
|
|
27
|
+
{ name: 'id', type: 'integer', interface: 'number' },
|
|
28
|
+
{ name: 'title', type: 'string', interface: 'input' },
|
|
29
|
+
],
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
return engine.createModel<TableBlockModel>({
|
|
33
|
+
uid: `posts-table-${options.isMobileLayout ? 'mobile' : 'desktop'}`,
|
|
34
|
+
use: 'TableBlockModel',
|
|
35
|
+
stepParams: {
|
|
36
|
+
resourceSettings: {
|
|
37
|
+
init: {
|
|
38
|
+
dataSourceKey: 'main',
|
|
39
|
+
collectionName: 'posts',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function getSettingsButton(element: React.ReactElement) {
|
|
47
|
+
return element.props.children as React.ReactElement;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
describe('TableBlockModel mobile settings buttons', () => {
|
|
51
|
+
it('renders table actions and fields settings as icon-only buttons in mobile layouts', () => {
|
|
52
|
+
const model = createTableModel({ isMobileLayout: true, flowSettingsEnabled: true });
|
|
53
|
+
const actionButton = getSettingsButton(model.renderConfigureActions() as React.ReactElement);
|
|
54
|
+
const addColumn = model.getColumns().find((column) => column.key === 'addColumn');
|
|
55
|
+
const fieldsButton = getSettingsButton(
|
|
56
|
+
(addColumn?.title as React.ReactElement).type({ model }) as React.ReactElement,
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
expect(actionButton.props.children).toBeNull();
|
|
60
|
+
expect(actionButton.props['aria-label']).toBe('Actions');
|
|
61
|
+
expect(fieldsButton.props.children).toBeNull();
|
|
62
|
+
expect(fieldsButton.props['aria-label']).toBe('Fields');
|
|
63
|
+
expect(addColumn?.width).toBeUndefined();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('keeps table actions and fields settings labels outside mobile layouts', () => {
|
|
67
|
+
const model = createTableModel({ flowSettingsEnabled: true });
|
|
68
|
+
const actionButton = getSettingsButton(model.renderConfigureActions() as React.ReactElement);
|
|
69
|
+
const addColumn = model.getColumns().find((column) => column.key === 'addColumn');
|
|
70
|
+
const fieldsButton = getSettingsButton(
|
|
71
|
+
(addColumn?.title as React.ReactElement).type({ model }) as React.ReactElement,
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
expect(actionButton.props.children).toBe('Actions');
|
|
75
|
+
expect(fieldsButton.props.children).toBe('Fields');
|
|
76
|
+
expect(addColumn?.width).toBe(100);
|
|
77
|
+
});
|
|
78
|
+
});
|