@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
|
@@ -0,0 +1,43 @@
|
|
|
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 { SelectFieldModel } from '../SelectFieldModel';
|
|
13
|
+
|
|
14
|
+
function mockT(text: string) {
|
|
15
|
+
if (text === '{{t("Yes")}}') return '是';
|
|
16
|
+
if (text === '{{t("No")}}') return '否';
|
|
17
|
+
return text;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
describe('SelectFieldModel', () => {
|
|
21
|
+
it('translates enum fallback labels for selected values', () => {
|
|
22
|
+
const model = {
|
|
23
|
+
props: {
|
|
24
|
+
value: true,
|
|
25
|
+
},
|
|
26
|
+
context: {
|
|
27
|
+
collectionField: {
|
|
28
|
+
uiSchema: {
|
|
29
|
+
enum: [
|
|
30
|
+
{ label: '{{t("Yes")}}', value: true },
|
|
31
|
+
{ label: '{{t("No")}}', value: false },
|
|
32
|
+
],
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
translate: mockT,
|
|
37
|
+
} as unknown as SelectFieldModel;
|
|
38
|
+
|
|
39
|
+
const element = SelectFieldModel.prototype.render.call(model) as React.ReactElement;
|
|
40
|
+
|
|
41
|
+
expect(element.props.value).toEqual({ label: '是', value: true });
|
|
42
|
+
});
|
|
43
|
+
});
|
|
@@ -0,0 +1,100 @@
|
|
|
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 { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
|
12
|
+
import React from 'react';
|
|
13
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
14
|
+
import { TextareaFieldModel } from '../TextareaFieldModel';
|
|
15
|
+
|
|
16
|
+
function createTextareaFieldModel(props?: Record<string, unknown>) {
|
|
17
|
+
const engine = new FlowEngine();
|
|
18
|
+
return new TextareaFieldModel({
|
|
19
|
+
uid: 'textarea-field-model-test',
|
|
20
|
+
flowEngine: engine,
|
|
21
|
+
props,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
describe('TextareaFieldModel', () => {
|
|
26
|
+
it('keeps IME composition text visible before the parent value is committed', () => {
|
|
27
|
+
const onChange = vi.fn();
|
|
28
|
+
const onCompositionStart = vi.fn();
|
|
29
|
+
const onCompositionEnd = vi.fn();
|
|
30
|
+
const model = createTextareaFieldModel({
|
|
31
|
+
value: '',
|
|
32
|
+
onChange,
|
|
33
|
+
onCompositionStart,
|
|
34
|
+
onCompositionEnd,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
render(<>{model.render()}</>);
|
|
38
|
+
|
|
39
|
+
const textarea = screen.getByRole('textbox') as HTMLTextAreaElement;
|
|
40
|
+
|
|
41
|
+
fireEvent.compositionStart(textarea);
|
|
42
|
+
fireEvent.change(textarea, { target: { value: 'ni' }, nativeEvent: { isComposing: true } });
|
|
43
|
+
|
|
44
|
+
expect(textarea.value).toBe('ni');
|
|
45
|
+
expect(onChange).toHaveBeenCalledTimes(1);
|
|
46
|
+
expect(onCompositionStart).toHaveBeenCalledTimes(1);
|
|
47
|
+
|
|
48
|
+
fireEvent.compositionEnd(textarea, { target: { value: '你' } });
|
|
49
|
+
|
|
50
|
+
expect(textarea.value).toBe('你');
|
|
51
|
+
expect(onCompositionEnd).toHaveBeenCalledTimes(1);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('does not overwrite in-progress DOM input with a stale parent value', async () => {
|
|
55
|
+
const onChange = vi.fn();
|
|
56
|
+
const createModel = (value: string) =>
|
|
57
|
+
createTextareaFieldModel({
|
|
58
|
+
value,
|
|
59
|
+
onChange,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const { rerender } = render(<>{createModel('').render()}</>);
|
|
63
|
+
const textarea = screen.getByRole('textbox') as HTMLTextAreaElement;
|
|
64
|
+
|
|
65
|
+
fireEvent.change(textarea, { target: { value: 'té' } });
|
|
66
|
+
rerender(<>{createModel('').render()}</>);
|
|
67
|
+
|
|
68
|
+
expect(textarea.value).toBe('té');
|
|
69
|
+
|
|
70
|
+
rerender(<>{createModel('reset').render()}</>);
|
|
71
|
+
|
|
72
|
+
await waitFor(() => {
|
|
73
|
+
expect((screen.getByRole('textbox') as HTMLTextAreaElement).value).toBe('reset');
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('keeps replacement-style Vietnamese IME edits in the DOM', () => {
|
|
78
|
+
const onChange = vi.fn();
|
|
79
|
+
const createModel = (value: string) =>
|
|
80
|
+
createTextareaFieldModel({
|
|
81
|
+
value,
|
|
82
|
+
onChange,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const { rerender } = render(<>{createModel('').render()}</>);
|
|
86
|
+
const textarea = screen.getByRole('textbox') as HTMLTextAreaElement;
|
|
87
|
+
|
|
88
|
+
fireEvent.change(textarea, { target: { value: 'te' } });
|
|
89
|
+
rerender(<>{createModel('te').render()}</>);
|
|
90
|
+
expect(textarea.value).toBe('te');
|
|
91
|
+
|
|
92
|
+
fireEvent.change(textarea, { target: { value: 'té' } });
|
|
93
|
+
rerender(<>{createModel('te').render()}</>);
|
|
94
|
+
expect(textarea.value).toBe('té');
|
|
95
|
+
|
|
96
|
+
fireEvent.change(textarea, { target: { value: 'tét' } });
|
|
97
|
+
rerender(<>{createModel('té').render()}</>);
|
|
98
|
+
expect(textarea.value).toBe('tét');
|
|
99
|
+
});
|
|
100
|
+
});
|
|
@@ -14,8 +14,9 @@ import { Button, Dropdown, theme, Tooltip, type ButtonProps, type MenuProps } fr
|
|
|
14
14
|
import React, { useEffect, useMemo, useState } from 'react';
|
|
15
15
|
import { useHotkeys } from 'react-hotkeys-hook';
|
|
16
16
|
import { useTranslation } from 'react-i18next';
|
|
17
|
-
import { Link } from 'react-router-dom';
|
|
17
|
+
import { Link, useLocation } from 'react-router-dom';
|
|
18
18
|
import { useACLRoleContext } from '../../../acl';
|
|
19
|
+
import type { BaseApplication } from '../../../BaseApplication';
|
|
19
20
|
import type { PluginSettingsPageType } from '../../../PluginSettingsManager';
|
|
20
21
|
import { useApp } from '../../../hooks/useApp';
|
|
21
22
|
import {
|
|
@@ -64,6 +65,89 @@ const topbarActionTriggerClassName = css`
|
|
|
64
65
|
height: 100%;
|
|
65
66
|
`;
|
|
66
67
|
|
|
68
|
+
type TopbarSettingsAppLike = Pick<BaseApplication<any>, 'router' | 'getPublicPath'>;
|
|
69
|
+
|
|
70
|
+
const normalizeTopbarPath = (pathname?: string) => {
|
|
71
|
+
const trimmed = pathname?.trim();
|
|
72
|
+
if (!trimmed || trimmed === '/') {
|
|
73
|
+
return '/';
|
|
74
|
+
}
|
|
75
|
+
return `/${trimmed.replace(/^\/+/, '')}`;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const normalizeTopbarBasePath = (pathname?: string) => {
|
|
79
|
+
const normalized = normalizeTopbarPath(pathname).replace(/\/+$/, '');
|
|
80
|
+
return normalized === '' || normalized === '/' ? '' : normalized;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const getTopbarRouterBasePath = (app: TopbarSettingsAppLike | undefined) => {
|
|
84
|
+
return app?.router?.getBasename?.() || app?.router?.basename || app?.getPublicPath?.() || '';
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const stripTopbarRouterBasePath = (pathname: string, basename?: string) => {
|
|
88
|
+
const normalizedPath = normalizeTopbarPath(pathname);
|
|
89
|
+
const normalizedBase = normalizeTopbarBasePath(basename);
|
|
90
|
+
|
|
91
|
+
if (!normalizedBase) {
|
|
92
|
+
return normalizedPath;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (normalizedPath === normalizedBase) {
|
|
96
|
+
return '/';
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (normalizedPath.startsWith(`${normalizedBase}/`)) {
|
|
100
|
+
return normalizeTopbarPath(normalizedPath.slice(normalizedBase.length));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return normalizedPath;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const isAdminRuntimePath = (pathname: string) => {
|
|
107
|
+
return pathname === '/admin' || pathname.startsWith('/admin/');
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const buildTopbarDocumentHref = (targetPath: string, basename?: string) => {
|
|
111
|
+
const normalizedTarget = normalizeTopbarPath(targetPath);
|
|
112
|
+
const normalizedBase = normalizeTopbarBasePath(basename);
|
|
113
|
+
|
|
114
|
+
if (!normalizedBase || normalizedTarget === normalizedBase || normalizedTarget.startsWith(`${normalizedBase}/`)) {
|
|
115
|
+
return normalizedTarget;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return `${normalizedBase}${normalizedTarget}`;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
function TopbarExternalSettingsLabel(props: { title: React.ReactNode; link: string }) {
|
|
122
|
+
return (
|
|
123
|
+
<div
|
|
124
|
+
onClick={() => {
|
|
125
|
+
window.open(props.link, '_blank', 'noopener,noreferrer');
|
|
126
|
+
}}
|
|
127
|
+
>
|
|
128
|
+
{props.title}
|
|
129
|
+
</div>
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function TopbarInternalSettingsLabel(props: { title: React.ReactNode; path?: string }) {
|
|
134
|
+
const app = useApp();
|
|
135
|
+
const location = useLocation();
|
|
136
|
+
const targetPath = props.path || '/admin/settings';
|
|
137
|
+
const basename = getTopbarRouterBasePath(app);
|
|
138
|
+
const currentPath = stripTopbarRouterBasePath(location.pathname, basename);
|
|
139
|
+
|
|
140
|
+
if (isAdminRuntimePath(currentPath)) {
|
|
141
|
+
return <Link to={targetPath}>{props.title}</Link>;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return (
|
|
145
|
+
<a href={buildTopbarDocumentHref(targetPath, basename)} target="_blank" rel="noopener noreferrer">
|
|
146
|
+
{props.title}
|
|
147
|
+
</a>
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
67
151
|
/**
|
|
68
152
|
* 将 settings 顶部菜单转换成右上角 dropdown items。
|
|
69
153
|
*
|
|
@@ -112,15 +196,9 @@ export function getTopbarPluginSettingsItems(options: {
|
|
|
112
196
|
title: targetTitle,
|
|
113
197
|
icon: item.icon,
|
|
114
198
|
label: targetLink ? (
|
|
115
|
-
<
|
|
116
|
-
onClick={() => {
|
|
117
|
-
window.open(targetLink, '_blank', 'noopener,noreferrer');
|
|
118
|
-
}}
|
|
119
|
-
>
|
|
120
|
-
{targetTitle}
|
|
121
|
-
</div>
|
|
199
|
+
<TopbarExternalSettingsLabel title={targetTitle} link={targetLink} />
|
|
122
200
|
) : (
|
|
123
|
-
<
|
|
201
|
+
<TopbarInternalSettingsLabel title={targetTitle} path={targetPath} />
|
|
124
202
|
),
|
|
125
203
|
};
|
|
126
204
|
});
|
|
@@ -131,7 +209,12 @@ export function getTopbarPluginSettingsItems(options: {
|
|
|
131
209
|
items.push({
|
|
132
210
|
key: pluginManagerSetting.key,
|
|
133
211
|
icon: pluginManagerSetting.icon || <ApiOutlined />,
|
|
134
|
-
label:
|
|
212
|
+
label: (
|
|
213
|
+
<TopbarInternalSettingsLabel
|
|
214
|
+
title={pluginManagerSetting.title || t('Plugin manager')}
|
|
215
|
+
path={pluginManagerSetting.path}
|
|
216
|
+
/>
|
|
217
|
+
),
|
|
135
218
|
});
|
|
136
219
|
}
|
|
137
220
|
|
|
@@ -49,12 +49,12 @@ export function resolveViewParamsToViewList(
|
|
|
49
49
|
return viewItems;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
export function updateViewListHidden(viewItems: ViewItem[]) {
|
|
52
|
+
export function updateViewListHidden(viewItems: ViewItem[], isMobileLayout = false) {
|
|
53
53
|
// Calculate hidden values based on view types and positions
|
|
54
54
|
let hasEmbedAfter = false;
|
|
55
55
|
for (let i = viewItems.length - 1; i >= 0; i--) {
|
|
56
56
|
const viewItem = viewItems[i];
|
|
57
|
-
const viewType = getViewType(viewItem);
|
|
57
|
+
const viewType = getViewType(viewItem, isMobileLayout);
|
|
58
58
|
|
|
59
59
|
if (viewType === 'embed' && !hasEmbedAfter) {
|
|
60
60
|
hasEmbedAfter = true;
|
|
@@ -65,15 +65,23 @@ export function updateViewListHidden(viewItems: ViewItem[]) {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
function getViewType(viewItem: ViewItem): string {
|
|
68
|
+
function getViewType(viewItem: ViewItem, isMobileLayout = false): string {
|
|
69
69
|
if (viewItem.model instanceof RouteModel) {
|
|
70
70
|
return 'embed';
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
if (isMobileLayout && viewItem.index > 0) {
|
|
74
|
+
return 'embed';
|
|
75
|
+
}
|
|
76
|
+
|
|
73
77
|
if (!viewItem.model) {
|
|
74
78
|
return 'drawer';
|
|
75
79
|
}
|
|
76
80
|
|
|
81
|
+
if (viewItem.params.openViewRouteState?.mode) {
|
|
82
|
+
return viewItem.params.openViewRouteState.mode;
|
|
83
|
+
}
|
|
84
|
+
|
|
77
85
|
const params = viewItem.model.getStepParams('popupSettings', 'openView');
|
|
78
86
|
return params?.mode || 'drawer';
|
|
79
87
|
}
|
|
@@ -48,6 +48,264 @@ describe('dateTimeFormat', () => {
|
|
|
48
48
|
});
|
|
49
49
|
});
|
|
50
50
|
|
|
51
|
+
it('uses the association title field when deciding the format schema', () => {
|
|
52
|
+
const ctx = {
|
|
53
|
+
model: {
|
|
54
|
+
props: {
|
|
55
|
+
titleField: 'shipmentsTime',
|
|
56
|
+
},
|
|
57
|
+
context: {
|
|
58
|
+
collectionField: {
|
|
59
|
+
type: 'belongsTo',
|
|
60
|
+
targetCollection: {
|
|
61
|
+
getField: (name) =>
|
|
62
|
+
name === 'shipmentsTime'
|
|
63
|
+
? {
|
|
64
|
+
type: 'time',
|
|
65
|
+
interface: 'time',
|
|
66
|
+
}
|
|
67
|
+
: null,
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
expect(Object.keys(dateTimeFormat.uiSchema(ctx))).toEqual(['timeFormat']);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('saves association title time field format as a time format', () => {
|
|
78
|
+
const setProps = vi.fn();
|
|
79
|
+
const ctx = {
|
|
80
|
+
model: {
|
|
81
|
+
props: {
|
|
82
|
+
titleField: 'shipmentsTime',
|
|
83
|
+
},
|
|
84
|
+
context: {
|
|
85
|
+
collectionField: {
|
|
86
|
+
type: 'belongsTo',
|
|
87
|
+
targetCollection: {
|
|
88
|
+
getField: (name) =>
|
|
89
|
+
name === 'shipmentsTime'
|
|
90
|
+
? {
|
|
91
|
+
type: 'time',
|
|
92
|
+
interface: 'time',
|
|
93
|
+
}
|
|
94
|
+
: null,
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
setProps,
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
dateTimeFormat.handler(ctx, { timeFormat: 'hh:mm:ss a' });
|
|
103
|
+
|
|
104
|
+
expect(setProps).toHaveBeenCalledWith({
|
|
105
|
+
timeFormat: 'hh:mm:ss a',
|
|
106
|
+
format: 'hh:mm:ss a',
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('applies and persists date time format params when settings are saved', async () => {
|
|
111
|
+
const setProps = vi.fn();
|
|
112
|
+
const save = vi.fn();
|
|
113
|
+
const ctx = {
|
|
114
|
+
model: {
|
|
115
|
+
props: {
|
|
116
|
+
titleField: 'shipmentsDatetime',
|
|
117
|
+
},
|
|
118
|
+
context: {
|
|
119
|
+
collectionField: {
|
|
120
|
+
type: 'belongsTo',
|
|
121
|
+
targetCollection: {
|
|
122
|
+
getField: (name) =>
|
|
123
|
+
name === 'shipmentsDatetime'
|
|
124
|
+
? {
|
|
125
|
+
type: 'datetime',
|
|
126
|
+
interface: 'datetime',
|
|
127
|
+
}
|
|
128
|
+
: null,
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
setProps,
|
|
133
|
+
save,
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
await dateTimeFormat.beforeParamsSave(ctx, {
|
|
138
|
+
picker: 'date',
|
|
139
|
+
dateFormat: 'YYYY-MM-DD',
|
|
140
|
+
showTime: true,
|
|
141
|
+
timeFormat: 'hh:mm:ss a',
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
expect(setProps).toHaveBeenCalledWith({
|
|
145
|
+
picker: 'date',
|
|
146
|
+
dateFormat: 'YYYY-MM-DD',
|
|
147
|
+
showTime: true,
|
|
148
|
+
timeFormat: 'hh:mm:ss a',
|
|
149
|
+
format: 'YYYY-MM-DD hh:mm:ss a',
|
|
150
|
+
});
|
|
151
|
+
expect(save).toHaveBeenCalled();
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('syncs table association column props when title date time format settings are saved', async () => {
|
|
155
|
+
const setProps = vi.fn();
|
|
156
|
+
const save = vi.fn();
|
|
157
|
+
const setParentProps = vi.fn();
|
|
158
|
+
const model = {
|
|
159
|
+
props: {
|
|
160
|
+
titleField: 'shipmentsDatetime',
|
|
161
|
+
},
|
|
162
|
+
context: {
|
|
163
|
+
collectionField: {
|
|
164
|
+
type: 'belongsTo',
|
|
165
|
+
targetCollection: {
|
|
166
|
+
getField: (name) =>
|
|
167
|
+
name === 'shipmentsDatetime'
|
|
168
|
+
? {
|
|
169
|
+
type: 'datetime',
|
|
170
|
+
interface: 'datetime',
|
|
171
|
+
}
|
|
172
|
+
: null,
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
setProps,
|
|
177
|
+
save,
|
|
178
|
+
parent: {
|
|
179
|
+
use: 'TableColumnModel',
|
|
180
|
+
collectionField: {
|
|
181
|
+
isAssociationField: () => true,
|
|
182
|
+
},
|
|
183
|
+
setProps: setParentProps,
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
model.parent['subModels'] = {
|
|
187
|
+
field: model,
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
await dateTimeFormat.beforeParamsSave(
|
|
191
|
+
{ model },
|
|
192
|
+
{
|
|
193
|
+
picker: 'date',
|
|
194
|
+
dateFormat: 'YYYY-MM-DD',
|
|
195
|
+
showTime: true,
|
|
196
|
+
timeFormat: 'hh:mm:ss a',
|
|
197
|
+
},
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
expect(setParentProps).toHaveBeenCalledWith({
|
|
201
|
+
picker: 'date',
|
|
202
|
+
dateFormat: 'YYYY-MM-DD',
|
|
203
|
+
showTime: true,
|
|
204
|
+
timeFormat: 'hh:mm:ss a',
|
|
205
|
+
format: 'YYYY-MM-DD hh:mm:ss a',
|
|
206
|
+
});
|
|
207
|
+
expect(save).toHaveBeenCalled();
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it('hides time format for association title date-only fields', () => {
|
|
211
|
+
const ctx = {
|
|
212
|
+
model: {
|
|
213
|
+
props: {
|
|
214
|
+
titleField: 'shipmentsDateOnly',
|
|
215
|
+
showTime: true,
|
|
216
|
+
},
|
|
217
|
+
context: {
|
|
218
|
+
collectionField: {
|
|
219
|
+
type: 'belongsTo',
|
|
220
|
+
targetCollection: {
|
|
221
|
+
getField: (name) =>
|
|
222
|
+
name === 'shipmentsDateOnly'
|
|
223
|
+
? {
|
|
224
|
+
type: 'dateOnly',
|
|
225
|
+
interface: 'date',
|
|
226
|
+
getComponentProps: () => ({
|
|
227
|
+
dateOnly: true,
|
|
228
|
+
showTime: false,
|
|
229
|
+
}),
|
|
230
|
+
}
|
|
231
|
+
: null,
|
|
232
|
+
},
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
};
|
|
237
|
+
const schema = dateTimeFormat.uiSchema(ctx);
|
|
238
|
+
const timeFormatField: any = schema.timeFormat;
|
|
239
|
+
const showTimeField: any = schema.showTime;
|
|
240
|
+
const timeFormatState = {
|
|
241
|
+
hidden: false,
|
|
242
|
+
form: {
|
|
243
|
+
values: {
|
|
244
|
+
picker: 'date',
|
|
245
|
+
showTime: true,
|
|
246
|
+
},
|
|
247
|
+
},
|
|
248
|
+
};
|
|
249
|
+
const showTimeState = {
|
|
250
|
+
hidden: false,
|
|
251
|
+
value: true,
|
|
252
|
+
form: {
|
|
253
|
+
values: {
|
|
254
|
+
picker: 'date',
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
timeFormatField['x-reactions'][0](timeFormatState);
|
|
260
|
+
showTimeField['x-reactions'][1](showTimeState);
|
|
261
|
+
|
|
262
|
+
expect(timeFormatState.hidden).toBe(true);
|
|
263
|
+
expect(showTimeState.hidden).toBe(true);
|
|
264
|
+
expect(showTimeState.value).toBe(false);
|
|
265
|
+
expect(dateTimeFormat.defaultParams(ctx)).toMatchObject({
|
|
266
|
+
showTime: false,
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it('saves association title date-only field format without time even when params contain showTime', () => {
|
|
271
|
+
const setProps = vi.fn();
|
|
272
|
+
const ctx = {
|
|
273
|
+
model: {
|
|
274
|
+
props: {
|
|
275
|
+
titleField: 'shipmentsDateOnly',
|
|
276
|
+
},
|
|
277
|
+
context: {
|
|
278
|
+
collectionField: {
|
|
279
|
+
type: 'belongsTo',
|
|
280
|
+
targetCollection: {
|
|
281
|
+
getField: (name) =>
|
|
282
|
+
name === 'shipmentsDateOnly'
|
|
283
|
+
? {
|
|
284
|
+
type: 'dateOnly',
|
|
285
|
+
interface: 'date',
|
|
286
|
+
}
|
|
287
|
+
: null,
|
|
288
|
+
},
|
|
289
|
+
},
|
|
290
|
+
},
|
|
291
|
+
setProps,
|
|
292
|
+
},
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
dateTimeFormat.handler(ctx, {
|
|
296
|
+
dateFormat: 'YYYY-MM-DD',
|
|
297
|
+
showTime: true,
|
|
298
|
+
timeFormat: 'HH:mm:ss',
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
expect(setProps).toHaveBeenCalledWith({
|
|
302
|
+
dateFormat: 'YYYY-MM-DD',
|
|
303
|
+
showTime: false,
|
|
304
|
+
timeFormat: 'HH:mm:ss',
|
|
305
|
+
format: 'YYYY-MM-DD',
|
|
306
|
+
});
|
|
307
|
+
});
|
|
308
|
+
|
|
51
309
|
it('uses format as the default time format when timeFormat is missing', () => {
|
|
52
310
|
const ctx = {
|
|
53
311
|
model: {
|