Skip to content

Commit f5f999b

Browse files
ggbond2077QIQI03
authored andcommitted
- fix: query library execute undefined args
- fix: table empty data table border style - fix(withParamsForMap): fix withParamsForMap mainly on node for performance
1 parent 62b21f9 commit f5f999b

File tree

17 files changed

+815
-415
lines changed

17 files changed

+815
-415
lines changed

client/packages/openblocks-core/lib/index.d.ts

Lines changed: 585 additions & 366 deletions
Large diffs are not rendered by default.

client/packages/openblocks-core/lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ function getDependNode(subPaths, exposingNodes) {
729729
for (var _i = 0, subPaths_1 = subPaths; _i < subPaths_1.length; _i++) {
730730
var subPath = subPaths_1[_i];
731731
var subNode = nodes[subPath];
732-
if (!subNode) {
732+
if (!nodes.hasOwnProperty(subPath) || !subNode) {
733733
break;
734734
}
735735
node = subNode;

client/packages/openblocks-core/src/eval/utils/evaluate.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ function getDependNode(
140140
const path = [];
141141
for (const subPath of subPaths) {
142142
const subNode = nodes[subPath];
143-
if (!subNode) {
143+
if (!nodes.hasOwnProperty(subPath) || !subNode) {
144144
break;
145145
}
146146
node = subNode;

client/packages/openblocks/src/comps/comps/moduleContainerComp/moduleMethodListComp.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ function MethodItem(props: MethodItemProps) {
136136
const { name, action, params, onDelete } = props;
137137

138138
const handleOnParamsConfigChange = () => {
139-
action.dispatch(WithParamsActionControl.changeParamDataAction(params.getParamsData()));
139+
action.dispatch(WithParamsActionControl.setParamDataAction(params.getParamsData()));
140140
};
141141

142142
const content = (

client/packages/openblocks/src/comps/comps/moduleContainerComp/moduleMethodListItemComp.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class ModuleMethodListItemComp extends ModuleMethodListItemBase {
3333

3434
await getPromiseAfterDispatch(
3535
this.children.action.dispatch,
36-
WithParamsActionControl.changeParamDataAction(paramsMap),
36+
WithParamsActionControl.setParamDataAction(paramsMap),
3737
{ autoHandleAfterReduce: true }
3838
);
3939
return getPromiseAfterDispatch(

client/packages/openblocks/src/comps/comps/tableComp/resizeableTable.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,16 @@ export const TableWrapper = styled.div<{
346346
fill: #fff;
347347
}
348348
349+
> thead > tr:first-child {
350+
th:first-child {
351+
border-top-left-radius: 0px;
352+
}
353+
354+
th:last-child {
355+
border-top-right-radius: 0px;
356+
}
357+
}
358+
349359
// hide the bottom border of the last row
350360
${(props) =>
351361
props.toolbarPosition !== "below" &&
@@ -355,6 +365,10 @@ export const TableWrapper = styled.div<{
355365
}
356366
`}
357367
}
368+
369+
.ant-table-expanded-row-fixed:after {
370+
border-right: unset !important;
371+
}
358372
}
359373
}
360374
}

client/packages/openblocks/src/comps/generators/withParams.test.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { NumberControl, StringControl } from "comps/controls/codeControl";
2+
import { evalAndReduce } from "comps/utils";
23
import { MultiCompBuilder } from "./multi";
34
import { withParams, withParamsWithDefault } from "./withParams";
4-
import { evalAndReduce } from "comps/utils";
55

66
const TestComp = new MultiCompBuilder(
77
{
@@ -29,15 +29,13 @@ describe("withParams", () => {
2929
expect(output.v1).toEqual("v1: 1");
3030
expect(output.v2).toEqual(2);
3131

32-
comp = comp.reduce(Comp.changeParamDataAction({ a: "10" }));
32+
comp = comp.reduce(Comp.setParamDataAction({ a: "10" }));
3333
comp = evalAndReduce(comp);
3434
output = comp.getView();
3535
expect(output.v1).toEqual("v1: 101");
3636
expect(output.v2).toEqual(102);
3737
});
38-
});
3938

40-
describe("withParams", () => {
4139
it("normal with default", () => {
4240
const Comp = withParamsWithDefault(TestComp, { a: 10 });
4341
let comp = new Comp(testData);
@@ -46,10 +44,21 @@ describe("withParams", () => {
4644
expect(output.v1).toEqual("v1: 11");
4745
expect(output.v2).toEqual(12);
4846

49-
comp = comp.reduce(Comp.changeParamDataAction({ a: "10" } as any));
47+
comp = comp.reduce(Comp.setParamDataAction({ a: "10" } as any));
5048
comp = evalAndReduce(comp);
5149
output = comp.getView();
5250
expect(output.v1).toEqual("v1: 101");
5351
expect(output.v2).toEqual(102);
5452
});
53+
54+
it("keep node stable", () => {
55+
const Comp = withParams(TestComp, ["a"]);
56+
let comp = new Comp(testData);
57+
comp = evalAndReduce(comp);
58+
const comp1 = comp.setParams({ a: 0 });
59+
expect(comp1.getComp().node() === comp.getComp().node()).toBeTruthy();
60+
expect(comp1.node()?.children.comp.child === comp.node()?.children.comp.child).toBeTruthy();
61+
expect((comp1 as any).extraNode() === (comp as any).extraNode()).toBeTruthy();
62+
expect(comp1.node()?.children.wrap === comp.node()?.children.wrap).toBeTruthy();
63+
});
5564
});

client/packages/openblocks/src/comps/generators/withParams.tsx

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,18 @@ import _ from "lodash";
22
import {
33
Comp,
44
CompAction,
5-
CompActionTypes,
65
CompParams,
76
ConstructorToComp,
87
ConstructorToNodeType,
98
ConstructorToView,
109
customAction,
11-
fromRecord,
1210
fromValue,
1311
isMyCustomAction,
1412
MultiBaseComp,
1513
MultiCompConstructor,
1614
Node,
1715
NodeToValue,
16+
RecordNode,
1817
updateNodesV2Action,
1918
wrapContext,
2019
WrapContextFn,
@@ -58,8 +57,14 @@ export function withParamsWithDefault<
5857
type ChildrenType = {
5958
comp: ConstructorToComp<TCtor>;
6059
};
61-
type CompNodeValue = NodeToValue<ConstructorToNodeType<TCtor>>;
62-
type NodeType = Node<{ wrap: WrapContextFn<CompNodeValue>; original: CompNodeValue }> | undefined;
60+
type CompNode = NonNullable<ConstructorToNodeType<TCtor>>;
61+
type CompNodeValue = NodeToValue<CompNode>;
62+
type NodeType =
63+
| RecordNode<{
64+
wrap: Node<WrapContextFn<CompNodeValue>>;
65+
comp: WrapContextNodeV2<CompNodeValue>;
66+
}>
67+
| undefined;
6368

6469
class WithParamComp
6570
extends MultiBaseComp<ChildrenType, JSONValue, NodeType>
@@ -71,7 +76,7 @@ export function withParamsWithDefault<
7176
/**
7277
* this action requires eval to be valid, don't use it directly with reduce
7378
*/
74-
static changeParamDataAction(paramData: ParamValues) {
79+
static setParamDataAction(paramData: ParamValues) {
7580
return customAction({
7681
type: "setParamData",
7782
data: paramData,
@@ -121,19 +126,13 @@ export function withParamsWithDefault<
121126
}
122127
if (isMyCustomAction<SetCompAction>(action, "setComp")) {
123128
const child = action.value.comp.changeDispatch(this.getComp().dispatch);
124-
return this.setChild("comp", child);
125-
}
126-
if (action.type === CompActionTypes.UPDATE_NODES_V2) {
127-
let child = this.getComp().reduce(updateNodesV2Action(action.value.original));
128-
let comp = this.setChild("comp", child);
129-
const wrap = action.value.wrap;
130-
if (wrap && this.wrapValue !== wrap) {
131-
comp = setFieldsNoTypeCheck(comp, { wrapValue: wrap });
129+
if (action.value.comp.node() !== child.node()) {
130+
console.error("withParams setComp node diff. action: ", action);
132131
}
133-
// console.info("WithParamsReduce. action: ", action, " original: ", action.value.original, " oldComp: ", this, " newComp: ", comp);
134-
return comp;
132+
return this.setChild("comp", child);
135133
}
136-
return super.reduce(action);
134+
const comp = super.reduce(action);
135+
return comp;
137136
}
138137

139138
setParams(params: Partial<ParamValues>): this {
@@ -155,14 +154,30 @@ export function withParamsWithDefault<
155154
return this.params;
156155
}
157156

158-
override nodeWithoutCache() {
157+
protected override childrenNode() {
159158
const compNode: ConstructorToNodeType<TCtor> = this.getComp().node();
160-
if (_.isNil(compNode)) return undefined;
161-
const wrapNode = wrapContext(compNode);
162-
159+
if (_.isNil(compNode)) return {} as {};
163160
const paramNodes = this.getParamNodes();
164161
const originalNode = new WrapContextNodeV2(compNode, paramNodes);
165-
return fromRecord({ wrap: wrapNode, original: originalNode }) as NonNullable<NodeType>;
162+
return { comp: originalNode };
163+
}
164+
165+
protected override extraNode() {
166+
const compNode: ConstructorToNodeType<TCtor> = this.getComp().node();
167+
if (_.isNil(compNode)) return undefined;
168+
const wrapNode = wrapContext(compNode);
169+
const result = {
170+
node: { wrap: wrapNode },
171+
updateNodeFields: (value: any) => {
172+
return { wrapValue: value.wrap };
173+
},
174+
};
175+
return lastValueIfEqual(
176+
this,
177+
"extra_node",
178+
[result, compNode] as const,
179+
(a, b) => a[1] === b[1]
180+
)[0];
166181
}
167182

168183
private getParamNodes(): Record<keyof ParamValues, Node<unknown>> {
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { NumberControl, StringControl } from "comps/controls/codeControl";
2+
import { evalAndReduce } from "comps/utils";
3+
import _ from "lodash";
4+
import { updateNodesV2Action } from "openblocks-core";
5+
import { getObjectId } from "util/objectUtils";
6+
import { cost } from "util/perfUtils";
7+
import { MultiCompBuilder } from "./multi";
8+
import { withParamsForMap } from "./withParamsForMap";
9+
10+
const TestComp = new MultiCompBuilder(
11+
{
12+
v1: StringControl,
13+
v2: NumberControl,
14+
},
15+
(props) => props
16+
)
17+
.setPropertyViewFn(() => <></>)
18+
.build();
19+
20+
const testData = {
21+
value: {
22+
v1: "v1: {{a + 1}}",
23+
v2: "{{a + 2}}",
24+
},
25+
};
26+
27+
const Comp = withParamsForMap(TestComp, ["a"]);
28+
function checkNode(comp: InstanceType<typeof Comp>, str: string) {
29+
const coreComp = comp.getOriginalComp().getComp();
30+
console.info(`---- checkNode ${str}. node id: `, getObjectId(coreComp.node()));
31+
_.forEach(comp.getView(), (subComp, key) => {
32+
if (subComp.getComp().node() !== coreComp.node()) {
33+
console.info(" diff node id: ", getObjectId(subComp.getComp().node()), " key: ", key);
34+
}
35+
});
36+
}
37+
38+
describe("withParamsForMap", () => {
39+
it("performance", () => {
40+
let comp = new Comp(testData);
41+
comp = evalAndReduce(comp);
42+
// checkNode(comp, "0");
43+
const paramValues = _.chain(_.range(10000))
44+
.map((idx) => [idx, { a: idx }] as const)
45+
.fromPairs()
46+
.value();
47+
comp = comp.batchSet(paramValues);
48+
// checkNode(comp, "1");
49+
// console.info("node: ", comp.node());
50+
// console.info("node[map]: ", (comp.node() as any).children.__map__);
51+
const costMs = cost(() => evalAndReduce(comp));
52+
// checkNode(comp, "2");
53+
// evalPerfUtil.print(0);
54+
expect(costMs < 10000).toBeTruthy();
55+
});
56+
57+
it("test_node", () => {
58+
let comp = new TestComp({ value: { v1: "", v2: "2" } });
59+
comp = evalAndReduce(comp);
60+
const comp1 = comp.reduce(updateNodesV2Action(testData.value));
61+
expect(comp1.node() === comp.node()).toBeTruthy();
62+
expect(getObjectId(comp1.node()) === getObjectId(comp.node())).toBeTruthy();
63+
});
64+
});

client/packages/openblocks/src/comps/generators/withParamsForMap.tsx

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ import {
77
ConstructorToComp,
88
ConstructorToNodeType,
99
ConstructorToView,
10+
fromRecord,
1011
isChildAction,
1112
MultiBaseComp,
1213
MultiCompConstructor,
1314
Node,
1415
NodeToValue,
1516
RecordConstructorToComp,
1617
wrapDispatch,
18+
updateNodesV2Action,
1719
} from "openblocks-core";
1820
import { ReactNode } from "react";
1921
import { JSONValue } from "util/jsonTypes";
@@ -79,9 +81,10 @@ export function withParamsForMapWithDefault<
7981
}
8082

8183
batchSet(paramValuesMap: Record<string, ParamValues>) {
82-
const mapComp = _.mapValues(paramValuesMap, (values) =>
83-
this.children[CHILD_KEY].reduce(WithParamsCompCtor.changeParamDataAction(values))
84-
);
84+
const mapComp = _.mapValues(paramValuesMap, (values, key) => {
85+
const comp = this.getOriginalComp().setParams(values);
86+
return comp;
87+
});
8588
const mapChild = this.children.__map__.reduce(MapCtor.batchSetCompAction(mapComp));
8689
return this.setChild("__map__", mapChild);
8790
}
@@ -106,27 +109,67 @@ export function withParamsForMapWithDefault<
106109

107110
override reduce(action: CompAction): this {
108111
let newComp = super.reduce(action);
112+
newComp.getOriginalComp().node(); // for cache
109113

110114
if (
111115
isChildAction(action) &&
112116
action.path[0] === CHILD_KEY &&
113117
action.type !== CompActionTypes.UPDATE_NODES_V2
114118
) {
115-
const newMap = _.mapValues(this.children.__map__.children, (comp) => {
116-
return comp.reduce(WithParamsCompCtor.setCompAction(newComp.children.__comp__.getComp()));
119+
const newMap = _.mapValues(this.getView(), (comp) => {
120+
return comp.reduce(WithParamsCompCtor.setCompAction(newComp.getOriginalComp().getComp()));
117121
});
118122
newComp = newComp.setChild(
119123
"__map__",
120124
this.children.__map__.reduce(MapCtor.batchSetCompAction(newMap))
121125
);
126+
} else if (
127+
action.type === CompActionTypes.UPDATE_NODES_V2
128+
// && newComp.getOriginalComp().getComp().node() !== this.getOriginalComp().getComp().node()
129+
) {
130+
const value = action.value;
131+
const newMap = _.chain(newComp.getView())
132+
.mapValues((comp, key) => {
133+
if (value.__map__.hasOwnProperty(key)) {
134+
return comp;
135+
}
136+
const wrap = value[CHILD_KEY].wrap;
137+
const compValue = { wrap, comp: wrap(comp.getParams()) };
138+
return comp.reduce(updateNodesV2Action(compValue));
139+
})
140+
.value();
141+
const newMapComp = newComp.children.__map__.reduce(MapCtor.batchSetCompAction(newMap));
142+
newComp = newComp.setChild("__map__", newMapComp);
122143
}
123144

145+
/*
146+
_.forEach(newComp.getView(), (comp, key) => {
147+
if (comp.getComp().node() !== newComp.getOriginalComp().getComp().node()) {
148+
console.info("node diff. key:", key, " action: ", action, " subComp: ", comp, " coreComp: ", newComp.getOriginalComp().getComp());
149+
}
150+
})
151+
*/
152+
124153
return newComp;
125154
}
126155

127156
getOriginalComp() {
128157
return this.children[CHILD_KEY];
129158
}
159+
160+
override childrenNode() {
161+
const compNode = this.getOriginalComp().node()!;
162+
const coreNode = this.getOriginalComp().getComp().node();
163+
const mapNode = fromRecord(
164+
_.chain(this.getView())
165+
.pickBy((comp, key) => {
166+
return comp.getComp().node() !== coreNode;
167+
})
168+
.mapValues((comp) => comp.node()!)
169+
.value()
170+
);
171+
return { [CHILD_KEY]: compNode, __map__: mapNode };
172+
}
130173
}
131174

132175
return WithParamsForMapComp;

client/packages/openblocks/src/comps/queries/queryComp.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ QueryCompTmp = class extends QueryCompTmp {
321321
queryId,
322322
applicationId: applicationId,
323323
applicationPath: parentApplicationPath,
324-
args: action.args,
324+
args: action.args ?? {},
325325
timeout: this.children.timeout,
326326
}),
327327
() => this.dispatch(changeChildAction("isFetching", false)),

0 commit comments

Comments
 (0)