Skip to content

Commit abf460b

Browse files
fix values not saved for comps inside table's expansion container
1 parent 4f06801 commit abf460b

File tree

6 files changed

+34
-22
lines changed

6 files changed

+34
-22
lines changed

client/packages/lowcoder/src/comps/comps/lazyLoadComp/lazyLoadComp.tsx

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,18 @@ function ViewLoading(props: { padding?: number }) {
3838
);
3939
}
4040

41-
interface RemoteCompReadyAction {
42-
type: "RemoteCompReady";
41+
export interface LazyCompReadyAction {
42+
type: "LazyCompReady";
4343
comp: Comp;
4444
}
4545

46-
interface RemoteCompViewProps {
46+
interface LazyCompViewProps {
4747
loadComp: () => Promise<void>;
4848
loadingElement?: () => React.ReactNode;
4949
errorElement?: (error: any) => React.ReactNode;
5050
}
5151

52-
function RemoteCompView(props: React.PropsWithChildren<RemoteCompViewProps>) {
52+
function LazyCompView(props: React.PropsWithChildren<LazyCompViewProps>) {
5353
const { loadComp, loadingElement, errorElement } = props;
5454
const [error, setError] = useState<any>("");
5555

@@ -100,20 +100,22 @@ export function lazyLoadComp(
100100
}
101101

102102
private async load() {
103+
console.log('lazyLoad ->', compName);
103104
if (!compPath) {
104105
return;
105106
}
106-
let RemoteExportedComp;
107+
let LazyExportedComp;
107108
if (!loader) {
108109
const module = await import(`../../${compPath}.tsx`);
109-
RemoteExportedComp = module[compName!];
110+
LazyExportedComp = module[compName!];
110111
} else {
111-
RemoteExportedComp = await loader();
112+
LazyExportedComp = await loader();
112113
}
113-
if (!RemoteExportedComp) {
114+
if (!LazyExportedComp) {
114115
log.error("loader not found, lazy load info:", compPath);
115116
return;
116117
}
118+
console.log(LazyExportedComp)
117119

118120
const params: CompParams<any> = {
119121
dispatch: this.dispatch,
@@ -122,12 +124,12 @@ export function lazyLoadComp(
122124
if (this.compValue) {
123125
params.value = this.compValue;
124126
}
125-
const RemoteCompWithErrorBound = withErrorBoundary(RemoteExportedComp);
127+
const LazyCompWithErrorBound = withErrorBoundary(LazyExportedComp);
126128
this.dispatch(
127-
customAction<RemoteCompReadyAction>(
129+
customAction<LazyCompReadyAction>(
128130
{
129-
type: "RemoteCompReady",
130-
comp: new RemoteCompWithErrorBound(params),
131+
type: "LazyCompReady",
132+
comp: new LazyCompWithErrorBound(params),
131133
},
132134
false
133135
)
@@ -138,7 +140,7 @@ export function lazyLoadComp(
138140
// const key = `${remoteInfo?.packageName}-${remoteInfo?.packageVersion}-${remoteInfo?.compName}`;
139141
const key = `${compName}`;
140142
return (
141-
<RemoteCompView key={key} loadComp={() => this.load()} loadingElement={loadingElement} />
143+
<LazyCompView key={key} loadComp={() => this.load()} loadingElement={loadingElement} />
142144
);
143145
}
144146

@@ -147,7 +149,7 @@ export function lazyLoadComp(
147149
}
148150

149151
reduce(action: CompAction<any>): this {
150-
if (isCustomAction<RemoteCompReadyAction>(action, "RemoteCompReady")) {
152+
if (isCustomAction<LazyCompReadyAction>(action, "LazyCompReady")) {
151153
// use real remote comp instance to replace RemoteCompLoader
152154
return action.value.comp as this;
153155
}

client/packages/lowcoder/src/comps/comps/moduleComp/moduleComp.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ type UpdateDslAction = {
6868
moduleDsl: Record<string, DSLType>;
6969
};
7070

71-
type ModuleReadyAction = {
71+
export type ModuleReadyAction = {
7272
type: "moduleReady";
7373
comp: RootComp;
7474
};
@@ -263,7 +263,6 @@ class ModuleTmpComp extends ModuleCompBase {
263263

264264
override reduce(action: CompAction<JSONValue>): this {
265265
const appId = this.children.appId.getView();
266-
267266
// init
268267
if (isMyCustomAction<InitAction>(action, "init")) {
269268
if (getReduceContext().disableUpdateState) return this;

client/packages/lowcoder/src/comps/comps/tableComp/expansionControl.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ let ExpansionControlTmp = (function () {
5050
slot: ContextSlotControl,
5151
},
5252
() => ({ expandableConfig: {}, expandModalView: null })
53-
)
53+
)
5454
.setControlItemData({ filterText: label })
5555
.setPropertyViewFn((children, dispatch) => {
5656
return (

client/packages/lowcoder/src/comps/controls/slotControl.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { BackgroundColorContext } from "comps/utils/backgroundColorContext";
1010
import { CanvasContainerID } from "constants/domLocators";
1111
import { Layers } from "constants/Layers";
1212
import { trans } from "i18n";
13-
import { changeChildAction, ConstructorToView } from "lowcoder-core";
13+
import { changeChildAction, CompActionTypes, ConstructorToView } from "lowcoder-core";
1414
import { HintPlaceHolder, TacoButton } from "lowcoder-design";
1515
import { createContext, useContext } from "react";
1616
import styled from "styled-components";

client/packages/lowcoder/src/comps/generators/withMultiContext.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export function withMultiContext<TCtor extends MultiCompConstructor>(VariantComp
8787
override parseChildrenFromValue(params: CompParams): ChildrenType {
8888
const dispatch = params.dispatch ?? _.noop;
8989
const newParams = { ...params, dispatch: wrapDispatch(dispatch, COMP_KEY) };
90-
90+
9191
const comp: WithParamComp = new WithParamCompCtor(newParams) as unknown as WithParamComp;
9292
const mapComp = new MapCtor({ dispatch: wrapDispatch(dispatch, MAP_KEY) });
9393
return { [COMP_KEY]: comp, [MAP_KEY]: mapComp };

client/packages/lowcoder/src/comps/generators/withSelectedMultiContext.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import _ from "lodash";
22
import {
33
CompAction,
44
customAction,
5+
isCustomAction,
56
isMyCustomAction,
67
MultiCompConstructor,
78
wrapChildAction,
@@ -11,6 +12,8 @@ import { ReactNode } from "react";
1112
import { lastValueIfEqual, setFieldsNoTypeCheck } from "util/objectUtils";
1213
import { COMP_KEY, MAP_KEY, withMultiContext } from "./withMultiContext";
1314
import { paramsEqual } from "./withParams";
15+
import { LazyCompReadyAction } from "../comps/lazyLoadComp/lazyLoadComp";
16+
import { ModuleReadyAction } from "../comps/moduleComp/moduleComp";
1417

1518
const SELECTED_KEY = "SELECTED";
1619

@@ -50,7 +53,7 @@ export function withSelectedMultiContext<TCtor extends MultiCompConstructor>(
5053
}
5154

5255
override reduce(action: CompAction): this {
53-
// console.info("enter withSelectedMultiContext reduce. action: ", action, "\nthis: ", this);
56+
console.info("enter withSelectedMultiContext reduce. action: ", action, "\nthis: ", this);
5457
let comp = this;
5558
if (isMyCustomAction<SetSelectionAction>(action, "setSelection")) {
5659
const { selection, params } = action.value;
@@ -69,12 +72,20 @@ export function withSelectedMultiContext<TCtor extends MultiCompConstructor>(
6972
comp.getOriginalComp().setParams(comp.cacheParamsMap.get(selection)!)
7073
);
7174
}
72-
} else if (!action.editDSL || action.path[0] !== MAP_KEY || _.isNil(action.path[1])) {
75+
} else if ((
76+
!action.editDSL
77+
&& !isCustomAction<LazyCompReadyAction>(action, "LazyCompReady")
78+
&& !isCustomAction<ModuleReadyAction>(action, "moduleReady")
79+
) || action.path[0] !== MAP_KEY || _.isNil(action.path[1])) {
7380
if (action.path[0] === MAP_KEY && action.path[1] === SELECTED_KEY) {
7481
action.path[1] = this.selection;
7582
}
7683
comp = super.reduce(action);
77-
} else if (action.editDSL && action.path[1] === SELECTED_KEY) {
84+
} else if ((
85+
action.editDSL
86+
|| isCustomAction<LazyCompReadyAction>(action, "LazyCompReady")
87+
|| isCustomAction<ModuleReadyAction>(action, "moduleReady")
88+
) && action.path[1] === SELECTED_KEY) {
7889
// broadcast
7990
const newAction = {
8091
...action,

0 commit comments

Comments
 (0)