@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,10 +7,18 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import {
|
|
10
|
+
import { observable } from '@formily/reactive';
|
|
11
|
+
import { act, fireEvent, render, waitFor } from '@testing-library/react';
|
|
11
12
|
import React from 'react';
|
|
12
13
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
13
14
|
import { FlowPage } from '../FlowPage';
|
|
15
|
+
import { RouteModel } from '../models/base/RouteModel';
|
|
16
|
+
import { loadRouteContentForEditing } from '../FlowModelRepository';
|
|
17
|
+
|
|
18
|
+
vi.mock('../FlowModelRepository', () => ({
|
|
19
|
+
loadRouteContentForEditing: vi.fn(),
|
|
20
|
+
isRouteContentConfirmed: () => false,
|
|
21
|
+
}));
|
|
14
22
|
|
|
15
23
|
type TestContextProperty = {
|
|
16
24
|
value?: unknown;
|
|
@@ -71,7 +79,6 @@ const createPageModel = (): TestPageModel => {
|
|
|
71
79
|
};
|
|
72
80
|
|
|
73
81
|
const mocks = vi.hoisted(() => ({
|
|
74
|
-
flowSettingsEnabled: false,
|
|
75
82
|
loadModel: vi.fn(),
|
|
76
83
|
loadOrCreateModel: vi.fn(),
|
|
77
84
|
rendererMobileStates: [] as boolean[],
|
|
@@ -83,6 +90,8 @@ const mocks = vi.hoisted(() => ({
|
|
|
83
90
|
contextMobileLayout: undefined as boolean | undefined,
|
|
84
91
|
}));
|
|
85
92
|
|
|
93
|
+
const editor = observable({ enabled: false });
|
|
94
|
+
|
|
86
95
|
vi.mock('@nocobase/flow-engine', async () => {
|
|
87
96
|
const actual = await vi.importActual<typeof import('@nocobase/flow-engine')>('@nocobase/flow-engine');
|
|
88
97
|
const ReactModule = await import('react');
|
|
@@ -95,14 +104,17 @@ vi.mock('@nocobase/flow-engine', async () => {
|
|
|
95
104
|
if (typeof props.model?.context.isMobileLayout === 'boolean') {
|
|
96
105
|
mocks.rendererMobileStates.push(props.model.context.isMobileLayout);
|
|
97
106
|
}
|
|
98
|
-
return ReactModule.createElement('
|
|
107
|
+
return ReactModule.createElement('input', { 'data-testid': 'flow-model-renderer' });
|
|
99
108
|
}),
|
|
100
109
|
useFlowEngine: vi.fn(() => ({
|
|
110
|
+
getModel: () => Object.create(RouteModel.prototype),
|
|
101
111
|
getModelClassAsync: vi.fn(async () => TestPageModelClass),
|
|
102
112
|
loadModel: mocks.loadModel,
|
|
103
113
|
loadOrCreateModel: mocks.loadOrCreateModel,
|
|
104
114
|
context: {
|
|
105
|
-
flowSettingsEnabled
|
|
115
|
+
get flowSettingsEnabled() {
|
|
116
|
+
return editor.enabled;
|
|
117
|
+
},
|
|
106
118
|
},
|
|
107
119
|
translate: vi.fn((value: string) => value),
|
|
108
120
|
})),
|
|
@@ -123,46 +135,6 @@ vi.mock('@nocobase/flow-engine', async () => {
|
|
|
123
135
|
};
|
|
124
136
|
});
|
|
125
137
|
|
|
126
|
-
vi.mock('ahooks', async () => {
|
|
127
|
-
const actual = await vi.importActual<typeof import('ahooks')>('ahooks');
|
|
128
|
-
const ReactModule = await import('react');
|
|
129
|
-
return {
|
|
130
|
-
...actual,
|
|
131
|
-
useRequest: vi.fn((service: () => Promise<unknown>) => {
|
|
132
|
-
const serviceRef = ReactModule.useRef(service);
|
|
133
|
-
const [state, setState] = ReactModule.useState<{
|
|
134
|
-
loading: boolean;
|
|
135
|
-
data?: unknown;
|
|
136
|
-
error?: unknown;
|
|
137
|
-
}>({
|
|
138
|
-
loading: true,
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
ReactModule.useEffect(() => {
|
|
142
|
-
let active = true;
|
|
143
|
-
serviceRef
|
|
144
|
-
.current()
|
|
145
|
-
.then((data) => {
|
|
146
|
-
if (active) {
|
|
147
|
-
setState({ loading: false, data, error: null });
|
|
148
|
-
}
|
|
149
|
-
})
|
|
150
|
-
.catch((error) => {
|
|
151
|
-
if (active) {
|
|
152
|
-
setState({ loading: false, data: undefined, error });
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
return () => {
|
|
157
|
-
active = false;
|
|
158
|
-
};
|
|
159
|
-
}, []);
|
|
160
|
-
|
|
161
|
-
return state;
|
|
162
|
-
}),
|
|
163
|
-
};
|
|
164
|
-
});
|
|
165
|
-
|
|
166
138
|
describe('FlowPage', () => {
|
|
167
139
|
beforeEach(() => {
|
|
168
140
|
mocks.loadModel.mockImplementation(async () => null);
|
|
@@ -170,7 +142,10 @@ describe('FlowPage', () => {
|
|
|
170
142
|
});
|
|
171
143
|
|
|
172
144
|
afterEach(() => {
|
|
173
|
-
|
|
145
|
+
act(() => {
|
|
146
|
+
editor.enabled = false;
|
|
147
|
+
});
|
|
148
|
+
vi.mocked(loadRouteContentForEditing).mockReset();
|
|
174
149
|
mocks.loadModel.mockReset();
|
|
175
150
|
mocks.loadOrCreateModel.mockReset();
|
|
176
151
|
mocks.rendererMobileStates = [];
|
|
@@ -182,6 +157,63 @@ describe('FlowPage', () => {
|
|
|
182
157
|
mocks.contextMobileLayout = undefined;
|
|
183
158
|
});
|
|
184
159
|
|
|
160
|
+
it('keeps the mounted route page and confirms storage only on the first edit', async () => {
|
|
161
|
+
mocks.model = createPageModel();
|
|
162
|
+
const { queryByTestId } = render(<FlowPage parentId="route" />);
|
|
163
|
+
await waitFor(() => expect(queryByTestId('flow-model-renderer')).toBeTruthy());
|
|
164
|
+
expect(mocks.loadOrCreateModel).toHaveBeenCalledWith(expect.objectContaining({ parentId: 'route' }), {
|
|
165
|
+
skipSave: true,
|
|
166
|
+
});
|
|
167
|
+
expect(loadRouteContentForEditing).not.toHaveBeenCalled();
|
|
168
|
+
|
|
169
|
+
const input = queryByTestId('flow-model-renderer') as HTMLInputElement;
|
|
170
|
+
fireEvent.change(input, { target: { value: 'draft' } });
|
|
171
|
+
let finish: () => void;
|
|
172
|
+
vi.mocked(loadRouteContentForEditing).mockImplementationOnce(
|
|
173
|
+
() =>
|
|
174
|
+
new Promise((resolve) => {
|
|
175
|
+
finish = () => resolve(mocks.model as unknown as Awaited<ReturnType<typeof loadRouteContentForEditing>>);
|
|
176
|
+
}),
|
|
177
|
+
);
|
|
178
|
+
act(() => {
|
|
179
|
+
editor.enabled = true;
|
|
180
|
+
});
|
|
181
|
+
await waitFor(() => expect(loadRouteContentForEditing).toHaveBeenCalledOnce());
|
|
182
|
+
expect(input.closest('[inert]')).toBeTruthy();
|
|
183
|
+
expect(queryByTestId('flow-model-renderer')).toBe(input);
|
|
184
|
+
await act(async () => finish());
|
|
185
|
+
await waitFor(() => expect(input.closest('[inert]')).toBeNull());
|
|
186
|
+
act(() => {
|
|
187
|
+
editor.enabled = false;
|
|
188
|
+
});
|
|
189
|
+
act(() => {
|
|
190
|
+
editor.enabled = true;
|
|
191
|
+
});
|
|
192
|
+
expect(queryByTestId('flow-model-renderer')).toBe(input);
|
|
193
|
+
expect(input.value).toBe('draft');
|
|
194
|
+
expect(loadRouteContentForEditing).toHaveBeenCalledOnce();
|
|
195
|
+
expect(mocks.loadOrCreateModel).toHaveBeenCalledOnce();
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it('opens directly in the editor and keeps the confirmed page on subsequent toggles', async () => {
|
|
199
|
+
editor.enabled = true;
|
|
200
|
+
mocks.model = createPageModel();
|
|
201
|
+
vi.mocked(loadRouteContentForEditing).mockResolvedValue(
|
|
202
|
+
mocks.model as unknown as Awaited<ReturnType<typeof loadRouteContentForEditing>>,
|
|
203
|
+
);
|
|
204
|
+
const { findByTestId, getByTestId } = render(<FlowPage parentId="route" />);
|
|
205
|
+
const input = await findByTestId('flow-model-renderer');
|
|
206
|
+
act(() => {
|
|
207
|
+
editor.enabled = false;
|
|
208
|
+
});
|
|
209
|
+
act(() => {
|
|
210
|
+
editor.enabled = true;
|
|
211
|
+
});
|
|
212
|
+
expect(getByTestId('flow-model-renderer')).toBe(input);
|
|
213
|
+
expect(loadRouteContentForEditing).toHaveBeenCalledOnce();
|
|
214
|
+
expect(mocks.loadOrCreateModel).not.toHaveBeenCalled();
|
|
215
|
+
});
|
|
216
|
+
|
|
185
217
|
it('uses showFlowSettings from page model props', async () => {
|
|
186
218
|
mocks.model = createPageModel();
|
|
187
219
|
render(<FlowPage />);
|
|
@@ -239,7 +271,7 @@ describe('FlowPage', () => {
|
|
|
239
271
|
});
|
|
240
272
|
|
|
241
273
|
it('keeps configured page model cache behavior in flow settings mode', async () => {
|
|
242
|
-
|
|
274
|
+
editor.enabled = true;
|
|
243
275
|
mocks.model = createPageModel();
|
|
244
276
|
mocks.viewFilterByTk = 1;
|
|
245
277
|
|
|
@@ -0,0 +1,48 @@
|
|
|
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 { describe, expect, it, vi } from 'vitest';
|
|
11
|
+
import { validation } from '../validation';
|
|
12
|
+
|
|
13
|
+
vi.mock('../../../flow-compat', () => ({ FieldValidation: () => null }));
|
|
14
|
+
|
|
15
|
+
describe('validation action', () => {
|
|
16
|
+
it('rejects excess decimal places with a translated error and retains collection rules', async () => {
|
|
17
|
+
const setProps = vi.fn();
|
|
18
|
+
const collectionRule = { validator: vi.fn().mockResolvedValue(undefined) };
|
|
19
|
+
const t = vi.fn((key: string, options?: Record<string, unknown>) => {
|
|
20
|
+
return `${options?.label} 精度不能超过 ${options?.limit} 位小数`;
|
|
21
|
+
});
|
|
22
|
+
const ctx = {
|
|
23
|
+
model: {
|
|
24
|
+
props: { label: '工龄' },
|
|
25
|
+
collectionField: { getComponentProps: () => ({ rules: [collectionRule] }) },
|
|
26
|
+
setProps,
|
|
27
|
+
},
|
|
28
|
+
t,
|
|
29
|
+
} as unknown as Parameters<typeof validation.handler>[0];
|
|
30
|
+
|
|
31
|
+
await validation.handler(ctx, {
|
|
32
|
+
validation: { type: 'number', rules: [{ name: 'precision', args: { limit: 2 } }] },
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const { rules } = setProps.mock.calls[0][0] as {
|
|
36
|
+
rules: { validator: (rule: unknown, value: unknown) => Promise<void> }[];
|
|
37
|
+
};
|
|
38
|
+
expect(rules).toHaveLength(2);
|
|
39
|
+
expect(rules[0]).toBe(collectionRule);
|
|
40
|
+
await expect(rules[1].validator({}, 39.2234)).rejects.toBe('工龄 精度不能超过 2 位小数');
|
|
41
|
+
expect(t).toHaveBeenCalledWith(
|
|
42
|
+
'number.precision',
|
|
43
|
+
expect.objectContaining({ ns: 'data-source-main', label: '工龄', limit: 2 }),
|
|
44
|
+
);
|
|
45
|
+
await expect(rules[1].validator({}, 39.22)).resolves.toBeUndefined();
|
|
46
|
+
await expect(rules[1].validator({}, null)).resolves.toBeUndefined();
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
resolveAdminLayoutMenuDragMoveOptionsFromEvent,
|
|
29
29
|
} from './AdminLayoutMenuModels';
|
|
30
30
|
import type { AdminLayoutModel } from './AdminLayoutModel';
|
|
31
|
+
import { observeAdminMenuRoutes } from './observeAdminMenuRoutes';
|
|
31
32
|
import { AdminLayoutContent } from './AdminLayoutSlotModels';
|
|
32
33
|
import { ADMIN_LAYOUT_MODEL_UID } from './constants';
|
|
33
34
|
import { ResetThemeTokenAndKeepAlgorithm } from './ResetThemeTokenAndKeepAlgorithm';
|
|
@@ -65,7 +66,7 @@ const resetStyle = css`
|
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
.ant-menu-item:has([data-nb-hidden-menu-item='true']),
|
|
68
|
-
.ant-menu-submenu:has([data-nb-hidden-menu-item='true']) {
|
|
69
|
+
.ant-menu-submenu:has(> .ant-menu-submenu-title [data-nb-hidden-menu-item='true']) {
|
|
69
70
|
display: none !important;
|
|
70
71
|
}
|
|
71
72
|
`;
|
|
@@ -81,6 +82,8 @@ const popoverStyle = css`
|
|
|
81
82
|
}
|
|
82
83
|
`;
|
|
83
84
|
|
|
85
|
+
const siderToggleZIndex = 200;
|
|
86
|
+
|
|
84
87
|
const CollapsedButton: FC<{ collapsed: boolean }> = (props) => {
|
|
85
88
|
const { token } = antdTheme.useToken();
|
|
86
89
|
const customToken = token as CustomToken;
|
|
@@ -107,7 +110,7 @@ const CollapsedButton: FC<{ collapsed: boolean }> = (props) => {
|
|
|
107
110
|
.ant-pro-sider-collapsed-button {
|
|
108
111
|
top: 64px;
|
|
109
112
|
left: ${props.collapsed ? 52 : (customToken.siderWidth || 200) - 12}px;
|
|
110
|
-
z-index:
|
|
113
|
+
z-index: ${siderToggleZIndex};
|
|
111
114
|
transition: left 0.2s;
|
|
112
115
|
}
|
|
113
116
|
`}
|
|
@@ -497,15 +500,12 @@ export const AdminLayoutComponent = observer((props: any) => {
|
|
|
497
500
|
|
|
498
501
|
useLayoutEffect(() => {
|
|
499
502
|
adminLayoutModel?.syncMenuRoutes(allAccessRoutes);
|
|
500
|
-
|
|
503
|
+
return observeAdminMenuRoutes(
|
|
504
|
+
() =>
|
|
505
|
+
adminLayoutModel?.toProLayoutRoute({ designable, isMobile: isMobileSider, t }) || { path: '/', children: [] },
|
|
506
|
+
setRoute,
|
|
501
507
|
designable,
|
|
502
|
-
|
|
503
|
-
t,
|
|
504
|
-
}) || {
|
|
505
|
-
path: '/',
|
|
506
|
-
children: [],
|
|
507
|
-
};
|
|
508
|
-
setRoute(nextRoute);
|
|
508
|
+
);
|
|
509
509
|
}, [adminLayoutModel, allAccessRoutes, designable, isMobileSider, menuRouteRefreshVersion, t]);
|
|
510
510
|
|
|
511
511
|
useEffect(() => {
|
|
@@ -606,6 +606,11 @@ export const AdminLayoutComponent = observer((props: any) => {
|
|
|
606
606
|
z-index: 101 !important;
|
|
607
607
|
}
|
|
608
608
|
|
|
609
|
+
/* The switcher popup is mounted inside the header, while the sider toggle is portaled outside it. */
|
|
610
|
+
.ant-layout-header.ant-pro-layout-header:has(.ant-pro-layout-apps-icon-active) {
|
|
611
|
+
z-index: ${siderToggleZIndex + 1} !important;
|
|
612
|
+
}
|
|
613
|
+
|
|
609
614
|
.ant-pro-layout-apps-popover {
|
|
610
615
|
z-index: 2000 !important;
|
|
611
616
|
}
|
|
@@ -15,7 +15,7 @@ import { describe, expect, it, vi } from 'vitest';
|
|
|
15
15
|
import { NocoBaseDesktopRouteType } from '../../../flow-compat';
|
|
16
16
|
import { RouteRepository } from '../../../RouteRepository';
|
|
17
17
|
import { AdminLayoutEntryGuard } from './AdminLayoutEntryGuard';
|
|
18
|
-
import
|
|
18
|
+
import { AdminLayoutModel } from './AdminLayoutModel';
|
|
19
19
|
|
|
20
20
|
describe('AdminLayoutEntryGuard', () => {
|
|
21
21
|
it('should ensure accessible routes for the active layout before resolving the landing route', async () => {
|
|
@@ -309,6 +309,53 @@ describe('AdminLayoutEntryGuard', () => {
|
|
|
309
309
|
expect(activateLayout).toHaveBeenLastCalledWith(expect.objectContaining({ uid: 'admin-layout-next' }));
|
|
310
310
|
});
|
|
311
311
|
|
|
312
|
+
it.each([false, true])(
|
|
313
|
+
'should use the settled home destination only while still at the root (leave=%s)',
|
|
314
|
+
async (leave) => {
|
|
315
|
+
const engine = new FlowEngine();
|
|
316
|
+
const repository = new RouteRepository({});
|
|
317
|
+
const hidden = { type: NocoBaseDesktopRouteType.flowPage, schemaUid: 'hidden' };
|
|
318
|
+
const visible = { type: NocoBaseDesktopRouteType.flowPage, schemaUid: 'visible' };
|
|
319
|
+
repository.setRoutes([hidden, visible]);
|
|
320
|
+
engine.context.defineProperty('routeRepository', { value: repository });
|
|
321
|
+
engine.context.defineProperty('app', {
|
|
322
|
+
value: {
|
|
323
|
+
getPublicPath: () => '/v/',
|
|
324
|
+
router: { getBasename: () => '/v' },
|
|
325
|
+
},
|
|
326
|
+
});
|
|
327
|
+
const model = engine.createModel<AdminLayoutModel>({ uid: 'admin-layout-model', use: AdminLayoutModel });
|
|
328
|
+
let finish!: (page: typeof visible) => void;
|
|
329
|
+
const pending = new Promise<typeof visible>((resolve) => {
|
|
330
|
+
finish = resolve;
|
|
331
|
+
});
|
|
332
|
+
const resolvePage = vi.spyOn(model, 'resolveDefaultPage').mockReturnValue(pending);
|
|
333
|
+
const router = createMemoryRouter(
|
|
334
|
+
[
|
|
335
|
+
{
|
|
336
|
+
id: 'admin',
|
|
337
|
+
path: '/admin',
|
|
338
|
+
element: (
|
|
339
|
+
<FlowEngineProvider engine={engine}>
|
|
340
|
+
<AdminLayoutEntryGuard model={model}>
|
|
341
|
+
<Outlet />
|
|
342
|
+
</AdminLayoutEntryGuard>
|
|
343
|
+
</FlowEngineProvider>
|
|
344
|
+
),
|
|
345
|
+
children: [{ id: 'admin.__page', path: ':name', element: <div>Page</div> }],
|
|
346
|
+
},
|
|
347
|
+
],
|
|
348
|
+
{ initialEntries: ['/admin'] },
|
|
349
|
+
);
|
|
350
|
+
render(<RouterProvider router={router} />);
|
|
351
|
+
await waitFor(() => expect(resolvePage).toHaveBeenCalled());
|
|
352
|
+
expect(router.state.location.pathname).toBe('/admin');
|
|
353
|
+
if (leave) await act(() => router.navigate('/admin/sibling'));
|
|
354
|
+
await act(async () => finish(visible));
|
|
355
|
+
expect(router.state.location.pathname).toBe(leave ? '/admin/sibling' : '/admin/visible');
|
|
356
|
+
},
|
|
357
|
+
);
|
|
358
|
+
|
|
312
359
|
it('should redirect group id paths to the first v2 landing route', async () => {
|
|
313
360
|
const modernWindow = window as Window & { __nocobase_modern_client_prefix__?: string };
|
|
314
361
|
modernWindow.__nocobase_modern_client_prefix__ = 'v2';
|
|
@@ -158,7 +158,11 @@ export const AdminLayoutEntryGuard: FC<{ children: React.ReactNode; model?: Admi
|
|
|
158
158
|
return;
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
-
const
|
|
161
|
+
const routes = routeRepository?.listAccessible?.() || [];
|
|
162
|
+
const firstAccessibleRoute = model?.resolveDefaultPage
|
|
163
|
+
? await model.resolveDefaultPage(routes, findFirstV2LandingRoute)
|
|
164
|
+
: findFirstV2LandingRoute(routes);
|
|
165
|
+
if (!active) return;
|
|
162
166
|
if (!firstAccessibleRoute) {
|
|
163
167
|
if (active) {
|
|
164
168
|
setReady(true);
|
|
@@ -203,6 +207,7 @@ export const AdminLayoutEntryGuard: FC<{ children: React.ReactNode; model?: Admi
|
|
|
203
207
|
location.hash,
|
|
204
208
|
location.pathname,
|
|
205
209
|
location.search,
|
|
210
|
+
model,
|
|
206
211
|
navigate,
|
|
207
212
|
pageUid,
|
|
208
213
|
routeRepository,
|
|
@@ -43,9 +43,6 @@ import {
|
|
|
43
43
|
import { ADMIN_LAYOUT_MODEL_UID } from './constants';
|
|
44
44
|
import {
|
|
45
45
|
type AdminLayoutRoutePathLike,
|
|
46
|
-
findFirstAccessiblePageRoute,
|
|
47
|
-
findFirstV2LandingRoute,
|
|
48
|
-
isV2AdminRuntime,
|
|
49
46
|
joinAdminLayoutRoutePath,
|
|
50
47
|
resolveAdminRouteRuntimeTarget,
|
|
51
48
|
toRouterNavigationPath,
|
|
@@ -91,6 +88,10 @@ export class AdminLayoutMenuItemModel extends FlowModel<AdminLayoutMenuItemStruc
|
|
|
91
88
|
private persistedStateHydrated = false;
|
|
92
89
|
private persistedStateHydrating?: Promise<void>;
|
|
93
90
|
|
|
91
|
+
get pendingMenuState() {
|
|
92
|
+
return this.persistedStateHydrating;
|
|
93
|
+
}
|
|
94
|
+
|
|
94
95
|
onInit(options: any) {
|
|
95
96
|
super.onInit(options);
|
|
96
97
|
this.syncFromRoute(
|
|
@@ -98,7 +99,9 @@ export class AdminLayoutMenuItemModel extends FlowModel<AdminLayoutMenuItemStruc
|
|
|
98
99
|
this.props.parentRoute as NocoBaseDesktopRoute | undefined,
|
|
99
100
|
);
|
|
100
101
|
if (this.shouldHydratePersistedState()) {
|
|
101
|
-
void this.hydratePersistedState()
|
|
102
|
+
void this.hydratePersistedState().catch((error) => {
|
|
103
|
+
console.error('[NocoBase] Failed to hydrate menu item', this.uid, error);
|
|
104
|
+
});
|
|
102
105
|
}
|
|
103
106
|
}
|
|
104
107
|
|
|
@@ -289,7 +292,7 @@ export class AdminLayoutMenuItemModel extends FlowModel<AdminLayoutMenuItemStruc
|
|
|
289
292
|
}
|
|
290
293
|
|
|
291
294
|
if (shouldRerenderAfterHydrate) {
|
|
292
|
-
|
|
295
|
+
await this.rerender();
|
|
293
296
|
}
|
|
294
297
|
})().finally(() => {
|
|
295
298
|
this.persistedStateHydrated = true;
|
|
@@ -669,6 +672,7 @@ export class AdminLayoutMenuItemModel extends FlowModel<AdminLayoutMenuItemStruc
|
|
|
669
672
|
path,
|
|
670
673
|
redirect: route.schemaUid ? joinAdminLayoutRoutePath(layout, route.schemaUid) : undefined,
|
|
671
674
|
hideInMenu: route.hideInMenu,
|
|
675
|
+
_landingPage: runtimeTarget.runtimePath && !route.hideInMenu && !route.hidden ? route : undefined,
|
|
672
676
|
disabled: !runtimeTarget.runtimePath,
|
|
673
677
|
_runtimePath: runtimeTarget.runtimePath,
|
|
674
678
|
_navigationMode: runtimeTarget.navigationMode,
|
|
@@ -681,27 +685,18 @@ export class AdminLayoutMenuItemModel extends FlowModel<AdminLayoutMenuItemStruc
|
|
|
681
685
|
}
|
|
682
686
|
|
|
683
687
|
if (route.type === NocoBaseDesktopRouteType.group) {
|
|
684
|
-
const
|
|
685
|
-
|
|
686
|
-
(
|
|
687
|
-
|
|
688
|
-
item.toProLayoutRoute({
|
|
689
|
-
...options,
|
|
690
|
-
depth: depth + 1,
|
|
691
|
-
}),
|
|
692
|
-
)
|
|
693
|
-
.filter(Boolean) || [];
|
|
688
|
+
const children = (this.subModels.menuItems || [])
|
|
689
|
+
.map((item: AdminLayoutMenuItemModel) => item.toProLayoutRoute({ ...options, depth: depth + 1 }))
|
|
690
|
+
.filter((item): item is AdminLayoutMenuNode => item !== null);
|
|
691
|
+
const landingPage = children.find((item) => item._landingPage)?._landingPage;
|
|
694
692
|
|
|
695
693
|
if (options.designable && depth === 0) {
|
|
696
694
|
children.push(getAdminLayoutMenuInitializerButton('schema-initializer-Menu-side', this, route, layout));
|
|
697
695
|
}
|
|
698
696
|
|
|
699
|
-
const landingRoute = isV2AdminRuntime(this.context.app)
|
|
700
|
-
? findFirstV2LandingRoute(itemChildren)
|
|
701
|
-
: findFirstAccessiblePageRoute(itemChildren);
|
|
702
697
|
const runtimeTarget = resolveAdminRouteRuntimeTarget({
|
|
703
698
|
app: this.context.app,
|
|
704
|
-
route:
|
|
699
|
+
route: landingPage,
|
|
705
700
|
layout,
|
|
706
701
|
});
|
|
707
702
|
|
|
@@ -712,8 +707,9 @@ export class AdminLayoutMenuItemModel extends FlowModel<AdminLayoutMenuItemStruc
|
|
|
712
707
|
redirect:
|
|
713
708
|
children[0]?.key === 'x-designer-button'
|
|
714
709
|
? undefined
|
|
715
|
-
: joinAdminLayoutRoutePath(layout,
|
|
710
|
+
: joinAdminLayoutRoutePath(layout, landingPage?.schemaUid || route.id),
|
|
716
711
|
hideInMenu: route.hideInMenu,
|
|
712
|
+
_landingPage: route.hideInMenu || route.hidden ? undefined : landingPage,
|
|
717
713
|
_runtimePath: runtimeTarget.runtimePath,
|
|
718
714
|
_navigationMode: runtimeTarget.navigationMode,
|
|
719
715
|
_isLegacy: runtimeTarget.isLegacy,
|
|
@@ -724,7 +720,7 @@ export class AdminLayoutMenuItemModel extends FlowModel<AdminLayoutMenuItemStruc
|
|
|
724
720
|
};
|
|
725
721
|
|
|
726
722
|
if (children.length > 0) {
|
|
727
|
-
groupRoute.routes = children
|
|
723
|
+
groupRoute.routes = children;
|
|
728
724
|
}
|
|
729
725
|
|
|
730
726
|
return groupRoute;
|
|
@@ -36,6 +36,35 @@ export type AdminLayoutStructure = BaseLayoutStructure & {
|
|
|
36
36
|
};
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
+
type FindFirstPage = (routes: NocoBaseDesktopRoute[]) => NocoBaseDesktopRoute | undefined;
|
|
40
|
+
|
|
41
|
+
async function findVisibleMenuPage(
|
|
42
|
+
items: AdminLayoutMenuItemModel[],
|
|
43
|
+
findFirstPage: FindFirstPage,
|
|
44
|
+
): Promise<NocoBaseDesktopRoute | undefined> {
|
|
45
|
+
for (const item of items) {
|
|
46
|
+
const route = item.getRoute();
|
|
47
|
+
// Keep the runtime's existing rules for static visibility and supported page types.
|
|
48
|
+
if (!findFirstPage([route])) continue;
|
|
49
|
+
|
|
50
|
+
if (item.pendingMenuState) {
|
|
51
|
+
try {
|
|
52
|
+
await item.pendingMenuState;
|
|
53
|
+
} catch {
|
|
54
|
+
// A failed menu rule cannot establish a default destination for this branch.
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (item.hidden) continue;
|
|
59
|
+
if (route.type === 'group') {
|
|
60
|
+
const page = await findVisibleMenuPage(item.subModels.menuItems || [], findFirstPage);
|
|
61
|
+
if (page) return page;
|
|
62
|
+
} else if (route.schemaUid) {
|
|
63
|
+
return route;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
39
68
|
type GetAdminLayoutModelOptions<TModel extends FlowModel = AdminLayoutModel> = GetLayoutModelOptions<TModel>;
|
|
40
69
|
|
|
41
70
|
/**
|
|
@@ -79,6 +108,11 @@ export class AdminLayoutModel extends BaseLayoutModel<AdminLayoutStructure> {
|
|
|
79
108
|
reconcileAdminLayoutMenuItems(this, Array.isArray(routes) ? routes : []);
|
|
80
109
|
}
|
|
81
110
|
|
|
111
|
+
resolveDefaultPage(routes: NocoBaseDesktopRoute[], findFirstPage: FindFirstPage) {
|
|
112
|
+
this.syncMenuRoutes(routes);
|
|
113
|
+
return findVisibleMenuPage(this.subModels.menuItems || [], findFirstPage);
|
|
114
|
+
}
|
|
115
|
+
|
|
82
116
|
/**
|
|
83
117
|
* 将菜单模型转换为 ProLayout 路由树。
|
|
84
118
|
*
|
|
@@ -70,7 +70,11 @@ const SettingsMenu: React.FC = () => {
|
|
|
70
70
|
key: 'userManual',
|
|
71
71
|
label: (
|
|
72
72
|
<a
|
|
73
|
-
href={
|
|
73
|
+
href={
|
|
74
|
+
isSimplifiedChinese
|
|
75
|
+
? 'https://nocode.docs.nocobase.com/cn/guide/'
|
|
76
|
+
: 'https://nocode.docs.nocobase.com/guide/'
|
|
77
|
+
}
|
|
74
78
|
target="_blank"
|
|
75
79
|
rel="noreferrer"
|
|
76
80
|
>
|
|
@@ -0,0 +1,13 @@
|
|
|
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 { createContext } from 'react';
|
|
11
|
+
|
|
12
|
+
// Internal callback for dismissing the mobile topbar after a nested menu action completes.
|
|
13
|
+
export const MobileTopbarActionsContext = createContext<(() => void) | undefined>(undefined);
|
|
@@ -11,13 +11,14 @@ import { EllipsisOutlined } from '@ant-design/icons';
|
|
|
11
11
|
import { css } from '@emotion/css';
|
|
12
12
|
import { FlowModelRenderer } from '@nocobase/flow-engine';
|
|
13
13
|
import { ConfigProvider, Divider, Popover, theme } from 'antd';
|
|
14
|
-
import React, { useCallback, useMemo, useState } from 'react';
|
|
14
|
+
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
15
15
|
import { ErrorBoundary } from 'react-error-boundary';
|
|
16
16
|
import { useAclSnippets } from '../../../acl/useAclSnippets';
|
|
17
17
|
import type { CustomToken } from '../../../theme';
|
|
18
18
|
import { TopbarActionModel } from '../../models/topbar/TopbarActionModel';
|
|
19
19
|
import { USER_CENTER_ACTION_ID } from '../../models/topbar/UserCenterTopbarActionModel';
|
|
20
20
|
import { HelpLite } from './HelpLite';
|
|
21
|
+
import { MobileTopbarActionsContext } from './MobileTopbarActionsContext';
|
|
21
22
|
|
|
22
23
|
const topbarActionsBarClassName = css`
|
|
23
24
|
display: inline-flex;
|
|
@@ -206,11 +207,21 @@ export const TopbarActionsBar = React.memo((props: { actions: TopbarActionModel[
|
|
|
206
207
|
setOpen(false);
|
|
207
208
|
}, []);
|
|
208
209
|
|
|
210
|
+
useEffect(() => {
|
|
211
|
+
if (!props.isMobile) {
|
|
212
|
+
setOpen(false);
|
|
213
|
+
}
|
|
214
|
+
}, [props.isMobile]);
|
|
215
|
+
|
|
209
216
|
if (props.isMobile) {
|
|
210
217
|
return (
|
|
211
218
|
<Popover
|
|
212
219
|
rootClassName={popoverStyle}
|
|
213
|
-
content={
|
|
220
|
+
content={
|
|
221
|
+
<MobileTopbarActionsContext.Provider value={handleContentClick}>
|
|
222
|
+
<TopbarActionsContent actions={props.actions} onActionClick={handleContentClick} />
|
|
223
|
+
</MobileTopbarActionsContext.Provider>
|
|
224
|
+
}
|
|
214
225
|
color={customToken.colorBgHeader}
|
|
215
226
|
trigger="click"
|
|
216
227
|
open={open}
|