@nocobase/client-v2 2.4.0-alpha.17 → 2.4.0-alpha.19
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/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/models/actions/getHasManyDeleteFilterByTk.d.ts +12 -0
- package/es/flow/models/base/PageModel/closeGuard.d.ts +8 -1
- package/es/flow/models/blocks/form/EditFormModel.d.ts +2 -0
- 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 +19 -0
- package/es/index.mjs +125 -88
- package/lib/index.js +128 -91
- package/package.json +7 -7
- package/src/components/form/VariableInput.tsx +1 -0
- package/src/flow/FlowModelRepository.ts +47 -1
- package/src/flow/FlowPage.tsx +19 -10
- package/src/flow/__tests__/FlowModelRepository.test.ts +38 -1
- package/src/flow/__tests__/FlowPage.test.tsx +78 -46
- package/src/flow/admin-shell/admin-layout/AdminLayoutComponent.tsx +8 -1
- package/src/flow/admin-shell/admin-layout/__tests__/TopbarActionsBar.mobile.test.tsx +55 -1
- package/src/flow/models/actions/BulkDeleteActionModel.tsx +13 -2
- package/src/flow/models/actions/DeleteActionModel.tsx +16 -2
- package/src/flow/models/actions/__tests__/DeleteActionModel.test.ts +256 -0
- package/src/flow/models/actions/getHasManyDeleteFilterByTk.ts +40 -0
- 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/details/DetailsItemModel.tsx +62 -1
- package/src/flow/models/blocks/details/__tests__/DetailsItemModel.spacing.test.tsx +77 -0
- package/src/flow/models/blocks/form/EditFormModel.tsx +23 -1
- package/src/flow/models/blocks/form/__tests__/EditFormModel.pagination.test.tsx +77 -0
- package/src/flow/models/blocks/table/TableBlockModel.tsx +4 -10
- 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/topbar/UserCenterTopbarActionModel.tsx +58 -28
- package/src/flow/useRouteContentRequest.tsx +42 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/client-v2",
|
|
3
|
-
"version": "2.4.0-alpha.
|
|
3
|
+
"version": "2.4.0-alpha.19",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "es/index.mjs",
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
"@formily/antd-v5": "1.2.3",
|
|
28
28
|
"@formily/react": "^2.2.27",
|
|
29
29
|
"@formily/shared": "^2.2.27",
|
|
30
|
-
"@nocobase/evaluators": "2.4.0-alpha.
|
|
31
|
-
"@nocobase/flow-engine": "2.4.0-alpha.
|
|
32
|
-
"@nocobase/sdk": "2.4.0-alpha.
|
|
33
|
-
"@nocobase/shared": "2.4.0-alpha.
|
|
34
|
-
"@nocobase/utils": "2.4.0-alpha.
|
|
30
|
+
"@nocobase/evaluators": "2.4.0-alpha.19",
|
|
31
|
+
"@nocobase/flow-engine": "2.4.0-alpha.19",
|
|
32
|
+
"@nocobase/sdk": "2.4.0-alpha.19",
|
|
33
|
+
"@nocobase/shared": "2.4.0-alpha.19",
|
|
34
|
+
"@nocobase/utils": "2.4.0-alpha.19",
|
|
35
35
|
"ahooks": "^3.7.2",
|
|
36
36
|
"antd": "5.24.2",
|
|
37
37
|
"antd-style": "3.7.1",
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"react-router-dom": "^6.30.1",
|
|
50
50
|
"zxing-wasm": "^3.1.3"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "b958d8e10e75dd27b0e7a2882ffc8f9bda9da0d8"
|
|
53
53
|
}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { FlowModel, IFlowModelRepository } from '@nocobase/flow-engine';
|
|
10
|
+
import { type CreateModelOptions, type FlowEngine, FlowModel, IFlowModelRepository } from '@nocobase/flow-engine';
|
|
11
11
|
import type { BaseApplication } from '../BaseApplication';
|
|
12
12
|
import _ from 'lodash';
|
|
13
13
|
|
|
@@ -180,6 +180,21 @@ export class FlowModelRepository implements IFlowModelRepository<FlowModel> {
|
|
|
180
180
|
return data ? _.cloneDeep(data) : data;
|
|
181
181
|
}
|
|
182
182
|
|
|
183
|
+
async ensureRouteContent(options: CreateModelOptions) {
|
|
184
|
+
const existing = await this.findOne({ parentId: options.parentId, subKey: options.subKey });
|
|
185
|
+
if (existing) return existing;
|
|
186
|
+
|
|
187
|
+
const response = await this.app.apiClient.request({
|
|
188
|
+
method: 'POST',
|
|
189
|
+
url: 'flowModels:save',
|
|
190
|
+
params: { ensureRouteContent: true },
|
|
191
|
+
data: options,
|
|
192
|
+
});
|
|
193
|
+
const persisted = await this.findOne({ uid: response.data.data });
|
|
194
|
+
if (!persisted) throw new Error('Could not load the initialized route content');
|
|
195
|
+
return persisted;
|
|
196
|
+
}
|
|
197
|
+
|
|
183
198
|
async save(model: FlowModel, options?: { onlyStepParams?: boolean }) {
|
|
184
199
|
const data = model.serialize();
|
|
185
200
|
if (options?.onlyStepParams) {
|
|
@@ -220,3 +235,34 @@ export class FlowModelRepository implements IFlowModelRepository<FlowModel> {
|
|
|
220
235
|
return response.data?.data;
|
|
221
236
|
}
|
|
222
237
|
}
|
|
238
|
+
|
|
239
|
+
// A tab renderer can be mounted again when the UI Editor adds or removes its controls.
|
|
240
|
+
const confirmedRouteModels = new WeakSet<FlowModel>();
|
|
241
|
+
|
|
242
|
+
export function isRouteContentConfirmed(model: FlowModel) {
|
|
243
|
+
return confirmedRouteModels.has(model);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export async function loadRouteContentForEditing(engine: FlowEngine, options: CreateModelOptions) {
|
|
247
|
+
const repository = engine.modelRepository;
|
|
248
|
+
if (!(repository instanceof FlowModelRepository)) {
|
|
249
|
+
return engine.loadOrCreateModel(options);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// A route model can live in the outer engine while its page lives in this view's engine.
|
|
253
|
+
let cached = engine.findModelByParentId(options.parentId, options.subKey);
|
|
254
|
+
if (!cached) {
|
|
255
|
+
engine.forEachModel((model) => {
|
|
256
|
+
if (model.parentId === options.parentId && model.subKey === options.subKey) cached = model;
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
if (cached && isRouteContentConfirmed(cached)) return cached;
|
|
260
|
+
const data = await repository.ensureRouteContent({ ...options, uid: cached?.uid });
|
|
261
|
+
if (cached && cached.uid !== data.uid) engine.removeModelWithSubModels(cached.uid);
|
|
262
|
+
const model = await engine.createModelAsync(data);
|
|
263
|
+
if (model.parent && model.parent.subModels[options.subKey] !== model) {
|
|
264
|
+
model.parent.setSubModel(options.subKey, model);
|
|
265
|
+
}
|
|
266
|
+
confirmedRouteModels.add(model);
|
|
267
|
+
return model;
|
|
268
|
+
}
|
package/src/flow/FlowPage.tsx
CHANGED
|
@@ -15,6 +15,10 @@ import {
|
|
|
15
15
|
useFlowViewContext,
|
|
16
16
|
} from '@nocobase/flow-engine';
|
|
17
17
|
import type { FlowEngineContext, FlowModel, FlowModelRendererProps, ModelConstructor } from '@nocobase/flow-engine';
|
|
18
|
+
import { observer } from '@formily/reactive-react';
|
|
19
|
+
import { loadRouteContentForEditing } from './FlowModelRepository';
|
|
20
|
+
import { RouteContent, useRouteContentRequest } from './useRouteContentRequest';
|
|
21
|
+
import { RouteModel } from './models/base/RouteModel';
|
|
18
22
|
import { useRequest } from 'ahooks';
|
|
19
23
|
import React from 'react';
|
|
20
24
|
import FlowRoute from './components/FlowRoute';
|
|
@@ -85,12 +89,13 @@ const bindViewLayoutState = (model: FlowModel, ctx?: FlowPageViewContext | null)
|
|
|
85
89
|
});
|
|
86
90
|
};
|
|
87
91
|
|
|
88
|
-
export const FlowPage =
|
|
92
|
+
export const FlowPage = observer((props: FlowPageProps & Record<string, unknown>) => {
|
|
89
93
|
const { pageModelClass = 'ChildPageModel', parentId, onModelLoaded, defaultTabTitle, ...rest } = props;
|
|
90
94
|
const flowEngine = useFlowEngine();
|
|
95
|
+
const isRoute = !!parentId && flowEngine.getModel(parentId, true) instanceof RouteModel;
|
|
91
96
|
const ctx = useFlowViewContext<FlowPageViewContext>();
|
|
92
|
-
const {
|
|
93
|
-
async () => {
|
|
97
|
+
const { model, loading, error, needsConfirmation } = useRouteContentRequest(
|
|
98
|
+
async (forEditing) => {
|
|
94
99
|
const ModelClass = await flowEngine.getModelClassAsync(pageModelClass);
|
|
95
100
|
if (!ModelClass) {
|
|
96
101
|
throw new Error(`[NocoBase] Page model class '${pageModelClass}' is not registered.`);
|
|
@@ -101,7 +106,7 @@ export const FlowPage = React.memo((props: FlowPageProps & Record<string, unknow
|
|
|
101
106
|
async: true,
|
|
102
107
|
parentId,
|
|
103
108
|
subKey: 'page',
|
|
104
|
-
subType: 'object',
|
|
109
|
+
subType: 'object' as const,
|
|
105
110
|
use: pageModelClass,
|
|
106
111
|
};
|
|
107
112
|
const isRuntimeRecordScopedPage =
|
|
@@ -136,7 +141,11 @@ export const FlowPage = React.memo((props: FlowPageProps & Record<string, unknow
|
|
|
136
141
|
}
|
|
137
142
|
const data =
|
|
138
143
|
(isRuntimeRecordScopedPage && (await flowEngine.loadModel({ ...options, refresh: true }))) ||
|
|
139
|
-
(
|
|
144
|
+
(forEditing
|
|
145
|
+
? await loadRouteContentForEditing(flowEngine, options)
|
|
146
|
+
: await flowEngine.loadOrCreateModel(options, {
|
|
147
|
+
skipSave: isRoute || !flowEngine.context.flowSettingsEnabled,
|
|
148
|
+
}));
|
|
140
149
|
if (data?.uid && onModelLoaded) {
|
|
141
150
|
data.context.addDelegate(ctx);
|
|
142
151
|
bindViewLayoutState(data, ctx);
|
|
@@ -145,17 +154,17 @@ export const FlowPage = React.memo((props: FlowPageProps & Record<string, unknow
|
|
|
145
154
|
}
|
|
146
155
|
return data;
|
|
147
156
|
},
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
},
|
|
157
|
+
isRoute && flowEngine.context.flowSettingsEnabled,
|
|
158
|
+
[parentId, pageModelClass, defaultTabTitle],
|
|
151
159
|
);
|
|
152
160
|
if (error) {
|
|
153
161
|
throw error;
|
|
154
162
|
}
|
|
155
|
-
if (
|
|
163
|
+
if (!model?.uid || (loading && !isRoute)) {
|
|
156
164
|
return <SkeletonFallback style={{ margin: ctx?.isMobileLayout ? 8 : ctx?.themeToken.marginBlock }} />;
|
|
157
165
|
}
|
|
158
|
-
|
|
166
|
+
const page = <InternalFlowPage uid={model.uid} {...rest} />;
|
|
167
|
+
return isRoute ? <RouteContent pending={needsConfirmation}>{page}</RouteContent> : page;
|
|
159
168
|
});
|
|
160
169
|
|
|
161
170
|
FlowPage.displayName = 'FlowPage';
|
|
@@ -8,9 +8,46 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { describe, it, expect, vi } from 'vitest';
|
|
11
|
-
import {
|
|
11
|
+
import { FlowEngine, FlowModel } from '@nocobase/flow-engine';
|
|
12
|
+
import type { BaseApplication } from '../../BaseApplication';
|
|
13
|
+
import { FlowModelRepository, loadRouteContentForEditing } from '../FlowModelRepository';
|
|
12
14
|
|
|
13
15
|
describe('FlowModelRepository', () => {
|
|
16
|
+
it('keeps the browse UID when the route parent is outside the current engine', async () => {
|
|
17
|
+
const engine = new FlowEngine();
|
|
18
|
+
engine.registerModels({ FlowModel });
|
|
19
|
+
const request = vi
|
|
20
|
+
.fn()
|
|
21
|
+
.mockResolvedValueOnce({ data: {} })
|
|
22
|
+
.mockResolvedValueOnce({ data: { data: 'browse-uid' } })
|
|
23
|
+
.mockResolvedValueOnce({
|
|
24
|
+
data: { data: { uid: 'browse-uid', use: 'FlowModel', parentId: 'route', subKey: 'page' } },
|
|
25
|
+
});
|
|
26
|
+
engine.setModelRepository(new FlowModelRepository({ apiClient: { request } } as unknown as BaseApplication));
|
|
27
|
+
const options = { use: 'FlowModel', parentId: 'route', subKey: 'page', subType: 'object' as const };
|
|
28
|
+
const browsing = engine.createModel({ ...options, uid: 'browse-uid' });
|
|
29
|
+
expect(await loadRouteContentForEditing(engine, options)).toBe(browsing);
|
|
30
|
+
expect(await loadRouteContentForEditing(engine, options)).toBe(browsing);
|
|
31
|
+
expect(request).toHaveBeenCalledTimes(3);
|
|
32
|
+
expect(request.mock.calls[1][0].data).toMatchObject({ ...options, uid: browsing.uid });
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('retries the first edit when the initialization request fails', async () => {
|
|
36
|
+
const engine = new FlowEngine();
|
|
37
|
+
engine.registerModels({ FlowModel });
|
|
38
|
+
const options = { use: 'FlowModel', parentId: 'route', subKey: 'page', subType: 'object' as const };
|
|
39
|
+
const model = engine.createModel({ ...options, uid: 'browse-uid' });
|
|
40
|
+
const request = vi
|
|
41
|
+
.fn()
|
|
42
|
+
.mockResolvedValueOnce({ data: {} })
|
|
43
|
+
.mockRejectedValueOnce(new Error('Save failed'))
|
|
44
|
+
.mockResolvedValueOnce({ data: { data: { ...options, uid: model.uid } } });
|
|
45
|
+
engine.setModelRepository(new FlowModelRepository({ apiClient: { request } } as unknown as BaseApplication));
|
|
46
|
+
await expect(loadRouteContentForEditing(engine, options)).rejects.toThrow('Save failed');
|
|
47
|
+
expect(await loadRouteContentForEditing(engine, options)).toBe(model);
|
|
48
|
+
expect(request).toHaveBeenCalledTimes(3);
|
|
49
|
+
});
|
|
50
|
+
|
|
14
51
|
it('dedupes concurrent findOne requests with same key', async () => {
|
|
15
52
|
const request = vi.fn(async () => {
|
|
16
53
|
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
@@ -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
|
|
|
@@ -81,6 +81,8 @@ const popoverStyle = css`
|
|
|
81
81
|
}
|
|
82
82
|
`;
|
|
83
83
|
|
|
84
|
+
const siderToggleZIndex = 200;
|
|
85
|
+
|
|
84
86
|
const CollapsedButton: FC<{ collapsed: boolean }> = (props) => {
|
|
85
87
|
const { token } = antdTheme.useToken();
|
|
86
88
|
const customToken = token as CustomToken;
|
|
@@ -107,7 +109,7 @@ const CollapsedButton: FC<{ collapsed: boolean }> = (props) => {
|
|
|
107
109
|
.ant-pro-sider-collapsed-button {
|
|
108
110
|
top: 64px;
|
|
109
111
|
left: ${props.collapsed ? 52 : (customToken.siderWidth || 200) - 12}px;
|
|
110
|
-
z-index:
|
|
112
|
+
z-index: ${siderToggleZIndex};
|
|
111
113
|
transition: left 0.2s;
|
|
112
114
|
}
|
|
113
115
|
`}
|
|
@@ -606,6 +608,11 @@ export const AdminLayoutComponent = observer((props: any) => {
|
|
|
606
608
|
z-index: 101 !important;
|
|
607
609
|
}
|
|
608
610
|
|
|
611
|
+
/* The switcher popup is mounted inside the header, while the sider toggle is portaled outside it. */
|
|
612
|
+
.ant-layout-header.ant-pro-layout-header:has(.ant-pro-layout-apps-icon-active) {
|
|
613
|
+
z-index: ${siderToggleZIndex + 1} !important;
|
|
614
|
+
}
|
|
615
|
+
|
|
609
616
|
.ant-pro-layout-apps-popover {
|
|
610
617
|
z-index: 2000 !important;
|
|
611
618
|
}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
|
|
10
|
+
import { act, cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
|
|
11
11
|
import { Drawer, Input } from 'antd';
|
|
12
12
|
import React, { useState } from 'react';
|
|
13
13
|
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
@@ -157,6 +157,60 @@ describe('mobile user center popover', () => {
|
|
|
157
157
|
expect(screen.queryByRole('img', { name: 'ellipsis' })).not.toBeInTheDocument();
|
|
158
158
|
});
|
|
159
159
|
|
|
160
|
+
it('shows profile while checking availability and ignores a result from an earlier opening', async () => {
|
|
161
|
+
let resolveFirst!: (visible: boolean) => void;
|
|
162
|
+
const firstCheck = new Promise<boolean>((resolve) => {
|
|
163
|
+
resolveFirst = resolve;
|
|
164
|
+
});
|
|
165
|
+
const check = vi.fn().mockReturnValueOnce(firstCheck).mockResolvedValueOnce(false).mockResolvedValueOnce(true);
|
|
166
|
+
const prepareProfile = vi.fn(async () => {});
|
|
167
|
+
class Profile extends UserCenterActionItemModel {
|
|
168
|
+
static itemId = 'profile';
|
|
169
|
+
prepare = prepareProfile;
|
|
170
|
+
label = 'Edit profile';
|
|
171
|
+
}
|
|
172
|
+
class Verification extends UserCenterActionItemModel {
|
|
173
|
+
static itemId = 'verification';
|
|
174
|
+
label = 'Verification';
|
|
175
|
+
checkAvailability = check;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const model = new UserCenterTopbarActionModel({ uid: 'menu', use: 'UserCenterTopbarActionModel' });
|
|
179
|
+
Object.defineProperty(model, 'flowEngine', {
|
|
180
|
+
value: {
|
|
181
|
+
getSubclassesOfAsync: () =>
|
|
182
|
+
new Map<string, typeof UserCenterActionItemModel>([
|
|
183
|
+
['profile', Profile],
|
|
184
|
+
['verification', Verification],
|
|
185
|
+
]),
|
|
186
|
+
createModel: ({ use, uid }: { use: typeof UserCenterActionItemModel; uid: string }) =>
|
|
187
|
+
new use({ uid, use: use.name }),
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
render(<TopbarActionsBar actions={[model]} />);
|
|
191
|
+
|
|
192
|
+
const closeMenu = async () => {
|
|
193
|
+
fireEvent.click(screen.getByRole('button', { name: 'Edit profile' }));
|
|
194
|
+
await waitFor(() => expect(screen.queryByRole('button', { name: 'Edit profile' })).not.toBeInTheDocument());
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
await openUserMenu(false);
|
|
198
|
+
expect(check).toHaveBeenCalledTimes(1);
|
|
199
|
+
expect(screen.queryByRole('button', { name: 'Verification' })).not.toBeInTheDocument();
|
|
200
|
+
await closeMenu();
|
|
201
|
+
|
|
202
|
+
await openUserMenu(false);
|
|
203
|
+
expect(check).toHaveBeenCalledTimes(2);
|
|
204
|
+
await act(async () => resolveFirst(true));
|
|
205
|
+
expect(screen.queryByRole('button', { name: 'Verification' })).not.toBeInTheDocument();
|
|
206
|
+
await closeMenu();
|
|
207
|
+
|
|
208
|
+
await openUserMenu(false);
|
|
209
|
+
expect(await screen.findByRole('button', { name: 'Verification' })).toBeVisible();
|
|
210
|
+
expect(check).toHaveBeenCalledTimes(3);
|
|
211
|
+
expect(prepareProfile).toHaveBeenCalledOnce();
|
|
212
|
+
});
|
|
213
|
+
|
|
160
214
|
it.each([true, false])('respects closeOnChange=%s for preference selectors', async (closeOnChange) => {
|
|
161
215
|
const onChange = vi.fn(async () => {});
|
|
162
216
|
const item = new UserCenterSelectItemModel({ uid: 'language', use: 'UserCenterSelectItemModel' });
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
import { tExpr, MultiRecordResource } from '@nocobase/flow-engine';
|
|
11
11
|
import { ButtonProps } from 'antd';
|
|
12
12
|
import { ActionModel, ActionSceneEnum } from '../base';
|
|
13
|
+
import { getHasManyDeleteFilterByTk } from './getHasManyDeleteFilterByTk';
|
|
13
14
|
|
|
14
15
|
export class BulkDeleteActionModel extends ActionModel {
|
|
15
16
|
static scene = ActionSceneEnum.collection;
|
|
@@ -49,11 +50,21 @@ BulkDeleteActionModel.registerFlow({
|
|
|
49
50
|
return;
|
|
50
51
|
}
|
|
51
52
|
const resource = ctx.blockModel.resource as MultiRecordResource;
|
|
52
|
-
|
|
53
|
+
const selectedRows = resource.getSelectedRows();
|
|
54
|
+
if (selectedRows.length === 0) {
|
|
53
55
|
ctx.message.warning(ctx.t('Please select at least one record to delete'));
|
|
54
56
|
return;
|
|
55
57
|
}
|
|
56
|
-
|
|
58
|
+
const association = ctx.blockModel.association;
|
|
59
|
+
const filterByTk =
|
|
60
|
+
association?.type === 'hasMany'
|
|
61
|
+
? getHasManyDeleteFilterByTk(association.targetKey, selectedRows)
|
|
62
|
+
: ctx.blockModel.collection.getFilterByTK(selectedRows);
|
|
63
|
+
if (association?.type === 'hasMany' && filterByTk === undefined) {
|
|
64
|
+
ctx.message.error(ctx.t('The association target key is missing or invalid.'));
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
await resource.destroy(filterByTk);
|
|
57
68
|
ctx.message.success(ctx.t('Selected records deleted successfully'));
|
|
58
69
|
},
|
|
59
70
|
},
|
|
@@ -7,9 +7,10 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { tExpr } from '@nocobase/flow-engine';
|
|
10
|
+
import { tExpr, SingleRecordResource } from '@nocobase/flow-engine';
|
|
11
11
|
import type { ButtonProps } from 'antd/es/button';
|
|
12
12
|
import { ActionModel, ActionSceneEnum } from '../base';
|
|
13
|
+
import { getHasManyDeleteFilterByTk } from './getHasManyDeleteFilterByTk';
|
|
13
14
|
|
|
14
15
|
export class DeleteActionModel extends ActionModel {
|
|
15
16
|
static scene = ActionSceneEnum.record;
|
|
@@ -53,7 +54,20 @@ DeleteActionModel.registerFlow({
|
|
|
53
54
|
ctx.message.error(ctx.t('No resource or record selected for deletion'));
|
|
54
55
|
return;
|
|
55
56
|
}
|
|
56
|
-
|
|
57
|
+
const association = ctx.blockModel.association;
|
|
58
|
+
const filterByTk =
|
|
59
|
+
association?.type === 'hasMany'
|
|
60
|
+
? getHasManyDeleteFilterByTk(association.targetKey, ctx.record)
|
|
61
|
+
: ctx.blockModel.collection.getFilterByTK(ctx.record);
|
|
62
|
+
if (association?.type === 'hasMany' && filterByTk === undefined) {
|
|
63
|
+
ctx.message.error(ctx.t('The association target key is missing or invalid.'));
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (association?.type === 'hasMany' && ctx.resource instanceof SingleRecordResource) {
|
|
67
|
+
await ctx.resource.destroy({ params: { filterByTk } });
|
|
68
|
+
} else {
|
|
69
|
+
await ctx.resource.destroy(filterByTk);
|
|
70
|
+
}
|
|
57
71
|
ctx.message.success(ctx.t('Record deleted successfully'));
|
|
58
72
|
},
|
|
59
73
|
},
|