Skip to content

Commit 0ee8c56

Browse files
committed
Merge branch 'feat/chat-component' of github.com:iamfaran/lowcoder into feat/chat-component
2 parents 3fc3517 + cd079e6 commit 0ee8c56

File tree

5 files changed

+158
-61
lines changed

5 files changed

+158
-61
lines changed
Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
1-
// client/packages/lowcoder/src/comps/comps/chatComp/chatCompTypes.ts
2-
3-
// ============================================================================
4-
// CLEAN CHATCOMP TYPES - SIMPLIFIED AND FOCUSED
5-
// ============================================================================
6-
7-
export type ChatCompProps = {
8-
// Storage
9-
tableName: string;
10-
11-
// Message Handler
12-
handlerType: "query" | "n8n";
13-
chatQuery: string; // Only used when handlerType === "query"
14-
modelHost: string; // Only used when handlerType === "n8n"
15-
systemPrompt: string;
16-
streaming: boolean;
17-
18-
// UI
19-
placeholder: string;
20-
21-
// Exposed Variables
22-
currentMessage: string; // Read-only exposed variable
23-
};
24-
25-
// Legacy export for backwards compatibility (if needed)
26-
export type ChatCompLegacyProps = ChatCompProps;
1+
2+
// ============================================================================
3+
// CLEAN CHATCOMP TYPES - SIMPLIFIED AND FOCUSED
4+
// ============================================================================
5+
6+
export type ChatCompProps = {
7+
// Storage
8+
tableName: string;
9+
10+
// Message Handler
11+
handlerType: "query" | "n8n";
12+
chatQuery: string; // Only used when handlerType === "query"
13+
modelHost: string; // Only used when handlerType === "n8n"
14+
systemPrompt: string;
15+
streaming: boolean;
16+
17+
// UI
18+
placeholder: string;
19+
20+
// Exposed Variables
21+
currentMessage: string; // Read-only exposed variable
22+
};
23+
24+
// Legacy export for backwards compatibility (if needed)
25+
export type ChatCompLegacyProps = ChatCompProps;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,4 +267,5 @@ export function ChatCoreMain({
267267
</ChatContainer>
268268
</AssistantRuntimeProvider>
269269
);
270-
}
270+
}
271+

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: 97 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import {
1313
deleteCompAction
1414
} from "lowcoder-core";
1515
import { getEditorComponentInfo } from "../utils";
16+
import { getPromiseAfterDispatch } from "@lowcoder-ee/util/promiseUtils";
17+
import { hookCompCategory, HookCompType } from "@lowcoder-ee/comps/hooks/hookCompTypes";
1618

1719
export const addComponentAction: ActionConfig = {
1820
key: 'add-components',
@@ -21,14 +23,30 @@ export const addComponentAction: ActionConfig = {
2123
requiresComponentSelection: true,
2224
requiresInput: false,
2325
execute: async (params: ActionExecuteParams) => {
24-
const { selectedComponent, editorState } = params;
25-
26+
const { selectedComponent, editorState, actionPayload } = params;
27+
const { component_name: name, layout, action_parameters } = actionPayload;
28+
2629
if (!selectedComponent || !editorState) {
2730
message.error('Component and editor state are required');
2831
return;
2932
}
3033

3134
try {
35+
if (hookCompCategory(selectedComponent) === "ui") {
36+
const compName = Boolean(name) ? name : editorState.getNameGenerator().genItemName(selectedComponent);
37+
editorState
38+
.getHooksComp()
39+
.dispatch(
40+
wrapActionExtraInfo(
41+
editorState
42+
.getHooksComp()
43+
.pushAction({ name: compName, compType: selectedComponent as HookCompType }),
44+
{ compInfos: [{ compName: compName, compType: selectedComponent, type: "add" }] }
45+
)
46+
);
47+
return;
48+
}
49+
3250
const uiComp = editorState.getUIComp();
3351
const container = uiComp.getComp();
3452

@@ -43,31 +61,33 @@ export const addComponentAction: ActionConfig = {
4361
return;
4462
}
4563

64+
let compName = name;
4665
const nameGenerator = editorState.getNameGenerator();
4766
const compInfo = parseCompType(selectedComponent);
48-
const compName = nameGenerator.genItemName(compInfo.compName);
67+
if (!compName) {
68+
compName = nameGenerator.genItemName(compInfo.compName);
69+
}
4970
const key = genRandomKey();
5071

5172
const manifest = uiCompRegistry[selectedComponent];
5273
let defaultDataFn = undefined;
5374

54-
if (manifest?.lazyLoad) {
55-
const { defaultDataFnName, defaultDataFnPath } = manifest;
56-
if (defaultDataFnName && defaultDataFnPath) {
57-
const module = await import(`../../../${defaultDataFnPath}.tsx`);
58-
defaultDataFn = module[defaultDataFnName];
59-
}
60-
} else if (!compInfo.isRemote) {
75+
if (!compInfo.isRemote) {
6176
defaultDataFn = manifest?.defaultDataFn;
6277
}
6378

79+
let compDefaultValue = defaultDataFn ? defaultDataFn(compName, nameGenerator, editorState) : undefined;
80+
const compInitialValue = {
81+
...(compDefaultValue as any || {}),
82+
...action_parameters,
83+
}
6484
const widgetValue: GridItemDataType = {
6585
compType: selectedComponent,
6686
name: compName,
67-
comp: defaultDataFn ? defaultDataFn(compName, nameGenerator, editorState) : undefined,
87+
comp: compInitialValue,
6888
};
6989

70-
const currentLayout = simpleContainer.children.layout.getView();
90+
const currentLayout = uiComp.children.comp.children.layout.getView();
7191
const layoutInfo = manifest?.layoutInfo || defaultLayout(selectedComponent as UICompType);
7292

7393
let itemPos = 0;
@@ -83,9 +103,11 @@ export const addComponentAction: ActionConfig = {
83103
h: layoutInfo.h || 5,
84104
pos: itemPos,
85105
isDragging: false,
106+
...(layout || {}),
86107
};
87108

88-
simpleContainer.dispatch(
109+
await getPromiseAfterDispatch(
110+
uiComp.children.comp.dispatch,
89111
wrapActionExtraInfo(
90112
multiChangeAction({
91113
layout: changeValueAction({
@@ -95,8 +117,23 @@ export const addComponentAction: ActionConfig = {
95117
items: addMapChildAction(key, widgetValue),
96118
}),
97119
{ compInfos: [{ compName: compName, compType: selectedComponent, type: "add" }] }
98-
)
120+
),
121+
{
122+
autoHandleAfterReduce: true,
123+
}
99124
);
125+
// simpleContainer.dispatch(
126+
// wrapActionExtraInfo(
127+
// multiChangeAction({
128+
// layout: changeValueAction({
129+
// ...currentLayout,
130+
// [key]: layoutItem,
131+
// }, true),
132+
// items: addMapChildAction(key, widgetValue),
133+
// }),
134+
// { compInfos: [{ compName: compName, compType: selectedComponent, type: "add" }] }
135+
// )
136+
// );
100137

101138
editorState.setSelectedCompNames(new Set([compName]), "addComp");
102139

@@ -116,28 +153,32 @@ export const nestComponentAction: ActionConfig = {
116153
requiresInput: false,
117154
isNested: true,
118155
execute: async (params: ActionExecuteParams) => {
119-
const { selectedEditorComponent, selectedNestComponent, editorState } = params;
120-
156+
// const { selectedEditorComponent, selectedNestComponent, editorState, actionPayload } = params;
157+
const { editorState, actionPayload, selectedComponent: selectedNestComponent } = params;
158+
const { component_name: name, layout, parent_component_name: selectedEditorComponent, action_parameters } = actionPayload;
159+
// const { name, layout, target: selectedEditorComponent, ...otherProps } = actionPayload;
160+
121161
if (!selectedEditorComponent || !selectedNestComponent || !editorState) {
122162
message.error('Parent component, child component, and editor state are required');
123163
return;
124164
}
125165

126-
const parentComponentInfo = getEditorComponentInfo(editorState, selectedEditorComponent);
166+
const [editorComponent, ...childComponents] = selectedEditorComponent.split('.');
167+
const parentItem = editorState.getUICompByName(editorComponent); //getEditorComponentInfo(editorState, editorComponent);
127168

128-
if (!parentComponentInfo) {
129-
message.error(`Parent component "${selectedEditorComponent}" not found`);
130-
return;
131-
}
169+
// if (!parentComponentInfo) {
170+
// message.error(`Parent component "${selectedEditorComponent}" not found`);
171+
// return;
172+
// }
132173

133-
const { componentKey: parentKey, items } = parentComponentInfo;
174+
// const { componentKey: parentKey, items } = parentComponentInfo;
134175

135-
if (!parentKey) {
136-
message.error(`Parent component "${selectedEditorComponent}" not found in layout`);
137-
return;
138-
}
176+
// if (!parentKey) {
177+
// message.error(`Parent component "${selectedEditorComponent}" not found in layout`);
178+
// return;
179+
// }
139180

140-
const parentItem = items[parentKey];
181+
// const parentItem = items[parentKey];
141182
if (!parentItem) {
142183
message.error(`Parent component "${selectedEditorComponent}" not found in items`);
143184
return;
@@ -153,10 +194,15 @@ export const nestComponentAction: ActionConfig = {
153194
}
154195

155196
try {
156-
197+
let compName = name;
157198
const nameGenerator = editorState.getNameGenerator();
158199
const compInfo = parseCompType(selectedNestComponent);
159-
const compName = nameGenerator.genItemName(compInfo.compName);
200+
if (!compName) {
201+
compName = nameGenerator.genItemName(compInfo.compName);
202+
}
203+
// const nameGenerator = editorState.getNameGenerator();
204+
// const compInfo = parseCompType(selectedNestComponent);
205+
// const compName = nameGenerator.genItemName(compInfo.compName);
160206
const key = genRandomKey();
161207

162208
const manifest = uiCompRegistry[selectedNestComponent];
@@ -172,15 +218,33 @@ export const nestComponentAction: ActionConfig = {
172218
defaultDataFn = manifest?.defaultDataFn;
173219
}
174220

221+
let compDefaultValue = defaultDataFn ? defaultDataFn(compName, nameGenerator, editorState) : undefined;
222+
const compInitialValue = {
223+
...(compDefaultValue as any || {}),
224+
...action_parameters,
225+
}
226+
175227
const widgetValue: GridItemDataType = {
176228
compType: selectedNestComponent,
177229
name: compName,
178-
comp: defaultDataFn ? defaultDataFn(compName, nameGenerator, editorState) : undefined,
230+
comp: compInitialValue,
179231
};
180232

181233
const parentContainer = parentItem.children.comp;
182-
183-
const realContainer = parentContainer.realSimpleContainer();
234+
let originalContainer = parentContainer;
235+
for (const childComponent of childComponents) {
236+
originalContainer = originalContainer.children[childComponent];
237+
}
238+
if (originalContainer?.children?.[0]?.children?.view) {
239+
originalContainer = originalContainer?.children?.[0]?.children?.view;
240+
}
241+
242+
if (!originalContainer) {
243+
message.error(`Container "${selectedEditorComponent}" cannot accept nested components`);
244+
return;
245+
}
246+
247+
const realContainer = originalContainer.realSimpleContainer();
184248
if (!realContainer) {
185249
message.error(`Container "${selectedEditorComponent}" cannot accept nested components`);
186250
return;
@@ -202,6 +266,7 @@ export const nestComponentAction: ActionConfig = {
202266
h: layoutInfo.h || 5,
203267
pos: itemPos,
204268
isDragging: false,
269+
...(layout || {}),
205270
};
206271

207272
realContainer.dispatch(

client/packages/lowcoder/src/comps/comps/preLoadComp/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export interface ActionConfig {
4444
export interface ActionExecuteParams {
4545
actionKey: string;
4646
actionValue: string;
47+
actionPayload?: any;
4748
selectedComponent: string | null;
4849
selectedEditorComponent: string | null;
4950
selectedNestComponent: string | null;

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