Skip to content

Commit 67ca218

Browse files
added setChildrensAction in list
1 parent 04a5968 commit 67ca218

File tree

1 file changed

+29
-1
lines changed
  • client/packages/lowcoder/src/comps/generators

1 file changed

+29
-1
lines changed

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ export type CustomListAction<CompCtor extends CompConstructor = CompConstructor>
2626
>;
2727

2828
type ListAction<CompCtor extends CompConstructor = CompConstructor> =
29+
| {
30+
type: "setChildrens";
31+
value: Array<ConstructorToDataType<CompCtor>>;
32+
}
2933
| {
3034
type: "push";
3135
value: ConstructorToDataType<CompCtor>;
@@ -145,7 +149,19 @@ export function list<ChildCompCtor extends CompConstructor<any, any>>(
145149

146150
private reduceCustom(action: ListAction<ChildCompCtor>): this {
147151
switch (action.type) {
148-
case "push":
152+
case "setChildrens": {
153+
const childrenMap: Record<number, ConstructorToComp<ChildCompCtor>> = {};
154+
const childrenOrder: number[] = [];
155+
action.value.forEach((children: any, key: number) => {
156+
childrenMap[key] = newChild(this.dispatch, String(key), children);
157+
childrenOrder.push(key);
158+
})
159+
return setFieldsNoTypeCheck(this, {
160+
children: childrenMap,
161+
childrenOrder: childrenOrder,
162+
});
163+
}
164+
case "push": {
149165
const key = this.genKey();
150166
const newChildren = {
151167
...this.children,
@@ -155,6 +171,7 @@ export function list<ChildCompCtor extends CompConstructor<any, any>>(
155171
children: newChildren,
156172
childrenOrder: [...this.childrenOrder, key],
157173
});
174+
}
158175
case "pushComp": {
159176
const key = this.genKey();
160177
const newChildren = {
@@ -209,6 +226,17 @@ export function list<ChildCompCtor extends CompConstructor<any, any>>(
209226
}
210227
}
211228
}
229+
230+
setChildrensAction(value: Array<ConstructorToDataType<ChildCompCtor>>) {
231+
return customAction<ListAction<ChildCompCtor>>(
232+
{
233+
type: "setChildrens",
234+
value: value,
235+
},
236+
true
237+
);
238+
}
239+
212240
pushAction(value: ConstructorToDataType<ChildCompCtor>) {
213241
return customAction<ListAction<ChildCompCtor>>(
214242
{

0 commit comments

Comments
 (0)