Skip to content

Commit 84c165b

Browse files
mapped nest_component and set_properties action
1 parent d6cea0c commit 84c165b

File tree

3 files changed

+95
-12
lines changed

3 files changed

+95
-12
lines changed

client/packages/lowcoder/src/comps/comps/chatComp/components/ChatMain.tsx

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import styled from "styled-components";
1919
import { ChatCompProps } from "../chatCompTypes";
2020
import { message } from "antd";
2121
import { EditorContext } from "@lowcoder-ee/comps/editorState";
22-
import { addComponentAction } from "../../preLoadComp/actions/componentManagement";
22+
import { addComponentAction, nestComponentAction } from "../../preLoadComp/actions/componentManagement";
23+
import { configureComponentAction } from "../../preLoadComp/actions/componentConfiguration";
2324

2425
const ChatContainer = styled.div<{ $autoHeight?: boolean }>`
2526
display: flex;
@@ -92,7 +93,7 @@ export function ChatMain(props: ChatCompProps) {
9293

9394
// Keep the ref updated with the latest editorState
9495
useEffect(() => {
95-
console.log("EDITOR STATE CHANGE ---> ", editorState);
96+
// console.log("EDITOR STATE CHANGE ---> ", editorState);
9697
editorStateRef.current = editorState;
9798
}, [editorState]);
9899

@@ -129,6 +130,30 @@ export function ChatMain(props: ChatCompProps) {
129130
actionPayload: action_payload,
130131
selectedComponent: action_parameters,
131132
selectedEditorComponent: null,
133+
selectedNestComponent: null,
134+
editorState: editorStateRef.current
135+
});
136+
break;
137+
case "nest_component":
138+
await nestComponentAction.execute({
139+
actionKey: action_name,
140+
actionValue: "",
141+
actionPayload: action_payload,
142+
selectedComponent: action_parameters,
143+
selectedEditorComponent: null,
144+
selectedNestComponent: null,
145+
editorState: editorStateRef.current
146+
});
147+
break;
148+
case "set_properties":
149+
debugger;
150+
await configureComponentAction.execute({
151+
actionKey: action_name,
152+
actionValue: action_parameters,
153+
actionPayload: action_payload,
154+
selectedEditorComponent: null,
155+
selectedComponent: null,
156+
selectedNestComponent: null,
132157
editorState: editorStateRef.current
133158
});
134159
break;

client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentConfiguration.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { message } from "antd";
22
import { ActionConfig, ActionExecuteParams } from "../types";
3+
import { getEditorComponentInfo } from "../utils";
34

45
export const configureComponentAction: ActionConfig = {
56
key: 'configure-components',
@@ -19,10 +20,40 @@ export const configureComponentAction: ActionConfig = {
1920
}
2021
},
2122
execute: async (params: ActionExecuteParams) => {
22-
const { selectedEditorComponent, actionValue } = params;
23+
const { selectedEditorComponent, actionValue: name, actionValue, actionPayload, editorState } = params;
24+
const otherProps = actionPayload;
25+
// const { name, ...otherProps } = actionPayload;
2326

2427
try {
25-
const config = JSON.parse(actionValue);
28+
const componentInfo = getEditorComponentInfo(editorState, name);
29+
30+
if (!componentInfo) {
31+
message.error(`Component "${selectedEditorComponent}" not found`);
32+
return;
33+
}
34+
35+
const { componentKey: parentKey, items } = componentInfo;
36+
37+
if (!parentKey) {
38+
message.error(`Parent component "${selectedEditorComponent}" not found in layout`);
39+
return;
40+
}
41+
42+
const parentItem = items[parentKey];
43+
if (!parentItem) {
44+
message.error(`Parent component "${selectedEditorComponent}" not found in items`);
45+
return;
46+
}
47+
48+
const itemComp = parentItem.children.comp;
49+
const itemData = itemComp.toJsonValue();
50+
const config = {
51+
...itemData,
52+
...otherProps
53+
};
54+
itemComp.dispatchChangeValueAction(config);
55+
56+
debugger;
2657
console.log('Configuring component:', selectedEditorComponent, 'with config:', config);
2758
message.info(`Configure action for component "${selectedEditorComponent}"`);
2859

client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentManagement.ts

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,17 @@ export const nestComponentAction: ActionConfig = {
137137
requiresInput: false,
138138
isNested: true,
139139
execute: async (params: ActionExecuteParams) => {
140-
const { selectedEditorComponent, selectedNestComponent, editorState } = params;
141-
140+
// const { selectedEditorComponent, selectedNestComponent, editorState, actionPayload } = params;
141+
const { editorState, actionPayload, selectedComponent: selectedNestComponent } = params;
142+
const { name, layout, target: selectedEditorComponent, ...otherProps } = actionPayload;
143+
142144
if (!selectedEditorComponent || !selectedNestComponent || !editorState) {
143145
message.error('Parent component, child component, and editor state are required');
144146
return;
145147
}
146148

147-
const parentComponentInfo = getEditorComponentInfo(editorState, selectedEditorComponent);
149+
const [editorComponent, ...childComponents] = selectedEditorComponent.split('.');
150+
const parentComponentInfo = getEditorComponentInfo(editorState, editorComponent);
148151

149152
if (!parentComponentInfo) {
150153
message.error(`Parent component "${selectedEditorComponent}" not found`);
@@ -174,10 +177,15 @@ export const nestComponentAction: ActionConfig = {
174177
}
175178

176179
try {
177-
180+
let compName = name;
178181
const nameGenerator = editorState.getNameGenerator();
179182
const compInfo = parseCompType(selectedNestComponent);
180-
const compName = nameGenerator.genItemName(compInfo.compName);
183+
if (!compName) {
184+
compName = nameGenerator.genItemName(compInfo.compName);
185+
}
186+
// const nameGenerator = editorState.getNameGenerator();
187+
// const compInfo = parseCompType(selectedNestComponent);
188+
// const compName = nameGenerator.genItemName(compInfo.compName);
181189
const key = genRandomKey();
182190

183191
const manifest = uiCompRegistry[selectedNestComponent];
@@ -193,15 +201,33 @@ export const nestComponentAction: ActionConfig = {
193201
defaultDataFn = manifest?.defaultDataFn;
194202
}
195203

204+
let compDefaultValue = defaultDataFn ? defaultDataFn(compName, nameGenerator, editorState) : undefined;
205+
const compInitialValue = {
206+
...(compDefaultValue as any || {}),
207+
...otherProps,
208+
}
209+
196210
const widgetValue: GridItemDataType = {
197211
compType: selectedNestComponent,
198212
name: compName,
199-
comp: defaultDataFn ? defaultDataFn(compName, nameGenerator, editorState) : undefined,
213+
comp: compInitialValue,
200214
};
201215

202216
const parentContainer = parentItem.children.comp;
203-
204-
const realContainer = parentContainer.realSimpleContainer();
217+
let originalContainer = parentContainer;
218+
for (const childComponent of childComponents) {
219+
originalContainer = originalContainer.children[childComponent];
220+
}
221+
if (originalContainer?.children?.[0]?.children?.view) {
222+
originalContainer = originalContainer?.children?.[0]?.children?.view;
223+
}
224+
225+
if (!originalContainer) {
226+
message.error(`Container "${selectedEditorComponent}" cannot accept nested components`);
227+
return;
228+
}
229+
230+
const realContainer = originalContainer.realSimpleContainer();
205231
if (!realContainer) {
206232
message.error(`Container "${selectedEditorComponent}" cannot accept nested components`);
207233
return;
@@ -223,6 +249,7 @@ export const nestComponentAction: ActionConfig = {
223249
h: layoutInfo.h || 5,
224250
pos: itemPos,
225251
isDragging: false,
252+
...(layout || {}),
226253
};
227254

228255
realContainer.dispatch(

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy