@nocobase/client-v2 2.4.0-alpha.2 → 2.4.0-alpha.21
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/README.md +4 -4
- package/es/BaseApplication.d.ts +3 -0
- package/es/RouteRepository.d.ts +6 -0
- package/es/components/form/ScanInput/useCodeScanner.d.ts +12 -2
- package/es/components/form/ScanInput/zxingWasmDecoder.d.ts +9 -0
- package/es/components/form/VariableInput.d.ts +1 -0
- package/es/flow/FlowModelRepository.d.ts +4 -1
- package/es/flow/FlowPage.d.ts +1 -1
- package/es/flow/admin-shell/admin-layout/AdminLayoutMenuModels.d.ts +1 -0
- package/es/flow/admin-shell/admin-layout/AdminLayoutMenuUtils.d.ts +1 -0
- package/es/flow/admin-shell/admin-layout/AdminLayoutModel.d.ts +2 -0
- package/es/flow/admin-shell/admin-layout/MobileTopbarActionsContext.d.ts +10 -0
- package/es/flow/admin-shell/admin-layout/index.d.ts +1 -0
- package/es/flow/admin-shell/admin-layout/observeAdminMenuRoutes.d.ts +26 -0
- package/es/flow/components/FieldAssignValueInput.d.ts +2 -0
- package/es/flow/components/field-value-variable/FieldValueVariableInput.d.ts +1 -0
- package/es/flow/components/filter/VariableFilterItem.d.ts +10 -1
- package/es/flow/internal/utils/quickEditDataScope.d.ts +48 -0
- package/es/flow/internal/utils/quickEditViewContainer.d.ts +27 -0
- package/es/flow/models/actions/LinkActionUtils.d.ts +1 -0
- package/es/flow/models/actions/getHasManyDeleteFilterByTk.d.ts +12 -0
- package/es/flow/models/base/PageModel/closeGuard.d.ts +8 -1
- package/es/flow/models/blocks/assign-form/assignFormValue.d.ts +29 -0
- package/es/flow/models/blocks/form/EditFormModel.d.ts +2 -0
- package/es/flow/models/blocks/form/QuickEditFormModel.d.ts +1 -0
- package/es/flow/models/blocks/table/TableJSFieldItemModel.d.ts +1 -1
- package/es/flow/models/blocks/table/sortUtils.d.ts +3 -0
- package/es/flow/models/topbar/UserCenterTopbarActionModel.d.ts +2 -0
- package/es/flow/useRouteContentRequest.d.ts +20 -0
- package/es/index.mjs +144 -107
- package/lib/index.js +179 -142
- package/package.json +9 -8
- package/src/BaseApplication.tsx +27 -0
- package/src/RouteRepository.ts +14 -0
- package/src/__tests__/RouteRepository.test.ts +51 -0
- package/src/__tests__/app.test.tsx +13 -0
- package/src/collection-manager/__tests__/field-configure.test.ts +52 -0
- package/src/collection-manager/field-configure.ts +2 -2
- package/src/components/form/ScanInput/CodeScanner.tsx +3 -1
- package/src/components/form/ScanInput/__tests__/CodeScanner.test.tsx +7 -1
- package/src/components/form/ScanInput/__tests__/useCodeScanner.test.tsx +182 -8
- package/src/components/form/ScanInput/__tests__/zxingWasmDecoder.test.ts +78 -0
- package/src/components/form/ScanInput/useCodeScanner.ts +135 -20
- package/src/components/form/ScanInput/zxingWasmDecoder.ts +64 -0
- package/src/components/form/VariableInput.tsx +1 -0
- package/src/flow/FlowModelRepository.ts +47 -1
- package/src/flow/FlowPage.tsx +25 -10
- package/src/flow/__tests__/FlowModelRepository.test.ts +38 -1
- package/src/flow/__tests__/FlowPage.test.tsx +78 -46
- package/src/flow/actions/__tests__/validation.test.ts +48 -0
- package/src/flow/admin-shell/admin-layout/AdminLayoutComponent.tsx +15 -10
- package/src/flow/admin-shell/admin-layout/AdminLayoutEntryGuard.test.tsx +48 -1
- package/src/flow/admin-shell/admin-layout/AdminLayoutEntryGuard.tsx +6 -1
- package/src/flow/admin-shell/admin-layout/AdminLayoutMenuModels.tsx +17 -21
- package/src/flow/admin-shell/admin-layout/AdminLayoutMenuUtils.tsx +1 -0
- package/src/flow/admin-shell/admin-layout/AdminLayoutModel.tsx +34 -0
- package/src/flow/admin-shell/admin-layout/HelpLite.tsx +5 -1
- package/src/flow/admin-shell/admin-layout/MobileTopbarActionsContext.ts +13 -0
- package/src/flow/admin-shell/admin-layout/TopbarActionsBar.tsx +13 -2
- package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutMenuModels.test.ts +146 -0
- package/src/flow/admin-shell/admin-layout/__tests__/TopbarActionsBar.mobile.test.tsx +259 -0
- package/src/flow/admin-shell/admin-layout/__tests__/TopbarActionsBar.test.tsx +39 -0
- package/src/flow/admin-shell/admin-layout/index.ts +1 -0
- package/src/flow/admin-shell/admin-layout/observeAdminMenuRoutes.ts +60 -0
- package/src/flow/components/FieldAssignValueInput.tsx +4 -0
- package/src/flow/components/field-value-variable/FieldValueVariableInput.tsx +21 -12
- package/src/flow/components/field-value-variable/__tests__/FieldValueVariableInput.test.tsx +9 -0
- package/src/flow/components/filter/VariableFilterItem.tsx +14 -4
- package/src/flow/components/filter/__tests__/VariableFilterItem.rightMetaTree.test.tsx +158 -0
- package/src/flow/flows/editMarkdownFlow.tsx +1 -1
- package/src/flow/internal/utils/__tests__/quickEditDataScope.test.ts +156 -0
- package/src/flow/internal/utils/__tests__/quickEditViewContainer.test.ts +52 -0
- package/src/flow/internal/utils/quickEditDataScope.tsx +177 -0
- package/src/flow/internal/utils/quickEditViewContainer.ts +46 -0
- package/src/flow/models/actions/BulkDeleteActionModel.tsx +13 -2
- package/src/flow/models/actions/DeleteActionModel.tsx +16 -2
- package/src/flow/models/actions/JSItemActionModel.tsx +19 -3
- package/src/flow/models/actions/LinkActionModel.tsx +11 -9
- package/src/flow/models/actions/LinkActionUtils.ts +4 -2
- package/src/flow/models/actions/__tests__/DeleteActionModel.test.ts +256 -0
- package/src/flow/models/actions/__tests__/JSItemActionModel.test.tsx +47 -1
- package/src/flow/models/actions/__tests__/LinkActionModel.test.ts +14 -0
- package/src/flow/models/actions/getHasManyDeleteFilterByTk.ts +40 -0
- package/src/flow/models/base/GridModel.tsx +0 -1
- package/src/flow/models/base/PageModel/PageTabModel.tsx +27 -12
- package/src/flow/models/base/PageModel/closeGuard.ts +9 -8
- package/src/flow/models/blocks/assign-form/AssignFormGridModel.tsx +22 -1
- package/src/flow/models/blocks/assign-form/AssignFormItemModel.tsx +40 -12
- package/src/flow/models/blocks/assign-form/__tests__/assignFieldValuesFlow.editor.test.tsx +140 -0
- package/src/flow/models/blocks/assign-form/__tests__/assignFieldValuesFlow.multipleSelect.test.tsx +216 -0
- package/src/flow/models/blocks/assign-form/__tests__/assignFormValue.test.ts +41 -0
- package/src/flow/models/blocks/assign-form/assignFormValue.ts +64 -0
- package/src/flow/models/blocks/details/DetailsItemModel.tsx +62 -1
- package/src/flow/models/blocks/details/__tests__/DetailsItemModel.spacing.test.tsx +77 -0
- package/src/flow/models/blocks/filter-form/__tests__/FilterFormGridModel.toggleFormFieldsCollapse.test.ts +29 -0
- package/src/flow/models/blocks/filter-form/fields/FieldComponentProps.tsx +1 -1
- package/src/flow/models/blocks/filter-form/fields/__tests__/FieldComponentProps.options.test.tsx +61 -0
- package/src/flow/models/blocks/form/EditFormModel.tsx +23 -1
- package/src/flow/models/blocks/form/FormBlockModel.tsx +26 -5
- package/src/flow/models/blocks/form/QuickEditFormModel.tsx +45 -11
- package/src/flow/models/blocks/form/__tests__/EditFormModel.pagination.test.tsx +77 -0
- package/src/flow/models/blocks/form/__tests__/FormBlockModel.test.tsx +145 -0
- package/src/flow/models/blocks/form/__tests__/QuickEditFormModel.quickEdit.test.ts +120 -0
- package/src/flow/models/blocks/form/__tests__/popupLinkage.test.tsx +175 -0
- package/src/flow/models/blocks/js-block/JSBlock.tsx +5 -1
- package/src/flow/models/blocks/js-block/__tests__/JSBlockModel.test.tsx +23 -1
- package/src/flow/models/blocks/table/TableBlockModel.tsx +4 -10
- package/src/flow/models/blocks/table/TableColumnModel.tsx +31 -0
- package/src/flow/models/blocks/table/TableJSFieldItemModel.tsx +11 -3
- package/src/flow/models/blocks/table/__tests__/TableColumnModel.test.tsx +90 -0
- package/src/flow/models/blocks/table/__tests__/sortUtils.test.ts +11 -1
- package/src/flow/models/blocks/table/sortUtils.ts +10 -0
- package/src/flow/models/fields/AssociationFieldModel/CascadeSelectFieldModel.tsx +11 -2
- package/src/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/PopupSubTableFieldModel.tsx +4 -3
- package/src/flow/models/fields/AssociationFieldModel/RecordSelectFieldModel.tsx +13 -1
- package/src/flow/models/fields/AssociationFieldModel/SubTableFieldModel/SubTableColumnModel.tsx +47 -17
- package/src/flow/models/fields/AssociationFieldModel/SubTableFieldModel/SubTableField.tsx +6 -1
- package/src/flow/models/fields/AssociationFieldModel/SubTableFieldModel/__tests__/SubTableColumnModel.largeField.test.tsx +178 -0
- package/src/flow/models/fields/AssociationFieldModel/SubTableFieldModel/__tests__/SubTableField.disabled.test.tsx +90 -0
- package/src/flow/models/fields/AssociationFieldModel/__tests__/RecordSelectFieldModel.quickCreatePopup.test.tsx +183 -0
- package/src/flow/models/fields/AssociationFieldModel/__tests__/associationSelect.search.test.ts +113 -0
- package/src/flow/models/fields/DisplayAssociationField/DisplaySubTableFieldModel.tsx +42 -7
- package/src/flow/models/fields/DisplayAssociationField/__tests__/DisplaySubTableFieldModel.test.tsx +351 -0
- package/src/flow/models/fields/InputFieldModel.tsx +1 -1
- package/src/flow/models/fields/SelectFieldModel.tsx +5 -0
- package/src/flow/models/fields/__tests__/InputFieldModel.test.tsx +16 -0
- package/src/flow/models/fields/__tests__/SelectFieldModel.test.tsx +29 -1
- package/src/flow/models/fields/mobile-components/MobileLazySelect.tsx +1 -0
- package/src/flow/models/fields/mobile-components/__tests__/MobileSelect.test.tsx +20 -0
- package/src/flow/models/topbar/UserCenterTopbarActionModel.tsx +64 -30
- package/src/flow/useRouteContentRequest.tsx +46 -0
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
import { css, cx } from '@emotion/css';
|
|
10
11
|
import {
|
|
11
12
|
Collection,
|
|
12
13
|
DisplayItemModel,
|
|
@@ -14,6 +15,8 @@ import {
|
|
|
14
15
|
FieldModelRenderer,
|
|
15
16
|
FlowModelContext,
|
|
16
17
|
FormItem,
|
|
18
|
+
formItemStyle,
|
|
19
|
+
untracked,
|
|
17
20
|
} from '@nocobase/flow-engine';
|
|
18
21
|
import { get, castArray } from 'lodash';
|
|
19
22
|
import React from 'react';
|
|
@@ -22,6 +25,49 @@ import { DetailsGridModel } from './DetailsGridModel';
|
|
|
22
25
|
import { rebuildFieldSubModel } from '../../../internal/utils/rebuildFieldSubModel';
|
|
23
26
|
import { isToManyAssociationField } from '../../../internal/utils/modelUtils';
|
|
24
27
|
|
|
28
|
+
function mobileHorizontalItemStyle(marginBottom: number) {
|
|
29
|
+
return css`
|
|
30
|
+
&&.ant-form-item {
|
|
31
|
+
margin-bottom: ${formItemStyle.marginBottom}px;
|
|
32
|
+
|
|
33
|
+
@media (max-width: 575px) {
|
|
34
|
+
margin-bottom: ${marginBottom}px;
|
|
35
|
+
min-height: ${32 - marginBottom}px;
|
|
36
|
+
|
|
37
|
+
> .ant-form-item-row > .ant-form-item-label {
|
|
38
|
+
padding-bottom: 0;
|
|
39
|
+
line-height: max(20px, 1.4em);
|
|
40
|
+
|
|
41
|
+
> label {
|
|
42
|
+
height: auto;
|
|
43
|
+
line-height: max(20px, 1.4em);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
> .ant-form-item-row > .ant-form-item-control > .ant-form-item-control-input {
|
|
48
|
+
min-height: 20px;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
`;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const mobileSpacingByBlock = new Map([
|
|
56
|
+
['DetailsBlockModel', mobileHorizontalItemStyle(3)],
|
|
57
|
+
['GridCardBlockModel', mobileHorizontalItemStyle(8)],
|
|
58
|
+
]);
|
|
59
|
+
|
|
60
|
+
const mobilePlainTextStyle = css`
|
|
61
|
+
@media (max-width: 575px) {
|
|
62
|
+
> .ant-form-item-row
|
|
63
|
+
> .ant-form-item-control
|
|
64
|
+
> .ant-form-item-control-input
|
|
65
|
+
> .ant-form-item-control-input-content {
|
|
66
|
+
line-height: max(20px, 1.4em);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
`;
|
|
70
|
+
|
|
25
71
|
/**
|
|
26
72
|
* 从 record 中取值
|
|
27
73
|
* @param record 当前行数据
|
|
@@ -217,8 +263,23 @@ export class DetailsItemModel extends DisplayItemModel<{
|
|
|
217
263
|
idx,
|
|
218
264
|
}),
|
|
219
265
|
);
|
|
266
|
+
const spacing =
|
|
267
|
+
this.context.isMobileLayout && mergedProps.layout === 'horizontal'
|
|
268
|
+
? mobileSpacingByBlock.get(this.context.blockModel.use)
|
|
269
|
+
: undefined;
|
|
270
|
+
const isPlainText =
|
|
271
|
+
spacing &&
|
|
272
|
+
modelForRender?.use === 'DisplayTextFieldModel' &&
|
|
273
|
+
(mergedProps.displayStyle ??
|
|
274
|
+
fieldModel.getStepParams('displayFieldSettings', 'displayStyle')?.displayStyle ??
|
|
275
|
+
// FieldModelRenderer writes back fork props after rendering. Subscribing here would render the item again.
|
|
276
|
+
untracked(() => modelForRender.props.displayStyle)) !== 'tag';
|
|
220
277
|
return (
|
|
221
|
-
<FormItem
|
|
278
|
+
<FormItem
|
|
279
|
+
{...mergedProps}
|
|
280
|
+
itemMarginClassName={spacing && cx(spacing, isPlainText && mobilePlainTextStyle)}
|
|
281
|
+
value={value}
|
|
282
|
+
>
|
|
222
283
|
<FieldModelRenderer model={modelForRender} />
|
|
223
284
|
</FormItem>
|
|
224
285
|
);
|
|
@@ -0,0 +1,77 @@
|
|
|
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, FlowModel, Tracker } from '@nocobase/flow-engine';
|
|
11
|
+
import { render } from '@testing-library/react';
|
|
12
|
+
import React from 'react';
|
|
13
|
+
import { expect, it, vi } from 'vitest';
|
|
14
|
+
import { DetailsItemModel } from '../DetailsItemModel';
|
|
15
|
+
|
|
16
|
+
it.each([
|
|
17
|
+
['DetailsBlockModel', true, 'horizontal', 'DisplayTextFieldModel', 'text', '3px', '29px', true],
|
|
18
|
+
['GridCardBlockModel', true, 'horizontal', 'DisplayTextFieldModel', 'text', '8px', '24px', true],
|
|
19
|
+
['GridCardBlockModel', true, 'horizontal', 'DisplayTextFieldModel', 'tag', '8px', '24px', false],
|
|
20
|
+
['DetailsBlockModel', true, 'horizontal', 'DisplayHtmlFieldModel', 'text', '3px', '29px', false],
|
|
21
|
+
['CCTaskCardDetailsModel', true, 'horizontal', 'DisplayTextFieldModel', 'text', '', '', false],
|
|
22
|
+
['DetailsBlockModel', false, 'horizontal', 'DisplayTextFieldModel', 'text', '', '', false],
|
|
23
|
+
['GridCardBlockModel', true, 'vertical', 'DisplayTextFieldModel', 'text', '', '', false],
|
|
24
|
+
] as const)(
|
|
25
|
+
'selects phone styles for %s, mobile=%s, %s, %s (%s)',
|
|
26
|
+
(block, mobile, layout, field, displayStyle, margin, minHeight, plainText) => {
|
|
27
|
+
const engine = new FlowEngine();
|
|
28
|
+
engine.registerModels({ [field]: FlowModel });
|
|
29
|
+
const model = new DetailsItemModel({ uid: 'detail-field', flowEngine: engine });
|
|
30
|
+
model.context.defineProperty('blockModel', { value: { use: block, props: { layout } } });
|
|
31
|
+
model.context.defineProperty('isMobileLayout', { value: mobile });
|
|
32
|
+
model.setProps('label', 'Name');
|
|
33
|
+
model.setStepParams('fieldSettings', 'init', { fieldPath: 'name' });
|
|
34
|
+
model.setSubModel('field', { use: field, props: { displayStyle } });
|
|
35
|
+
|
|
36
|
+
const { container } = render(React.cloneElement(model.renderItem(), {}, <span>Value</span>));
|
|
37
|
+
const item = container.querySelector<HTMLElement>('.ant-form-item');
|
|
38
|
+
const value = item.querySelector('.ant-form-item-control-input-content');
|
|
39
|
+
const rules = Array.from(document.styleSheets).flatMap((sheet) => Array.from(sheet.cssRules));
|
|
40
|
+
const narrowRules = rules.flatMap((rule) =>
|
|
41
|
+
rule instanceof CSSMediaRule && rule.conditionText === '(max-width: 575px)' ? Array.from(rule.cssRules) : [],
|
|
42
|
+
);
|
|
43
|
+
const declarations = (element: Element, property: string) =>
|
|
44
|
+
narrowRules
|
|
45
|
+
.flatMap((rule) =>
|
|
46
|
+
rule instanceof CSSStyleRule && element.matches(rule.selectorText)
|
|
47
|
+
? [rule.style.getPropertyValue(property)]
|
|
48
|
+
: [],
|
|
49
|
+
)
|
|
50
|
+
.filter(Boolean);
|
|
51
|
+
|
|
52
|
+
expect(item.style.marginBottom).toBe(margin ? '' : '12px');
|
|
53
|
+
expect(declarations(item, 'margin-bottom')).toEqual(margin ? [margin] : []);
|
|
54
|
+
expect(declarations(item, 'min-height')).toEqual(minHeight ? [minHeight] : []);
|
|
55
|
+
expect(declarations(value, 'line-height')).toEqual(plainText ? ['max(20px, 1.4em)'] : []);
|
|
56
|
+
},
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
it('does not subscribe the grid card item to field renderer prop writes', () => {
|
|
60
|
+
const engine = new FlowEngine();
|
|
61
|
+
engine.registerModels({ DisplayTextFieldModel: FlowModel });
|
|
62
|
+
const item = new DetailsItemModel({ uid: 'card-field', flowEngine: engine });
|
|
63
|
+
item.context.defineProperty('blockModel', { value: { use: 'GridCardBlockModel', props: { layout: 'horizontal' } } });
|
|
64
|
+
item.context.defineProperty('isMobileLayout', { value: true });
|
|
65
|
+
item.context.defineProperty('fieldIndex', { value: 0 });
|
|
66
|
+
item.setStepParams('fieldSettings', 'init', { fieldPath: 'name' });
|
|
67
|
+
const field = item.setSubModel('field', { use: 'DisplayTextFieldModel' });
|
|
68
|
+
const invalidate = vi.fn();
|
|
69
|
+
const tracker = new Tracker(invalidate);
|
|
70
|
+
try {
|
|
71
|
+
tracker.track(() => item.renderItem());
|
|
72
|
+
field.getFork('0').setProps({ value: 'First row' });
|
|
73
|
+
expect(invalidate).not.toHaveBeenCalled();
|
|
74
|
+
} finally {
|
|
75
|
+
tracker.dispose();
|
|
76
|
+
}
|
|
77
|
+
});
|
|
@@ -21,6 +21,35 @@ describe('FilterFormGridModel.toggleFormFieldsCollapse', () => {
|
|
|
21
21
|
engine.registerModels({ FilterFormGridModel });
|
|
22
22
|
});
|
|
23
23
|
|
|
24
|
+
it.each([false, true])('preserves collapsed fields in mobile layout with settings enabled: %s', (settingsEnabled) => {
|
|
25
|
+
engine.flowSettings[settingsEnabled ? 'enable' : 'disable']();
|
|
26
|
+
const rows = {
|
|
27
|
+
first: [['field-1']],
|
|
28
|
+
second: [['field-2']],
|
|
29
|
+
third: [['field-3']],
|
|
30
|
+
};
|
|
31
|
+
const model = engine.createModel<FilterFormGridModel>({
|
|
32
|
+
uid: 'mobile-filter-grid',
|
|
33
|
+
use: 'FilterFormGridModel',
|
|
34
|
+
props: { rows },
|
|
35
|
+
subModels: {
|
|
36
|
+
items: ['field-1', 'field-2', 'field-3'].map((uid) => ({ use: 'FlowModel', uid })),
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
model.context.defineProperty('isMobileLayout', { value: true });
|
|
40
|
+
model.setStepParams(GRID_FLOW_KEY, GRID_STEP, { rows });
|
|
41
|
+
type VisibleLayoutReader = { getVisibleLayout(): { rows: Record<string, string[][]> } };
|
|
42
|
+
const renderedItems = () =>
|
|
43
|
+
Object.values((model as unknown as VisibleLayoutReader).getVisibleLayout().rows).flat(2);
|
|
44
|
+
|
|
45
|
+
expect(renderedItems()).toEqual(['field-1', 'field-2', 'field-3']);
|
|
46
|
+
model.toggleFormFieldsCollapse(true, 1);
|
|
47
|
+
expect(renderedItems()).toEqual(['field-1']);
|
|
48
|
+
model.toggleFormFieldsCollapse(false, 1);
|
|
49
|
+
expect(renderedItems()).toEqual(['field-1', 'field-2', 'field-3']);
|
|
50
|
+
expect(model.getStepParams(GRID_FLOW_KEY, GRID_STEP).rows).toEqual(rows);
|
|
51
|
+
});
|
|
52
|
+
|
|
24
53
|
it('uses rowOrder from the full layout when collapsing after reorder', () => {
|
|
25
54
|
const model = engine.createModel<FilterFormGridModel>({
|
|
26
55
|
uid: 'filter-grid-collapse-order',
|
|
@@ -351,7 +351,7 @@ export const FieldComponentProps: React.FC<{ fieldModel: string; source: string[
|
|
|
351
351
|
<FormItem label={t('Options')}>
|
|
352
352
|
<Space direction="vertical" size={8} style={{ width: '100%' }}>
|
|
353
353
|
{options.map((option: any, index: number) => (
|
|
354
|
-
<Space key={
|
|
354
|
+
<Space key={index} style={{ width: '100%' }} size={8} wrap align="start">
|
|
355
355
|
<Input
|
|
356
356
|
style={{ flex: 1, minWidth: 120 }}
|
|
357
357
|
placeholder={t('Option label')}
|
package/src/flow/models/blocks/filter-form/fields/__tests__/FieldComponentProps.options.test.tsx
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
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 React from 'react';
|
|
11
|
+
import { describe, expect, it } from 'vitest';
|
|
12
|
+
import { createForm } from '@formily/core';
|
|
13
|
+
import { Field, FormProvider } from '@formily/react';
|
|
14
|
+
import { render, screen } from '@nocobase/test/client';
|
|
15
|
+
import userEvent from '@testing-library/user-event';
|
|
16
|
+
import { FlowEngine, FlowEngineProvider, FlowModel, FlowModelProvider } from '@nocobase/flow-engine';
|
|
17
|
+
import { FieldComponentProps } from '../FieldComponentProps';
|
|
18
|
+
|
|
19
|
+
class HostModel extends FlowModel {
|
|
20
|
+
render() {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
describe.each(['RadioGroupFieldModel', 'CheckboxGroupFieldModel', 'SelectFieldModel'])('%s options', (fieldModel) => {
|
|
26
|
+
it('keeps focus while editing option values and preserves remaining rows after removal', async () => {
|
|
27
|
+
const form = createForm();
|
|
28
|
+
const engine = new FlowEngine();
|
|
29
|
+
engine.registerModels({ HostModel });
|
|
30
|
+
const model = engine.createModel<HostModel>({ use: 'HostModel' });
|
|
31
|
+
render(
|
|
32
|
+
<FlowEngineProvider engine={engine}>
|
|
33
|
+
<FlowModelProvider model={model}>
|
|
34
|
+
<FormProvider form={form}>
|
|
35
|
+
<Field name="props" component={[FieldComponentProps, { fieldModel, source: [] }]} />
|
|
36
|
+
</FormProvider>
|
|
37
|
+
</FlowModelProvider>
|
|
38
|
+
</FlowEngineProvider>,
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
await userEvent.click(screen.getByRole('button', { name: 'plus Add' }));
|
|
42
|
+
const valueInput = screen.getByPlaceholderText('Option value');
|
|
43
|
+
await userEvent.type(valueInput, 'abcdef');
|
|
44
|
+
expect(screen.getByPlaceholderText('Option value')).toHaveValue('abcdef');
|
|
45
|
+
expect(valueInput).toHaveFocus();
|
|
46
|
+
|
|
47
|
+
await userEvent.keyboard('{Backspace}{Backspace}xy');
|
|
48
|
+
expect(valueInput).toHaveValue('abcdxy');
|
|
49
|
+
expect(valueInput).toHaveFocus();
|
|
50
|
+
await userEvent.type(screen.getByPlaceholderText('Option label'), 'First');
|
|
51
|
+
await userEvent.click(screen.getByRole('button', { name: 'plus Add' }));
|
|
52
|
+
await userEvent.type(screen.getAllByPlaceholderText('Option label')[1], 'Second');
|
|
53
|
+
await userEvent.type(screen.getAllByPlaceholderText('Option value')[1], 'second');
|
|
54
|
+
await userEvent.click(screen.getAllByRole('button', { name: 'close' })[0]);
|
|
55
|
+
expect(screen.getByPlaceholderText('Option label')).toHaveValue('Second');
|
|
56
|
+
expect(screen.getByPlaceholderText('Option value')).toHaveValue('second');
|
|
57
|
+
await userEvent.type(screen.getByPlaceholderText('Option value'), '2');
|
|
58
|
+
expect(screen.getByPlaceholderText('Option value')).toHaveFocus();
|
|
59
|
+
expect(form.values.props.options).toEqual([{ label: 'Second', value: 'second2' }]);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
FlowModelRenderer,
|
|
17
17
|
MemoFlowModelRenderer,
|
|
18
18
|
MultiRecordResource,
|
|
19
|
+
observable,
|
|
19
20
|
SingleRecordResource,
|
|
20
21
|
} from '@nocobase/flow-engine';
|
|
21
22
|
import { Pagination, Space } from 'antd';
|
|
@@ -23,12 +24,14 @@ import { isEqual } from 'lodash';
|
|
|
23
24
|
import React from 'react';
|
|
24
25
|
import { BlockSceneEnum } from '../../base/BlockModel';
|
|
25
26
|
import { FormBlockContent, FormBlockModel } from './FormBlockModel';
|
|
27
|
+
import { confirmDiscardChanges } from '../../base/PageModel/closeGuard';
|
|
26
28
|
import { dispatchEventDeep } from '../../../utils';
|
|
27
29
|
|
|
28
30
|
export class EditFormModel extends FormBlockModel {
|
|
29
31
|
static scene = BlockSceneEnum.oam;
|
|
30
32
|
static blockCapabilityActionName = 'update';
|
|
31
33
|
|
|
34
|
+
private readonly confirmingPageChange = observable.ref(false);
|
|
32
35
|
private actionFlowSettings = { showBackground: false, showBorder: false, toolbarPosition: 'above' as const };
|
|
33
36
|
private actionExtraToolbarItems = [
|
|
34
37
|
{
|
|
@@ -71,9 +74,26 @@ export class EditFormModel extends FormBlockModel {
|
|
|
71
74
|
getAclActionName() {
|
|
72
75
|
return 'update';
|
|
73
76
|
}
|
|
77
|
+
|
|
78
|
+
private hasUnsavedChanges = () => {
|
|
79
|
+
const record = this.getCurrentRecord();
|
|
80
|
+
return Array.from(this.getUserModifiedFields()).some(
|
|
81
|
+
(field) => !isEqual(this.form.getFieldValue(field), record?.[field]),
|
|
82
|
+
);
|
|
83
|
+
};
|
|
84
|
+
|
|
74
85
|
handlePageChange = async (page: number) => {
|
|
75
86
|
if (this.resource instanceof MultiRecordResource) {
|
|
76
87
|
const multiResource = this.resource as MultiRecordResource;
|
|
88
|
+
if (page === multiResource.getPage() || this.confirmingPageChange.value) return;
|
|
89
|
+
if (this.hasUnsavedChanges()) {
|
|
90
|
+
this.confirmingPageChange.value = true;
|
|
91
|
+
try {
|
|
92
|
+
if (!(await confirmDiscardChanges(this.context))) return;
|
|
93
|
+
} finally {
|
|
94
|
+
this.confirmingPageChange.value = false;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
77
97
|
multiResource.setPage(page);
|
|
78
98
|
multiResource.loading = true;
|
|
79
99
|
await multiResource.refresh();
|
|
@@ -116,10 +136,12 @@ export class EditFormModel extends FormBlockModel {
|
|
|
116
136
|
}}
|
|
117
137
|
>
|
|
118
138
|
<Pagination
|
|
139
|
+
// Simple pagination keeps its own editable page number. Reset it while confirming the switch.
|
|
140
|
+
key={this.confirmingPageChange.value ? 'confirming' : 'editing'}
|
|
119
141
|
simple
|
|
120
142
|
pageSize={1}
|
|
121
143
|
showSizeChanger={false}
|
|
122
|
-
|
|
144
|
+
current={(this.resource as MultiRecordResource).getPage()}
|
|
123
145
|
total={(this.resource as MultiRecordResource).getTotalPage()}
|
|
124
146
|
onChange={this.handlePageChange}
|
|
125
147
|
style={{ display: 'inline-block' }}
|
|
@@ -399,20 +399,41 @@ export class FormBlockModel<
|
|
|
399
399
|
if (Array.isArray(topValue) && topValue.length === 0) return false;
|
|
400
400
|
|
|
401
401
|
// 本地优先:支持对多关系的 dot 聚合路径(例如 assignees.name)。
|
|
402
|
-
//
|
|
403
|
-
// 因而这里先用 getValuesByPath 做一次前端可解析性检查,命中则直接前端解析。
|
|
402
|
+
// 关联字段只有在本地值包含目标标题字段时才算完整;标量外键或仅含主键的轻量对象仍需服务端补全。
|
|
404
403
|
const formValuesSnapshot = runtime.getFormValuesSnapshot();
|
|
404
|
+
let shouldResolveAssociationValueOnServer = false;
|
|
405
405
|
if (formValuesSnapshot && typeof formValuesSnapshot === 'object') {
|
|
406
|
-
const localResolved = getValuesByPath(formValuesSnapshot as Record<string,
|
|
406
|
+
const localResolved = getValuesByPath(formValuesSnapshot as Record<string, unknown>, subPath);
|
|
407
407
|
if (typeof localResolved !== 'undefined') {
|
|
408
|
-
|
|
408
|
+
const fieldPath = subPath
|
|
409
|
+
.replace(/\[\d+\]/g, '')
|
|
410
|
+
.split('.')
|
|
411
|
+
.filter((segment) => !/^\d+$/.test(segment))
|
|
412
|
+
.join('.');
|
|
413
|
+
const resolvedField = this.collection?.getFieldByPath?.(fieldPath);
|
|
414
|
+
const titleFieldName = resolvedField?.targetCollectionTitleFieldName;
|
|
415
|
+
const isLoadedAssociationRecord = (value: unknown) => {
|
|
416
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return false;
|
|
417
|
+
if (!titleFieldName) return true;
|
|
418
|
+
return typeof (value as Record<string, unknown>)[titleFieldName] !== 'undefined';
|
|
419
|
+
};
|
|
420
|
+
const isAssociationValueLoaded =
|
|
421
|
+
localResolved === null ||
|
|
422
|
+
(Array.isArray(localResolved)
|
|
423
|
+
? localResolved.length === 0 ||
|
|
424
|
+
localResolved.every((value) => value === null || isLoadedAssociationRecord(value))
|
|
425
|
+
: isLoadedAssociationRecord(localResolved));
|
|
426
|
+
if (!resolvedField?.isAssociationField?.() || isAssociationValueLoaded) {
|
|
427
|
+
return false;
|
|
428
|
+
}
|
|
429
|
+
shouldResolveAssociationValueOnServer = true;
|
|
409
430
|
}
|
|
410
431
|
}
|
|
411
432
|
|
|
412
433
|
// 已配置字段:仅关联字段的子路径按需服务端补全(保持现有语义)
|
|
413
434
|
const assocResolver = createAssociationSubpathResolver(
|
|
414
435
|
() => this.collection,
|
|
415
|
-
() => runtime.getFormValuesSnapshot(),
|
|
436
|
+
shouldResolveAssociationValueOnServer ? undefined : () => runtime.getFormValuesSnapshot(),
|
|
416
437
|
);
|
|
417
438
|
return assocResolver(subPath);
|
|
418
439
|
}
|
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
} from '@nocobase/flow-engine';
|
|
24
24
|
import { Button, Form, Skeleton, Space } from 'antd';
|
|
25
25
|
import React from 'react';
|
|
26
|
+
import { findDataScopeStep, getQuickEditDataScopeFilter } from '../../../internal/utils/quickEditDataScope';
|
|
26
27
|
import { FieldModel } from '../../base/FieldModel';
|
|
27
28
|
import { FormComponent } from './FormBlockModel';
|
|
28
29
|
import { FormItemModel } from './FormItemModel';
|
|
@@ -36,6 +37,14 @@ const QUICK_EDIT_MOBILE_CONTENT_PADDING = '8px var(--nb-mobile-page-tabs-content
|
|
|
36
37
|
const QUICK_EDIT_MOBILE_ACTIONS_PADDING =
|
|
37
38
|
'8px var(--nb-mobile-page-tabs-content-padding, 12px) calc(80px + env(safe-area-inset-bottom, 0px))';
|
|
38
39
|
const QUICK_EDIT_MOBILE_MEDIA_QUERY = '(max-width: 768px)';
|
|
40
|
+
// Dropdown-style editors open upwards inside the desktop popover so the option list does not cover the Submit and
|
|
41
|
+
// Cancel buttons rendered right below the field. antd still flips the list downwards when there is no room above.
|
|
42
|
+
const QUICK_EDIT_DROPDOWN_UP_MODELS = [
|
|
43
|
+
'SelectFieldModel',
|
|
44
|
+
'RecordSelectFieldModel',
|
|
45
|
+
'CascadeSelectFieldModel',
|
|
46
|
+
'CascadeSelectListFieldModel',
|
|
47
|
+
];
|
|
39
48
|
|
|
40
49
|
type QuickEditViewBeforeClosePayload = {
|
|
41
50
|
result?: unknown;
|
|
@@ -159,6 +168,7 @@ export class QuickEditFormModel extends FlowModel {
|
|
|
159
168
|
__onSubmitSuccess;
|
|
160
169
|
_fieldProps: any;
|
|
161
170
|
_onOk: any;
|
|
171
|
+
_dataScopeFilter: Record<string, any> | undefined;
|
|
162
172
|
|
|
163
173
|
get form() {
|
|
164
174
|
return this.context.form;
|
|
@@ -212,6 +222,7 @@ export class QuickEditFormModel extends FlowModel {
|
|
|
212
222
|
},
|
|
213
223
|
sourceFieldModel ? { delegate: sourceFieldModel.context } : undefined,
|
|
214
224
|
) as QuickEditFormModel;
|
|
225
|
+
model._dataScopeFilter = getQuickEditDataScopeFilter(sourceFieldModel);
|
|
215
226
|
|
|
216
227
|
const bodyStyles = {
|
|
217
228
|
maxHeight: QUICK_EDIT_POPOVER_MAX_HEIGHT,
|
|
@@ -410,6 +421,13 @@ QuickEditFormModel.registerFlow({
|
|
|
410
421
|
resource.setDataSourceKey(dataSourceKey);
|
|
411
422
|
resource.setResourceName(collectionName);
|
|
412
423
|
ctx.model.resource = resource;
|
|
424
|
+
// Seed the edited row before dispatching the field model's flows. An association data scope resolves
|
|
425
|
+
// `ctx.record` while the field renders, and so does the foreign key filter that one-to-one and one-to-many
|
|
426
|
+
// editors build, so the record has to be in place first.
|
|
427
|
+
if (ctx.inputArgs.filterByTk || ctx.inputArgs.record) {
|
|
428
|
+
resource.setFilterByTk(ctx.inputArgs.filterByTk);
|
|
429
|
+
resource.setData(ctx.inputArgs.record);
|
|
430
|
+
}
|
|
413
431
|
const collectionField = ctx.model.collection.getField(fieldPath) as CollectionField;
|
|
414
432
|
if (collectionField) {
|
|
415
433
|
const binding = FormItemModel.getDefaultBindingByField(ctx, collectionField);
|
|
@@ -417,24 +435,42 @@ QuickEditFormModel.registerFlow({
|
|
|
417
435
|
return;
|
|
418
436
|
}
|
|
419
437
|
const use = binding.modelName;
|
|
438
|
+
const stepParams: Record<string, Record<string, Record<string, unknown>>> = {
|
|
439
|
+
fieldSettings: {
|
|
440
|
+
init: {
|
|
441
|
+
dataSourceKey,
|
|
442
|
+
collectionName,
|
|
443
|
+
fieldPath,
|
|
444
|
+
},
|
|
445
|
+
},
|
|
446
|
+
};
|
|
447
|
+
const dataScopeFilter = ctx.model._dataScopeFilter;
|
|
448
|
+
if (dataScopeFilter) {
|
|
449
|
+
const dataScopeStep = findDataScopeStep(ctx.engine.getModelClass(use));
|
|
450
|
+
if (dataScopeStep) {
|
|
451
|
+
stepParams[dataScopeStep.flowKey] = {
|
|
452
|
+
...stepParams[dataScopeStep.flowKey],
|
|
453
|
+
[dataScopeStep.stepKey]: { filter: dataScopeFilter },
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
}
|
|
420
457
|
const fieldModel = ctx.model.addSubModel<FieldModel>('fields', {
|
|
421
458
|
use,
|
|
422
459
|
props:
|
|
423
460
|
typeof binding.defaultProps === 'function'
|
|
424
461
|
? binding.defaultProps(ctx, collectionField)
|
|
425
462
|
: binding.defaultProps,
|
|
426
|
-
stepParams
|
|
427
|
-
fieldSettings: {
|
|
428
|
-
init: {
|
|
429
|
-
dataSourceKey,
|
|
430
|
-
collectionName,
|
|
431
|
-
fieldPath,
|
|
432
|
-
},
|
|
433
|
-
},
|
|
434
|
-
},
|
|
463
|
+
stepParams,
|
|
435
464
|
});
|
|
436
465
|
fieldModel.setProps(getQuickEditFieldProps(collectionField, ctx.model._fieldProps));
|
|
437
466
|
fieldModel.setProps({ sourceFieldModelUid: ctx.inputArgs.sourceFieldModelUid });
|
|
467
|
+
if (
|
|
468
|
+
!ctx.model.context.isMobileLayout &&
|
|
469
|
+
QUICK_EDIT_DROPDOWN_UP_MODELS.includes(use) &&
|
|
470
|
+
fieldModel.props.placement == null
|
|
471
|
+
) {
|
|
472
|
+
fieldModel.setProps({ placement: 'topLeft' });
|
|
473
|
+
}
|
|
438
474
|
ctx.model.context.defineProperty('collectionField', {
|
|
439
475
|
get: () => collectionField,
|
|
440
476
|
});
|
|
@@ -442,8 +478,6 @@ QuickEditFormModel.registerFlow({
|
|
|
442
478
|
await fieldModel.dispatchEvent('beforeRender');
|
|
443
479
|
}
|
|
444
480
|
if (ctx.inputArgs.filterByTk || ctx.inputArgs.record) {
|
|
445
|
-
resource.setFilterByTk(ctx.inputArgs.filterByTk);
|
|
446
|
-
resource.setData(ctx.inputArgs.record);
|
|
447
481
|
ctx.model.form?.setFieldsValue(resource.getData());
|
|
448
482
|
}
|
|
449
483
|
},
|
|
@@ -0,0 +1,77 @@
|
|
|
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, MultiRecordResource, observer } from '@nocobase/flow-engine';
|
|
11
|
+
import { fireEvent, render, screen, waitFor, within } from '@testing-library/react';
|
|
12
|
+
import { Form, Input, Modal } from 'antd';
|
|
13
|
+
import React from 'react';
|
|
14
|
+
import { expect, it, vi } from 'vitest';
|
|
15
|
+
import { EditFormModel } from '../EditFormModel';
|
|
16
|
+
|
|
17
|
+
it('keeps the visible page and edits on cancel and loads the next record on confirm', async () => {
|
|
18
|
+
const records = [{ name: 'Record B' }, { name: 'Record A' }];
|
|
19
|
+
const model = new EditFormModel({ uid: 'edit', flowEngine: new FlowEngine() });
|
|
20
|
+
const resource = new MultiRecordResource(model.context);
|
|
21
|
+
resource.setPage(1).setPageSize(1).setMeta({ count: 2, totalPage: 2 }).setData([records[0]]);
|
|
22
|
+
model.context.defineProperty('resource', { value: resource });
|
|
23
|
+
model.context.defineProperty('record', { get: () => model.getCurrentRecord() });
|
|
24
|
+
const refresh = vi.spyOn(resource, 'refresh').mockImplementation(async () => {
|
|
25
|
+
const record = records[resource.getPage() - 1];
|
|
26
|
+
resource.setData([record]);
|
|
27
|
+
model.form.setFieldsValue(record);
|
|
28
|
+
model.resetUserModifiedFields();
|
|
29
|
+
resource.loading = false;
|
|
30
|
+
});
|
|
31
|
+
const Editor = observer(() => {
|
|
32
|
+
const [form] = Form.useForm();
|
|
33
|
+
const [modal, dialogs] = Modal.useModal();
|
|
34
|
+
model.context.defineProperty('form', { value: form });
|
|
35
|
+
model.context.defineProperty('modal', { value: modal });
|
|
36
|
+
const block = model.renderComponent();
|
|
37
|
+
return (
|
|
38
|
+
<>
|
|
39
|
+
{dialogs}
|
|
40
|
+
{React.cloneElement(block, {
|
|
41
|
+
grid: (
|
|
42
|
+
<Form.Item name="name" label="Name">
|
|
43
|
+
<Input />
|
|
44
|
+
</Form.Item>
|
|
45
|
+
),
|
|
46
|
+
actions: null,
|
|
47
|
+
})}
|
|
48
|
+
</>
|
|
49
|
+
);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const { container } = render(<Editor />);
|
|
53
|
+
const field = screen.getByRole('textbox', { name: 'Name' });
|
|
54
|
+
const pageInput = () => screen.getByRole('textbox', { name: 'Go to' });
|
|
55
|
+
const nextPage = () => fireEvent.click(container.querySelector('.ant-pagination-next button'));
|
|
56
|
+
expect(field).toHaveValue('Record B');
|
|
57
|
+
fireEvent.change(field, { target: { value: 'unsaved draft' } });
|
|
58
|
+
nextPage();
|
|
59
|
+
const dialog = await screen.findByRole('dialog');
|
|
60
|
+
expect(dialog).toHaveTextContent('Unsaved changes');
|
|
61
|
+
expect(pageInput()).toHaveValue('1');
|
|
62
|
+
fireEvent.click(within(dialog).getByText('Cancel'));
|
|
63
|
+
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull());
|
|
64
|
+
expect(pageInput()).toHaveValue('1');
|
|
65
|
+
expect(field).toHaveValue('unsaved draft');
|
|
66
|
+
expect(refresh).not.toHaveBeenCalled();
|
|
67
|
+
|
|
68
|
+
nextPage();
|
|
69
|
+
fireEvent.click(within(await screen.findByRole('dialog')).getByText('Confirm'));
|
|
70
|
+
await waitFor(() => expect(field).toHaveValue('Record A'));
|
|
71
|
+
expect(pageInput()).toHaveValue('2');
|
|
72
|
+
expect(refresh).toHaveBeenCalledTimes(1);
|
|
73
|
+
|
|
74
|
+
fireEvent.click(container.querySelector('.ant-pagination-prev button'));
|
|
75
|
+
await waitFor(() => expect(field).toHaveValue('Record B'));
|
|
76
|
+
expect(pageInput()).toHaveValue('1');
|
|
77
|
+
});
|