Skip to content

Commit 1314d93

Browse files
authored
Merge pull request baidu#7411 from 2betop/crud-reload
fix: 修复crud 中 drawer 动作后不刷新问题 Close: baidu#6903
2 parents a0b0109 + b337c15 commit 1314d93

File tree

12 files changed

+701
-125
lines changed

12 files changed

+701
-125
lines changed

.vscode/launch.json

Lines changed: 16 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,18 @@
11
{
2-
// 使用 IntelliSense 了解相关属性。
3-
// 悬停以查看现有属性的描述。
4-
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
5-
"version": "0.2.0",
6-
"configurations": [
7-
{
8-
"type": "node",
9-
"request": "launch",
10-
"name": "Jest All",
11-
"program": "${workspaceFolder}/node_modules/.bin/jest",
12-
"args": ["--runInBand"],
13-
"sourceMaps": true,
14-
"console": "integratedTerminal",
15-
"internalConsoleOptions": "neverOpen",
16-
"disableOptimisticBPs": true,
17-
"runtimeExecutable": "/usr/local/bin/node",
18-
"windows": {
19-
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
20-
}
21-
},
22-
{
23-
"type": "node",
24-
"request": "launch",
25-
"name": "Jest Current File",
26-
"program": "${workspaceFolder}/node_modules/.bin/jest",
27-
"args": [
28-
"--no-cache",
29-
"--runInBand",
30-
"${relativeFile}"
31-
],
32-
"sourceMaps": true,
33-
"console": "integratedTerminal",
34-
"internalConsoleOptions": "neverOpen",
35-
"disableOptimisticBPs": true,
36-
"runtimeExecutable": "/usr/local/bin/node",
37-
"windows": {
38-
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
39-
}
40-
},
41-
{
42-
"type": "node",
43-
"request": "launch",
44-
"name": "Jest Current File Specified test",
45-
"program": "${workspaceFolder}/node_modules/.bin/jest",
46-
"args": [
47-
"--no-cache",
48-
"--runInBand",
49-
"${relativeFile}",
50-
"-t",
51-
"${input:testName}"
52-
],
53-
"sourceMaps": true,
54-
"console": "integratedTerminal",
55-
"internalConsoleOptions": "neverOpen",
56-
"disableOptimisticBPs": true,
57-
"runtimeExecutable": "/usr/local/bin/node",
58-
"windows": {
59-
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
60-
}
61-
}
62-
],
63-
"inputs": [
64-
{
65-
"id": "testName",
66-
"type": "promptString",
67-
"default": "",
68-
"description": "Run only tests with a name that matches the regex pattern."
2+
"version": "1.0.0",
3+
"configurations": [
4+
{
5+
"type": "node",
6+
"request": "launch",
7+
"name": "Jest: current file",
8+
//"env": { "NODE_ENV": "test" },
9+
"program": "${workspaceFolder}/node_modules/.bin/jest",
10+
"args": ["${fileBasenameNoExtension}"],
11+
"console": "integratedTerminal",
12+
"disableOptimisticBPs": true,
13+
"windows": {
14+
"program": "${workspaceFolder}/node_modules/jest/bin/jest"
6915
}
70-
]
71-
}
16+
}
17+
]
18+
}

packages/amis-core/src/RootRenderer.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,12 @@ export class RootRenderer extends React.Component<RootRendererProps> {
160160
window.open(mailto);
161161
} else if (action.actionType === 'dialog') {
162162
store.setCurrentAction(action);
163-
store.openDialog(ctx, undefined, action.callback, delegate);
163+
store.openDialog(
164+
ctx,
165+
undefined,
166+
action.callback,
167+
delegate || (this.context as any)
168+
);
164169
} else if (action.actionType === 'drawer') {
165170
store.setCurrentAction(action);
166171
store.openDrawer(ctx, undefined, undefined, delegate);
@@ -323,9 +328,14 @@ export class RootRenderer extends React.Component<RootRendererProps> {
323328
actionType: 'dialog',
324329
dialog: dialog
325330
});
326-
store.openDialog(ctx, undefined, confirmed => {
327-
resolve(confirmed);
328-
});
331+
store.openDialog(
332+
ctx,
333+
undefined,
334+
confirmed => {
335+
resolve(confirmed);
336+
},
337+
this.context as any
338+
);
329339
});
330340
}
331341

packages/amis-core/src/Scoped.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ export interface ScopedComponentType extends React.Component<RendererProps> {
5858
}
5959

6060
export interface IScopedContext {
61+
rendererType?: string;
62+
component?: ScopedComponentType;
6163
parent?: AliasIScopedContext;
6264
children?: AliasIScopedContext[];
6365
registerComponent: (component: ScopedComponentType) => void;
@@ -69,6 +71,10 @@ export interface IScopedContext {
6971
send: (target: string, ctx: RendererData) => void;
7072
close: (target: string) => void;
7173
closeById: (target: string) => void;
74+
getComponentsByRefPath: (
75+
session: string,
76+
path: string
77+
) => ScopedComponentType[];
7278
}
7379
type AliasIScopedContext = IScopedContext;
7480

@@ -78,14 +84,18 @@ export const ScopedContext = React.createContext(rootScopedContext);
7884
function createScopedTools(
7985
path?: string,
8086
parent?: AliasIScopedContext,
81-
env?: RendererEnv
87+
env?: RendererEnv,
88+
rendererType?: string
8289
): IScopedContext {
8390
const components: Array<ScopedComponentType> = [];
84-
const self = {
91+
const self: IScopedContext = {
92+
rendererType,
93+
component: undefined,
8594
parent,
8695
registerComponent(component: ScopedComponentType) {
8796
// 不要把自己注册在自己的 Scoped 上,自己的 Scoped 是给子节点们注册的。
8897
if (component.props.$path === path && parent) {
98+
self.component = component;
8999
return parent.registerComponent(component);
90100
}
91101

@@ -404,7 +414,8 @@ export function HocScoped<
404414
env: RendererEnv;
405415
}
406416
>(
407-
ComposedComponent: React.ComponentType<T>
417+
ComposedComponent: React.ComponentType<T>,
418+
rendererType?: string
408419
): React.ComponentType<
409420
T & {
410421
scopeRef?: (ref: any) => void;
@@ -430,7 +441,8 @@ export function HocScoped<
430441
this.scoped = createScopedTools(
431442
this.props.$path,
432443
context,
433-
this.props.env
444+
this.props.env,
445+
rendererType
434446
);
435447

436448
const scopeRef = props.scopeRef;

packages/amis-core/src/factory.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ export function registerRenderer(config: RendererConfig): RendererConfig {
186186
}
187187

188188
if (config.isolateScope) {
189-
config.component = Scoped(config.component);
189+
config.component = Scoped(config.component, config.type);
190190
}
191191

192192
const idx = findIndex(

packages/amis-core/src/renderers/Form.tsx

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,12 @@ export default class Form extends React.Component<FormProps, object> {
11461146
action.target &&
11471147
this.reloadTarget(filterTarget(action.target, values), values);
11481148
} else if (action.actionType === 'dialog') {
1149-
store.openDialog(data, undefined, action.callback);
1149+
store.openDialog(
1150+
data,
1151+
undefined,
1152+
action.callback,
1153+
delegate || (this.context as any)
1154+
);
11501155
} else if (action.actionType === 'drawer') {
11511156
store.openDrawer(data);
11521157
} else if (isEffectiveApi(action.api || api, values)) {
@@ -1275,7 +1280,12 @@ export default class Form extends React.Component<FormProps, object> {
12751280
return this.validate(true, throwErrors);
12761281
} else if (action.actionType === 'dialog') {
12771282
store.setCurrentAction(action);
1278-
store.openDialog(data, undefined, action.callback);
1283+
store.openDialog(
1284+
data,
1285+
undefined,
1286+
action.callback,
1287+
delegate || (this.context as any)
1288+
);
12791289
} else if (action.actionType === 'drawer') {
12801290
store.setCurrentAction(action);
12811291
store.openDrawer(data);
@@ -1444,9 +1454,14 @@ export default class Form extends React.Component<FormProps, object> {
14441454
actionType: 'dialog',
14451455
dialog: dialog
14461456
});
1447-
store.openDialog(ctx, undefined, confirmed => {
1448-
resolve(confirmed);
1449-
});
1457+
store.openDialog(
1458+
ctx,
1459+
undefined,
1460+
confirmed => {
1461+
resolve(confirmed);
1462+
},
1463+
this.context as any
1464+
);
14501465
});
14511466
}
14521467

0 commit comments

Comments
 (0)