@nocobase/client-v2 2.2.0-beta.6 → 2.2.0-beta.8
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/flow/actions/afterSuccess.d.ts +8 -1
- package/es/flow/actions/index.d.ts +1 -1
- package/es/flow/admin-shell/admin-layout/AdminLayoutSlotModels.d.ts +1 -0
- package/es/flow/models/blocks/form/submitHandler.d.ts +1 -1
- package/es/flow/models/blocks/form/value-runtime/runtime.d.ts +9 -0
- package/es/flow/models/blocks/js-block/JSBlock.d.ts +1 -0
- 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/resolveViewParamsToViewList.d.ts +1 -1
- package/es/index.mjs +105 -89
- package/lib/index.js +106 -90
- package/package.json +7 -7
- package/src/PluginSettingsManager.ts +53 -0
- package/src/__tests__/PluginSettingsManager.test.ts +13 -0
- package/src/__tests__/plugin-manager.test.tsx +44 -2
- package/src/__tests__/settings-center.test.tsx +7 -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/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__/openView.defineProps.route.test.tsx +104 -0
- package/src/flow/actions/afterSuccess.tsx +142 -3
- package/src/flow/actions/dataScopeFilter.ts +10 -0
- package/src/flow/actions/index.ts +1 -1
- package/src/flow/actions/openView.tsx +38 -4
- 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 +1 -0
- package/src/flow/admin-shell/admin-layout/AdminLayoutSlotModels.tsx +5 -4
- package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutModel.test.tsx +82 -0
- package/src/flow/components/FieldAssignRulesEditor.tsx +66 -9
- package/src/flow/components/__tests__/FieldAssignRulesEditor.test.tsx +427 -0
- package/src/flow/components/__tests__/fieldAssignOptions.test.ts +151 -3
- package/src/flow/components/fieldAssignOptions.ts +155 -27
- package/src/flow/getViewDiffAndUpdateHidden.tsx +1 -0
- package/src/flow/models/base/ActionModelCore.tsx +6 -4
- package/src/flow/models/base/__tests__/ActionModelCore.render.test.tsx +37 -0
- package/src/flow/models/blocks/filter-form/fields/FilterFormCustomFieldModel.tsx +1 -1
- package/src/flow/models/blocks/form/FormActionModel.tsx +1 -1
- 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 +87 -0
- package/src/flow/models/blocks/form/value-runtime/runtime.ts +91 -0
- package/src/flow/models/blocks/js-block/JSBlock.tsx +223 -2
- package/src/flow/models/blocks/js-block/__tests__/JSBlockModel.test.tsx +150 -0
- package/src/flow/models/blocks/table/TableActionsColumnModel.tsx +35 -12
- package/src/flow/models/blocks/table/TableBlockModel.tsx +25 -14
- package/src/flow/models/blocks/table/__tests__/TableActionsColumnModel.test.tsx +57 -1
- package/src/flow/models/blocks/table/__tests__/TableBlockModel.dragSort.test.ts +127 -0
- package/src/flow/models/blocks/table/__tests__/TableBlockModel.rowSelection.test.tsx +1 -0
- 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/resolveViewParamsToViewList.tsx +11 -3
- package/src/nocobase-buildin-plugin/index.tsx +0 -2
- package/src/settings-center/SystemSettingsPage.tsx +1 -2
- package/src/settings-center/plugin-manager/PluginCard.tsx +2 -2
- package/src/settings-center/utils.tsx +0 -6
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
import React from 'react';
|
|
11
11
|
import { describe, it, expect, vi } from 'vitest';
|
|
12
|
+
import { RUNJS_OPEN_VIEW_ROUTE_STATE } from '@nocobase/flow-engine';
|
|
12
13
|
import { openView } from '../openView';
|
|
13
14
|
import { FlowPage } from '../../FlowPage';
|
|
14
15
|
|
|
@@ -50,6 +51,27 @@ describe('openView action - route mode defineProperties/defineMethods', () => {
|
|
|
50
51
|
return { ctx, engine };
|
|
51
52
|
};
|
|
52
53
|
|
|
54
|
+
const createFirstStageCtx = (inputArgs: Record<PropertyKey, unknown>) => {
|
|
55
|
+
const navigateTo = vi.fn();
|
|
56
|
+
const ctx: any = {
|
|
57
|
+
inputArgs,
|
|
58
|
+
engine: { context: { themeToken: { colorBgLayout: '#fff' } } },
|
|
59
|
+
model: {
|
|
60
|
+
uid: 'popup-uid',
|
|
61
|
+
context: {
|
|
62
|
+
inputArgs: {},
|
|
63
|
+
defineProperty: vi.fn(),
|
|
64
|
+
},
|
|
65
|
+
flowEngine: { context: { themeToken: { colorBgLayout: '#fff' } } },
|
|
66
|
+
},
|
|
67
|
+
view: {
|
|
68
|
+
navigation: { navigateTo },
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
return { ctx, navigateTo };
|
|
73
|
+
};
|
|
74
|
+
|
|
53
75
|
it('injects defineProperties/defineMethods on onModelLoaded even when not present in current inputArgs', async () => {
|
|
54
76
|
const { ctx } = createRouteManagedCtx();
|
|
55
77
|
|
|
@@ -149,4 +171,86 @@ describe('openView action - route mode defineProperties/defineMethods', () => {
|
|
|
149
171
|
const defineMethodCalls = pageModelContext.defineMethod.mock.calls.map((c: any[]) => c[0]);
|
|
150
172
|
expect(defineMethodCalls).toContain('pong');
|
|
151
173
|
});
|
|
174
|
+
|
|
175
|
+
it('adds route state to first-stage navigation only for RunJS ctx.openView calls', async () => {
|
|
176
|
+
const { ctx, navigateTo } = createFirstStageCtx({
|
|
177
|
+
mode: 'dialog',
|
|
178
|
+
size: 'large',
|
|
179
|
+
[RUNJS_OPEN_VIEW_ROUTE_STATE]: { mode: 'dialog', size: 'large' },
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
await openView.handler(ctx, { mode: 'drawer', size: 'medium', navigation: true });
|
|
183
|
+
|
|
184
|
+
expect(navigateTo).toHaveBeenCalledWith({
|
|
185
|
+
viewUid: 'popup-uid',
|
|
186
|
+
filterByTk: undefined,
|
|
187
|
+
sourceId: undefined,
|
|
188
|
+
tabUid: undefined,
|
|
189
|
+
openViewRouteState: { mode: 'dialog', size: 'large' },
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('normalizes first-stage RunJS route state mode on mobile layout', async () => {
|
|
194
|
+
const { ctx, navigateTo } = createFirstStageCtx({
|
|
195
|
+
isMobileLayout: true,
|
|
196
|
+
mode: 'dialog',
|
|
197
|
+
size: 'large',
|
|
198
|
+
[RUNJS_OPEN_VIEW_ROUTE_STATE]: { mode: 'dialog', size: 'large' },
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
await openView.handler(ctx, { mode: 'drawer', size: 'medium', navigation: true });
|
|
202
|
+
|
|
203
|
+
expect(navigateTo).toHaveBeenCalledWith({
|
|
204
|
+
viewUid: 'popup-uid',
|
|
205
|
+
filterByTk: undefined,
|
|
206
|
+
sourceId: undefined,
|
|
207
|
+
tabUid: undefined,
|
|
208
|
+
openViewRouteState: { mode: 'embed', size: 'large' },
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it('uses route replay mode and size before persisted openView defaults', async () => {
|
|
213
|
+
const { ctx } = createRouteManagedCtx();
|
|
214
|
+
ctx.inputArgs.mode = 'dialog';
|
|
215
|
+
ctx.inputArgs.size = 'large';
|
|
216
|
+
|
|
217
|
+
await openView.handler(ctx, { mode: 'drawer', size: 'medium', navigation: true });
|
|
218
|
+
|
|
219
|
+
expect(ctx.viewer.open).toHaveBeenCalledWith(
|
|
220
|
+
expect.objectContaining({
|
|
221
|
+
type: 'dialog',
|
|
222
|
+
width: '80%',
|
|
223
|
+
}),
|
|
224
|
+
);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it('uses decoded openView route state during route replay', async () => {
|
|
228
|
+
const { ctx } = createRouteManagedCtx();
|
|
229
|
+
ctx.inputArgs.openViewRouteState = { mode: 'dialog', size: 'large' };
|
|
230
|
+
|
|
231
|
+
await openView.handler(ctx, { mode: 'drawer', size: 'medium', navigation: true });
|
|
232
|
+
|
|
233
|
+
expect(ctx.viewer.open).toHaveBeenCalledWith(
|
|
234
|
+
expect.objectContaining({
|
|
235
|
+
type: 'dialog',
|
|
236
|
+
width: '80%',
|
|
237
|
+
}),
|
|
238
|
+
);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it('keeps first-stage navigation unchanged for non-RunJS openView calls', async () => {
|
|
242
|
+
const { ctx, navigateTo } = createFirstStageCtx({
|
|
243
|
+
mode: 'dialog',
|
|
244
|
+
size: 'large',
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
await openView.handler(ctx, { mode: 'drawer', size: 'medium', navigation: true });
|
|
248
|
+
|
|
249
|
+
expect(navigateTo).toHaveBeenCalledWith({
|
|
250
|
+
viewUid: 'popup-uid',
|
|
251
|
+
filterByTk: undefined,
|
|
252
|
+
sourceId: undefined,
|
|
253
|
+
tabUid: undefined,
|
|
254
|
+
});
|
|
255
|
+
});
|
|
152
256
|
});
|
|
@@ -7,13 +7,152 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
FlowContext,
|
|
12
|
+
createRecordMetaFactory,
|
|
13
|
+
createRecordResolveOnServerWithLocal,
|
|
14
|
+
defineAction,
|
|
15
|
+
tExpr,
|
|
16
|
+
useFlowSettingsContext,
|
|
17
|
+
type Collection,
|
|
18
|
+
type FlowRuntimeContext,
|
|
19
|
+
type MetaTreeNode,
|
|
20
|
+
type PropertyMetaFactory,
|
|
21
|
+
} from '@nocobase/flow-engine';
|
|
11
22
|
import { isURL } from '@nocobase/utils/client';
|
|
12
|
-
import {
|
|
23
|
+
import React, { useMemo } from 'react';
|
|
24
|
+
import {
|
|
25
|
+
TextAreaWithContextSelector,
|
|
26
|
+
type TextAreaWithContextSelectorProps,
|
|
27
|
+
} from '../components/TextAreaWithContextSelector';
|
|
28
|
+
|
|
29
|
+
type ResponseRecordPlainStepContext = {
|
|
30
|
+
steps?: FlowRuntimeContext['steps'];
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
type ResponseRecordFlowDefinitionContext = {
|
|
34
|
+
flowKey?: string;
|
|
35
|
+
model?: {
|
|
36
|
+
getFlow?: (flowKey: string) => { steps?: Record<string, unknown> } | undefined;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
type ResponseRecordContext = FlowContext &
|
|
41
|
+
ResponseRecordPlainStepContext & {
|
|
42
|
+
blockModel?: { collection?: Collection };
|
|
43
|
+
collection?: Collection;
|
|
44
|
+
model?: FlowRuntimeContext['model'] & { collection?: Collection };
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
function getResponseRecordSteps(ctx: FlowContext | ResponseRecordPlainStepContext): FlowRuntimeContext['steps'] {
|
|
48
|
+
return 'steps' in ctx ? ctx.steps || {} : {};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function getAfterSuccessResponseRecord(ctx: FlowContext | ResponseRecordPlainStepContext) {
|
|
52
|
+
const steps = getResponseRecordSteps(ctx);
|
|
53
|
+
const preferredStepKeys = ['saveResource', 'submit', 'request', 'apply', 'save'];
|
|
54
|
+
|
|
55
|
+
for (const stepKey of preferredStepKeys) {
|
|
56
|
+
if (Object.prototype.hasOwnProperty.call(steps, stepKey) && steps[stepKey]?.result != null) {
|
|
57
|
+
return steps[stepKey].result;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const results = Object.entries(steps)
|
|
62
|
+
.filter(([stepKey, step]) => stepKey !== 'afterSuccess' && step?.result != null)
|
|
63
|
+
.map(([, step]) => step.result);
|
|
64
|
+
return results[results.length - 1];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function getResponseRecordMeta(ctx: ResponseRecordContext): PropertyMetaFactory | undefined {
|
|
68
|
+
if (!hasResponseRecordSource(ctx)) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const collectionAccessor = getResponseRecordCollectionAccessor(ctx);
|
|
72
|
+
if (!collectionAccessor()) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
return createRecordMetaFactory(collectionAccessor, ctx.t('Response record'), () => {
|
|
76
|
+
const collection = collectionAccessor();
|
|
77
|
+
const record = getAfterSuccessResponseRecord(ctx);
|
|
78
|
+
if (!collection || !record) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
const filterByTk = collection.getFilterByTK(record);
|
|
83
|
+
if (filterByTk == null) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
collection: collection.name,
|
|
88
|
+
dataSourceKey: collection.dataSourceKey || 'main',
|
|
89
|
+
filterByTk,
|
|
90
|
+
};
|
|
91
|
+
} catch (error) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function hasResponseRecordSource(ctx: FlowContext | ResponseRecordPlainStepContext) {
|
|
98
|
+
if (Object.prototype.hasOwnProperty.call(getResponseRecordSteps(ctx), 'saveResource')) {
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const { model, flowKey } = ctx as ResponseRecordFlowDefinitionContext;
|
|
103
|
+
if (!model || typeof model.getFlow !== 'function' || !flowKey) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return Object.prototype.hasOwnProperty.call(model.getFlow(flowKey)?.steps || {}, 'saveResource');
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function getResponseRecordCollectionAccessor(ctx: ResponseRecordContext) {
|
|
111
|
+
return () => ctx.blockModel?.collection || ctx.collection || ctx.model?.collection || null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function getMetaTreeWithResponseRecord(ctx: FlowRuntimeContext): MetaTreeNode[] {
|
|
115
|
+
const responseRecordMeta = getResponseRecordMeta(ctx);
|
|
116
|
+
if (!responseRecordMeta) {
|
|
117
|
+
return ctx.getPropertyMetaTree?.() || [];
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const scoped = new FlowContext();
|
|
121
|
+
scoped.addDelegate(ctx);
|
|
122
|
+
scoped.defineProperty('responseRecord', {
|
|
123
|
+
get: () => getAfterSuccessResponseRecord(ctx),
|
|
124
|
+
cache: false,
|
|
125
|
+
resolveOnServer: createRecordResolveOnServerWithLocal(getResponseRecordCollectionAccessor(ctx), () =>
|
|
126
|
+
getAfterSuccessResponseRecord(ctx),
|
|
127
|
+
),
|
|
128
|
+
meta: responseRecordMeta,
|
|
129
|
+
});
|
|
130
|
+
return scoped.getPropertyMetaTree();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function AfterSuccessRedirectTextArea(props: TextAreaWithContextSelectorProps) {
|
|
134
|
+
const flowCtx = useFlowSettingsContext();
|
|
135
|
+
const metaTree = useMemo(() => () => getMetaTreeWithResponseRecord(flowCtx), [flowCtx]);
|
|
136
|
+
|
|
137
|
+
return <TextAreaWithContextSelector {...props} metaTree={metaTree} />;
|
|
138
|
+
}
|
|
13
139
|
|
|
14
140
|
export const afterSuccess = defineAction({
|
|
15
141
|
name: 'afterSuccess',
|
|
16
142
|
title: tExpr('After successful submission'),
|
|
143
|
+
defineProperties(ctx) {
|
|
144
|
+
const responseRecordMeta = getResponseRecordMeta(ctx);
|
|
145
|
+
return {
|
|
146
|
+
responseRecord: {
|
|
147
|
+
get: () => getAfterSuccessResponseRecord(ctx),
|
|
148
|
+
cache: false,
|
|
149
|
+
resolveOnServer: createRecordResolveOnServerWithLocal(getResponseRecordCollectionAccessor(ctx), () =>
|
|
150
|
+
getAfterSuccessResponseRecord(ctx),
|
|
151
|
+
),
|
|
152
|
+
...(responseRecordMeta ? { meta: responseRecordMeta } : {}),
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
},
|
|
17
156
|
uiSchema: {
|
|
18
157
|
successMessage: {
|
|
19
158
|
type: 'string',
|
|
@@ -46,7 +185,7 @@ export const afterSuccess = defineAction({
|
|
|
46
185
|
type: 'string',
|
|
47
186
|
title: tExpr('Link'),
|
|
48
187
|
'x-decorator': 'FormItem',
|
|
49
|
-
'x-component':
|
|
188
|
+
'x-component': AfterSuccessRedirectTextArea,
|
|
50
189
|
'x-reactions': {
|
|
51
190
|
dependencies: ['actionAfterSuccess'],
|
|
52
191
|
fulfill: {
|
|
@@ -12,6 +12,12 @@ import { transformFilter } from '@nocobase/utils/client';
|
|
|
12
12
|
import _ from 'lodash';
|
|
13
13
|
|
|
14
14
|
const PRESERVE_NULL = { __nocobaseDataScopeNull__: true };
|
|
15
|
+
const SERVER_CURRENT_ROLE_VARIABLE = '{{$nRole}}';
|
|
16
|
+
const CURRENT_ROLE_EXPRESSION_RE = /^\s*\{\{\s*ctx\.role\s*\}\}\s*$/;
|
|
17
|
+
|
|
18
|
+
function isCurrentRoleExpression(value: unknown) {
|
|
19
|
+
return typeof value === 'string' && CURRENT_ROLE_EXPRESSION_RE.test(value);
|
|
20
|
+
}
|
|
15
21
|
|
|
16
22
|
function isPreserveNull(value: any) {
|
|
17
23
|
return (
|
|
@@ -45,6 +51,10 @@ function markEmptyVariableValues(rawNode: any, resolvedNode: any) {
|
|
|
45
51
|
}
|
|
46
52
|
|
|
47
53
|
if ('path' in rawNode && 'operator' in rawNode) {
|
|
54
|
+
if (isCurrentRoleExpression(rawNode.value)) {
|
|
55
|
+
resolvedNode.value = SERVER_CURRENT_ROLE_VARIABLE;
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
48
58
|
if (
|
|
49
59
|
isVariableExpression(rawNode.value) &&
|
|
50
60
|
(resolvedNode.value === undefined || resolvedNode.value === null || resolvedNode.value === '')
|
|
@@ -7,7 +7,15 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
defineAction,
|
|
12
|
+
tExpr,
|
|
13
|
+
FlowModelContext,
|
|
14
|
+
FlowModel,
|
|
15
|
+
FlowExitAllException,
|
|
16
|
+
createOpenViewRouteState,
|
|
17
|
+
RUNJS_OPEN_VIEW_ROUTE_STATE,
|
|
18
|
+
} from '@nocobase/flow-engine';
|
|
11
19
|
import React from 'react';
|
|
12
20
|
import { FlowPage } from '../FlowPage';
|
|
13
21
|
import { PageModel, RootPageModel } from '../models';
|
|
@@ -291,8 +299,32 @@ export const openView = defineAction({
|
|
|
291
299
|
? (inputArgs as any).associationName
|
|
292
300
|
: (params as any)?.associationName;
|
|
293
301
|
const mergedTabUid = typeof inputArgs.tabUid !== 'undefined' ? inputArgs.tabUid : params.tabUid;
|
|
294
|
-
|
|
295
|
-
const
|
|
302
|
+
const hasRunJSOpenViewRouteState = Object.prototype.hasOwnProperty.call(inputArgs, RUNJS_OPEN_VIEW_ROUTE_STATE);
|
|
303
|
+
const runJSOpenViewRouteStateInput = (inputArgs as Record<PropertyKey, unknown>)[RUNJS_OPEN_VIEW_ROUTE_STATE];
|
|
304
|
+
const runJSOpenViewRouteState = hasRunJSOpenViewRouteState
|
|
305
|
+
? createOpenViewRouteState(
|
|
306
|
+
runJSOpenViewRouteStateInput && typeof runJSOpenViewRouteStateInput === 'object'
|
|
307
|
+
? (runJSOpenViewRouteStateInput as { mode?: unknown; size?: unknown })
|
|
308
|
+
: {
|
|
309
|
+
mode: inputArgs.mode,
|
|
310
|
+
size: inputArgs.size,
|
|
311
|
+
},
|
|
312
|
+
)
|
|
313
|
+
: undefined;
|
|
314
|
+
const replayOpenViewRouteStateInput = (inputArgs as { openViewRouteState?: unknown }).openViewRouteState;
|
|
315
|
+
const replayOpenViewRouteState =
|
|
316
|
+
replayOpenViewRouteStateInput && typeof replayOpenViewRouteStateInput === 'object'
|
|
317
|
+
? createOpenViewRouteState(replayOpenViewRouteStateInput as { mode?: unknown; size?: unknown })
|
|
318
|
+
: undefined;
|
|
319
|
+
const runtimeOpenViewRouteState = runJSOpenViewRouteState || replayOpenViewRouteState;
|
|
320
|
+
// 移动端中只需要显示子页面。本次 dispatch 参数优先于持久化默认值。
|
|
321
|
+
const openMode = ctx.inputArgs?.isMobileLayout
|
|
322
|
+
? 'embed'
|
|
323
|
+
: runtimeOpenViewRouteState?.mode || ctx.inputArgs?.mode || params.mode || 'drawer';
|
|
324
|
+
const effectiveRunJSOpenViewRouteState =
|
|
325
|
+
runJSOpenViewRouteState && ctx.inputArgs?.isMobileLayout
|
|
326
|
+
? createOpenViewRouteState({ ...runJSOpenViewRouteState, mode: openMode })
|
|
327
|
+
: runJSOpenViewRouteState;
|
|
296
328
|
let navigation = typeof inputArgs.navigation !== 'undefined' ? inputArgs.navigation : params.navigation;
|
|
297
329
|
|
|
298
330
|
// 传递了上下文就必须禁用路由,否则下次路由打开会缺少上下文
|
|
@@ -313,6 +345,7 @@ export const openView = defineAction({
|
|
|
313
345
|
sourceId: mergedSourceId,
|
|
314
346
|
tabUid: mergedTabUid,
|
|
315
347
|
viewUid: ctx.model.context?.inputArgs?.viewUid || ctx.model.uid,
|
|
348
|
+
...(effectiveRunJSOpenViewRouteState ? { openViewRouteState: effectiveRunJSOpenViewRouteState } : {}),
|
|
316
349
|
} as Record<string, unknown>;
|
|
317
350
|
const pendingView = {
|
|
318
351
|
type: pendingType,
|
|
@@ -328,6 +361,7 @@ export const openView = defineAction({
|
|
|
328
361
|
filterByTk: mergedFilterByTk,
|
|
329
362
|
sourceId: mergedSourceId,
|
|
330
363
|
tabUid: mergedTabUid,
|
|
364
|
+
...(effectiveRunJSOpenViewRouteState ? { openViewRouteState: effectiveRunJSOpenViewRouteState } : {}),
|
|
331
365
|
};
|
|
332
366
|
ctx.view.navigation.navigateTo(nextView);
|
|
333
367
|
return;
|
|
@@ -373,7 +407,7 @@ export const openView = defineAction({
|
|
|
373
407
|
|
|
374
408
|
const pageModelClass =
|
|
375
409
|
ctx.inputArgs.pageModelClass || params.pageModelClass || ctx.layout?.childPageModelClass || 'ChildPageModel';
|
|
376
|
-
const size = ctx.inputArgs.size || params.size || 'medium';
|
|
410
|
+
const size = runtimeOpenViewRouteState?.size || ctx.inputArgs.size || params.size || 'medium';
|
|
377
411
|
let pageModelUid: string | null = null;
|
|
378
412
|
let pageModelRef: FlowModel | null = null;
|
|
379
413
|
|
|
@@ -8,7 +8,13 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { define, observable } from '@formily/reactive';
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
decodeOpenViewRouteState,
|
|
13
|
+
parsePathnameToViewParams,
|
|
14
|
+
type FlowEngine,
|
|
15
|
+
FlowModel,
|
|
16
|
+
type ViewParam,
|
|
17
|
+
} from '@nocobase/flow-engine';
|
|
12
18
|
import {
|
|
13
19
|
BaseLayoutRouteCoordinator,
|
|
14
20
|
type BaseLayoutRouteCoordinatorOptions,
|
|
@@ -116,20 +122,36 @@ const isStandardLayoutRelativePath = (relativePath: string) => {
|
|
|
116
122
|
}
|
|
117
123
|
|
|
118
124
|
let i = 1;
|
|
125
|
+
let currentViewUid = segments[0];
|
|
119
126
|
while (i < segments.length) {
|
|
120
127
|
const segment = segments[i];
|
|
128
|
+
|
|
121
129
|
if (segment === 'view') {
|
|
122
130
|
if (!segments[i + 1]) {
|
|
123
131
|
return false;
|
|
124
132
|
}
|
|
133
|
+
currentViewUid = segments[i + 1];
|
|
134
|
+
i += 2;
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (segment === 'opts') {
|
|
139
|
+
if (!segments[i + 1] || !decodeOpenViewRouteState(currentViewUid, segments[i + 1])) {
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
i += 2;
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (isKnownViewParamName(segment) && segments[i + 1]) {
|
|
125
147
|
i += 2;
|
|
126
148
|
continue;
|
|
127
149
|
}
|
|
128
150
|
|
|
129
|
-
if (!
|
|
151
|
+
if (!segments[i + 1]) {
|
|
130
152
|
return false;
|
|
131
153
|
}
|
|
132
|
-
|
|
154
|
+
return false;
|
|
133
155
|
}
|
|
134
156
|
|
|
135
157
|
return true;
|
|
@@ -272,7 +272,7 @@ export class BaseLayoutRouteCoordinator {
|
|
|
272
272
|
runtime.viewState[getKey(viewItem)]?.destroy?.(true);
|
|
273
273
|
delete runtime.viewState[getKey(viewItem)];
|
|
274
274
|
});
|
|
275
|
-
updateViewListHidden(viewList);
|
|
275
|
+
updateViewListHidden(viewList, !!this.layoutContext?.isMobileLayout);
|
|
276
276
|
}
|
|
277
277
|
|
|
278
278
|
if (viewsToOpen.length) {
|
|
@@ -299,7 +299,7 @@ export class BaseLayoutRouteCoordinator {
|
|
|
299
299
|
}
|
|
300
300
|
|
|
301
301
|
if (runtime.meta.active) {
|
|
302
|
-
updateViewListHidden(viewList);
|
|
302
|
+
updateViewListHidden(viewList, !!this.layoutContext?.isMobileLayout);
|
|
303
303
|
return;
|
|
304
304
|
}
|
|
305
305
|
|
|
@@ -390,6 +390,7 @@ export class BaseLayoutRouteCoordinator {
|
|
|
390
390
|
openViewParams?.associationName && !hasUsableSourceId(viewItem.params.sourceId)
|
|
391
391
|
? null
|
|
392
392
|
: openViewParams?.associationName;
|
|
393
|
+
const openViewRouteState = viewItem.params.openViewRouteState;
|
|
393
394
|
const openerUids = viewList.slice(0, viewItem.index).map((item) => item.params.viewUid);
|
|
394
395
|
const navigation = new ViewNavigation(
|
|
395
396
|
this.flowEngine.context,
|
|
@@ -408,6 +409,8 @@ export class BaseLayoutRouteCoordinator {
|
|
|
408
409
|
deactivateRef,
|
|
409
410
|
openerUids,
|
|
410
411
|
...viewItem.params,
|
|
412
|
+
...(openViewRouteState?.mode ? { mode: openViewRouteState.mode } : {}),
|
|
413
|
+
...(openViewRouteState?.size ? { size: openViewRouteState.size } : {}),
|
|
411
414
|
pageActive: runtime.meta.active,
|
|
412
415
|
activationControlledByLayout: true,
|
|
413
416
|
navigation,
|
|
@@ -121,6 +121,19 @@ describe('AdminLayoutRouteCoordinator', () => {
|
|
|
121
121
|
});
|
|
122
122
|
});
|
|
123
123
|
|
|
124
|
+
it('passes RunJS openView route state as runtime mode and size during route replay', () => {
|
|
125
|
+
const { dispatchEvent } = setupRouteReplay({
|
|
126
|
+
openViewRouteState: { mode: 'dialog', size: 'large' },
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
expect(dispatchEvent.mock.calls[0][1]).toMatchObject({
|
|
130
|
+
mode: 'dialog',
|
|
131
|
+
size: 'large',
|
|
132
|
+
openViewRouteState: { mode: 'dialog', size: 'large' },
|
|
133
|
+
triggerByRouter: true,
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
|
|
124
137
|
it('uses layout content element before route page placeholder as view target', () => {
|
|
125
138
|
const engine = new FlowEngine();
|
|
126
139
|
engine.registerModels({ RouteModel });
|
|
@@ -718,6 +718,7 @@ export const AdminLayoutComponent = observer((props: any) => {
|
|
|
718
718
|
<ConfigProvider theme={isMobile ? mobileTheme : theme}>
|
|
719
719
|
<GlobalStyle />
|
|
720
720
|
<AdminLayoutContent
|
|
721
|
+
designable={designable}
|
|
721
722
|
layout={adminLayoutModel?.layout}
|
|
722
723
|
onContentElementChange={handleLayoutContentElementChange}
|
|
723
724
|
/>
|
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
type AdminLayoutContentProps = {
|
|
27
27
|
onContentElementChange?: (element: HTMLDivElement | null) => void;
|
|
28
28
|
layout?: (AdminLayoutRoutePathLike & { routeName?: string }) | null;
|
|
29
|
+
designable?: boolean;
|
|
29
30
|
};
|
|
30
31
|
|
|
31
32
|
const layoutContentClass = css`
|
|
@@ -70,7 +71,7 @@ function isDvhSupported() {
|
|
|
70
71
|
return testEl.style.height === '1dvh';
|
|
71
72
|
}
|
|
72
73
|
|
|
73
|
-
const ShowTipWhenNoPages = observer((props: { layout?: AdminLayoutRoutePathLike | null }) => {
|
|
74
|
+
const ShowTipWhenNoPages = observer((props: { designable?: boolean; layout?: AdminLayoutRoutePathLike | null }) => {
|
|
74
75
|
const flowEngine = useFlowEngine();
|
|
75
76
|
const { token } = antdTheme.useToken();
|
|
76
77
|
const { t } = useTranslation();
|
|
@@ -79,7 +80,7 @@ const ShowTipWhenNoPages = observer((props: { layout?: AdminLayoutRoutePathLike
|
|
|
79
80
|
const visibleRoutes = isV2AdminRuntime(flowEngine.context.app)
|
|
80
81
|
? allAccessRoutes.filter((route) => isV2MenuRoute(route))
|
|
81
82
|
: allAccessRoutes;
|
|
82
|
-
const designable = !!flowEngine.context.flowSettingsEnabled;
|
|
83
|
+
const designable = !!props.designable || !!flowEngine.context.flowSettingsEnabled;
|
|
83
84
|
const layoutRoutePath = getAdminLayoutRoutePath(props.layout);
|
|
84
85
|
|
|
85
86
|
if (
|
|
@@ -104,7 +105,7 @@ const ShowTipWhenNoPages = observer((props: { layout?: AdminLayoutRoutePathLike
|
|
|
104
105
|
*
|
|
105
106
|
* 内容区不再依赖独立 FlowModel,而是通过回调把挂载目标同步给 root model。
|
|
106
107
|
*/
|
|
107
|
-
export const AdminLayoutContent: FC<AdminLayoutContentProps> = ({ onContentElementChange, layout }) => {
|
|
108
|
+
export const AdminLayoutContent: FC<AdminLayoutContentProps> = ({ designable, onContentElementChange, layout }) => {
|
|
108
109
|
const style = useMemo(() => (isDvhSupported() ? mobileHeight : undefined), []);
|
|
109
110
|
const params = useParams();
|
|
110
111
|
const matches = useMatches();
|
|
@@ -131,7 +132,7 @@ export const AdminLayoutContent: FC<AdminLayoutContentProps> = ({ onContentEleme
|
|
|
131
132
|
>
|
|
132
133
|
<div style={pageContentStyle}>
|
|
133
134
|
{shouldKeepAlive && pageUid ? <KeepAlive uid={pageUid}>{() => <Outlet />}</KeepAlive> : <Outlet />}
|
|
134
|
-
<ShowTipWhenNoPages layout={layout} />
|
|
135
|
+
<ShowTipWhenNoPages designable={designable} layout={layout} />
|
|
135
136
|
</div>
|
|
136
137
|
</div>
|
|
137
138
|
);
|
|
@@ -39,6 +39,7 @@ import {
|
|
|
39
39
|
FlowEngine,
|
|
40
40
|
FlowEngineProvider,
|
|
41
41
|
FlowModelRenderer,
|
|
42
|
+
encodeOpenViewRouteState,
|
|
42
43
|
useFlowEngine,
|
|
43
44
|
type FlowModel,
|
|
44
45
|
} from '@nocobase/flow-engine';
|
|
@@ -213,6 +214,87 @@ describe('AdminLayoutModel runtime', () => {
|
|
|
213
214
|
});
|
|
214
215
|
});
|
|
215
216
|
|
|
217
|
+
it('should parse RunJS openView route params into layout route view stack state', async () => {
|
|
218
|
+
const token = encodeOpenViewRouteState('popup', { mode: 'dialog', size: 'large' });
|
|
219
|
+
if (!token) {
|
|
220
|
+
throw new Error('Expected openView route state token.');
|
|
221
|
+
}
|
|
222
|
+
const engine = new FlowEngine();
|
|
223
|
+
engine.context.defineProperty('routeRepository', {
|
|
224
|
+
value: {
|
|
225
|
+
getRouteBySchemaUid: (pageUid: string) => ({ title: pageUid }),
|
|
226
|
+
},
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
render(
|
|
230
|
+
<FlowEngineProvider engine={engine}>
|
|
231
|
+
<TestAdminLayoutHost />
|
|
232
|
+
</FlowEngineProvider>,
|
|
233
|
+
);
|
|
234
|
+
const model = engine.getModel<TestAdminLayoutModel>('admin-layout-model');
|
|
235
|
+
expect(model).toBeTruthy();
|
|
236
|
+
|
|
237
|
+
act(() => {
|
|
238
|
+
model.syncLayoutRoute({
|
|
239
|
+
name: getLayoutPageViewRouteName('admin'),
|
|
240
|
+
pathname: `/admin/page-1/view/popup/opts/${token}/filterbytk/1`,
|
|
241
|
+
layoutBasePathname: '/admin',
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
await waitFor(() => {
|
|
246
|
+
expect(model.context.layoutRoute).toMatchObject({
|
|
247
|
+
type: 'page',
|
|
248
|
+
pageUid: 'page-1',
|
|
249
|
+
viewStack: [
|
|
250
|
+
{ viewUid: 'page-1' },
|
|
251
|
+
{
|
|
252
|
+
viewUid: 'popup',
|
|
253
|
+
openViewRouteState: { mode: 'dialog', size: 'large' },
|
|
254
|
+
filterByTk: '1',
|
|
255
|
+
},
|
|
256
|
+
],
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it('should reject malformed RunJS openView route params', async () => {
|
|
262
|
+
const wrongViewToken = encodeOpenViewRouteState('other-popup', { mode: 'dialog', size: 'large' });
|
|
263
|
+
if (!wrongViewToken) {
|
|
264
|
+
throw new Error('Expected openView route state token.');
|
|
265
|
+
}
|
|
266
|
+
const engine = new FlowEngine();
|
|
267
|
+
|
|
268
|
+
render(
|
|
269
|
+
<FlowEngineProvider engine={engine}>
|
|
270
|
+
<TestAdminLayoutHost />
|
|
271
|
+
</FlowEngineProvider>,
|
|
272
|
+
);
|
|
273
|
+
const model = engine.getModel<TestAdminLayoutModel>('admin-layout-model');
|
|
274
|
+
expect(model).toBeTruthy();
|
|
275
|
+
|
|
276
|
+
[
|
|
277
|
+
'/admin/page-1/sourceid',
|
|
278
|
+
'/admin/page-1/AbCdEfGh/filterbytk/1',
|
|
279
|
+
'/admin/page-1/view/popup/AbCdEfGh/filterbytk/1',
|
|
280
|
+
'/admin/page-1/view/popup/opts/AbCdEfGh/filterbytk/1',
|
|
281
|
+
'/admin/page-1/view/popup/openviewmode/dialog',
|
|
282
|
+
'/admin/page-1/view/popup/openviewsize/large',
|
|
283
|
+
`/admin/page-1/view/popup/opts/${wrongViewToken}/filterbytk/1`,
|
|
284
|
+
].forEach((pathname) => {
|
|
285
|
+
expect(
|
|
286
|
+
model.resolveLayoutRoute({
|
|
287
|
+
name: getLayoutPageViewRouteName('admin'),
|
|
288
|
+
pathname,
|
|
289
|
+
layoutBasePathname: '/admin',
|
|
290
|
+
}),
|
|
291
|
+
).toMatchObject({
|
|
292
|
+
type: 'notFound',
|
|
293
|
+
pathname,
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
|
|
216
298
|
it('should not consume global routes that belong to nested layouts', async () => {
|
|
217
299
|
const engine = new FlowEngine();
|
|
218
300
|
const routeRef = observable.ref({
|