Skip to content

Commit 0c4e885

Browse files
committed
fix image attachments preview and remove attachments from the bottom panel
1 parent 7fd74ca commit 0c4e885

6 files changed

Lines changed: 40 additions & 48 deletions

File tree

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ export const chatChildrenMap = {
182182
};
183183

184184
// ============================================================================
185-
// CLEAN CHATCOMP - USES NEW ARCHITECTURE
185+
// CHATCOMP
186186
// ============================================================================
187187

188188
const ChatTmpComp = new UICompBuilder(
@@ -222,7 +222,7 @@ const ChatTmpComp = new UICompBuilder(
222222
]);
223223

224224
// Handle message updates for exposed variable
225-
// Using Lowcoder pattern: props.currentMessage.onChange() instead of dispatch(changeChildAction(...))
225+
// Using Lowcoder pattern: props.currentMessage.onChange()
226226
const handleMessageUpdate = (message: string) => {
227227
props.currentMessage.onChange(message);
228228
// Trigger messageSent event
@@ -259,7 +259,7 @@ const ChatTmpComp = new UICompBuilder(
259259
};
260260
}, []);
261261

262-
// Group all styles into single object for cleaner prop passing
262+
// custom styles
263263
const styles = {
264264
style: props.style,
265265
sidebarStyle: props.sidebarStyle,
@@ -300,7 +300,7 @@ const ChatCompWithAutoHeight = class extends ChatTmpComp {
300300
};
301301

302302
// ============================================================================
303-
// EXPORT WITH EXPOSED VARIABLES
303+
// EXPOSED VARIABLES
304304
// ============================================================================
305305

306306
export const ChatComp = withExposingConfigs(ChatCompWithAutoHeight, [

client/packages/lowcoder/src/comps/comps/chatComp/chatCompTypes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// client/packages/lowcoder/src/comps/comps/chatComp/chatCompTypes.ts
22

33
// ============================================================================
4-
// CLEAN CHATCOMP TYPES - SIMPLIFIED AND FOCUSED
4+
// CHATCOMP TYPES
55
// ============================================================================
66

77
export type ChatCompProps = {

client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { hiddenPropertyView } from "comps/utils/propertyUtils";
77
import { controlItem } from "lowcoder-design";
88

99
// ============================================================================
10-
// CLEAN PROPERTY VIEW - FOCUSED ON ESSENTIAL CONFIGURATION
10+
// PROPERTY VIEW
1111
// ============================================================================
1212

1313
export const ChatPropertyView = React.memo((props: any) => {

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { universalAttachmentAdapter } from "../utils/attachmentAdapter";
2424
import { StyledChatContainer } from "./ChatContainerStyles";
2525

2626
// ============================================================================
27-
// CHAT CONTAINER - USES CONTEXT FROM CHATPROVIDER
27+
// CHAT CONTAINER
2828
// ============================================================================
2929

3030
const generateId = () => Math.random().toString(36).substr(2, 9);
@@ -33,8 +33,7 @@ function ChatContainerView(props: ChatCoreProps) {
3333
const { state, actions } = useChatContext();
3434
const [isRunning, setIsRunning] = useState(false);
3535

36-
// Store callback props in refs so useEffects don't re-fire
37-
// when Lowcoder's builder creates new function references on each render
36+
// callback props in refs so useEffects don't re-fire
3837
const onConversationUpdateRef = useRef(props.onConversationUpdate);
3938
onConversationUpdateRef.current = props.onConversationUpdate;
4039

@@ -247,7 +246,7 @@ function ChatContainerView(props: ChatCoreProps) {
247246
}
248247

249248
// ============================================================================
250-
// EXPORT - SIMPLIFIED (PROVIDERS MOVED UP ONE LEVEL)
249+
// EXPORT
251250
// ============================================================================
252251

253252
export const ChatContainer = ChatContainerView;

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

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
AppendMessage,
88
AssistantRuntimeProvider,
99
ExternalStoreThreadListAdapter,
10-
CompleteAttachment,
1110
TextContentPart,
1211
ThreadUserContentPart
1312
} from "@assistant-ui/react";
@@ -22,7 +21,6 @@ import {
2221
import { MessageHandler, ChatMessage } from "../types/chatTypes";
2322
import styled from "styled-components";
2423
import { trans } from "i18n";
25-
import { universalAttachmentAdapter } from "../utils/attachmentAdapter";
2624
import { TooltipProvider } from "@radix-ui/react-tooltip";
2725

2826
import "@assistant-ui/styles/index.css";
@@ -89,20 +87,11 @@ function ChatPanelView({ messageHandler, placeholder, onMessageUpdate }: Omit<Ch
8987
const convertMessage = (message: ChatMessage): ThreadMessageLike => {
9088
const content: ThreadUserContentPart[] = [{ type: "text", text: message.text }];
9189

92-
if (message.attachments && message.attachments.length > 0) {
93-
for (const attachment of message.attachments) {
94-
if (attachment.content) {
95-
content.push(...attachment.content);
96-
}
97-
}
98-
}
99-
10090
return {
10191
role: message.role,
10292
content,
10393
id: message.id,
10494
createdAt: new Date(message.timestamp),
105-
...(message.attachments && message.attachments.length > 0 && { attachments: message.attachments }),
10695
};
10796
};
10897

@@ -112,11 +101,8 @@ function ChatPanelView({ messageHandler, placeholder, onMessageUpdate }: Omit<Ch
112101
);
113102

114103
const text = textPart?.text?.trim() ?? "";
115-
const completeAttachments = (message.attachments ?? []).filter(
116-
(att): att is CompleteAttachment => att.status.type === "complete"
117-
);
118104

119-
if (!text && !completeAttachments.length) {
105+
if (!text) {
120106
throw new Error("Cannot send an empty message");
121107
}
122108

@@ -125,7 +111,6 @@ function ChatPanelView({ messageHandler, placeholder, onMessageUpdate }: Omit<Ch
125111
role: "user",
126112
text,
127113
timestamp: Date.now(),
128-
attachments: completeAttachments,
129114
};
130115

131116
await actions.addMessage(state.currentThreadId, userMessage);
@@ -159,11 +144,8 @@ function ChatPanelView({ messageHandler, placeholder, onMessageUpdate }: Omit<Ch
159144
);
160145

161146
const text = textPart?.text?.trim() ?? "";
162-
const completeAttachments = (message.attachments ?? []).filter(
163-
(att): att is CompleteAttachment => att.status.type === "complete"
164-
);
165147

166-
if (!text && !completeAttachments.length) {
148+
if (!text) {
167149
throw new Error("Cannot send an empty message");
168150
}
169151

@@ -175,7 +157,6 @@ function ChatPanelView({ messageHandler, placeholder, onMessageUpdate }: Omit<Ch
175157
role: "user",
176158
text,
177159
timestamp: Date.now(),
178-
attachments: completeAttachments,
179160
});
180161

181162
await actions.updateMessages(state.currentThreadId, newMessages);
@@ -241,7 +222,7 @@ function ChatPanelView({ messageHandler, placeholder, onMessageUpdate }: Omit<Ch
241222
onEdit,
242223
adapters: {
243224
threadList: threadListAdapter,
244-
attachments: universalAttachmentAdapter,
225+
// No attachments support for bottom panel chat
245226
},
246227
});
247228

@@ -253,7 +234,7 @@ function ChatPanelView({ messageHandler, placeholder, onMessageUpdate }: Omit<Ch
253234
<AssistantRuntimeProvider runtime={runtime}>
254235
<StyledChatContainer>
255236
<ThreadList />
256-
<Thread placeholder={placeholder} />
237+
<Thread placeholder={placeholder} showAttachments={false} />
257238
</StyledChatContainer>
258239
</AssistantRuntimeProvider>
259240
);

client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread.tsx

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
MessagePrimitive,
66
ThreadPrimitive,
77
} from "@assistant-ui/react";
8-
import type { FC } from "react";
8+
import { useMemo, type FC } from "react";
99
import { trans } from "i18n";
1010
import {
1111
ArrowDownIcon,
@@ -14,7 +14,6 @@ import {
1414
ChevronRightIcon,
1515
CopyIcon,
1616
PencilIcon,
17-
RefreshCwIcon,
1817
SendHorizontalIcon,
1918
} from "lucide-react";
2019
import { cn } from "../../utils/cn";
@@ -54,9 +53,20 @@ import { ComposerAddAttachment, ComposerAttachments, UserMessageAttachments } fr
5453

5554
interface ThreadProps {
5655
placeholder?: string;
56+
showAttachments?: boolean;
5757
}
5858

59-
export const Thread: FC<ThreadProps> = ({ placeholder = trans("chat.composerPlaceholder") }) => {
59+
export const Thread: FC<ThreadProps> = ({
60+
placeholder = trans("chat.composerPlaceholder"),
61+
showAttachments = true
62+
}) => {
63+
// Stable component reference so React doesn't unmount/remount on every render
64+
const UserMessageComponent = useMemo<FC>(() => {
65+
const Wrapper: FC = () => <UserMessage showAttachments={showAttachments} />;
66+
Wrapper.displayName = "UserMessage";
67+
return Wrapper;
68+
}, [showAttachments]);
69+
6070
return (
6171
<StyledThreadRoot
6272
className="aui-root aui-thread-root"
@@ -69,7 +79,7 @@ import { ComposerAddAttachment, ComposerAttachments, UserMessageAttachments } fr
6979

7080
<ThreadPrimitive.Messages
7181
components={{
72-
UserMessage: UserMessage,
82+
UserMessage: UserMessageComponent,
7383
EditComposer: EditComposer,
7484
AssistantMessage: AssistantMessage,
7585
}}
@@ -85,7 +95,7 @@ import { ComposerAddAttachment, ComposerAttachments, UserMessageAttachments } fr
8595

8696
<div className="aui-thread-viewport-footer">
8797
<ThreadScrollToBottom />
88-
<Composer placeholder={placeholder} />
98+
<Composer placeholder={placeholder} showAttachments={showAttachments} />
8999
</div>
90100
</ThreadPrimitive.Viewport>
91101
</StyledThreadRoot>
@@ -148,11 +158,18 @@ import { ComposerAddAttachment, ComposerAttachments, UserMessageAttachments } fr
148158
);
149159
};
150160

151-
const Composer: FC<{ placeholder?: string }> = ({ placeholder = trans("chat.composerPlaceholder") }) => {
161+
const Composer: FC<{ placeholder?: string; showAttachments?: boolean }> = ({
162+
placeholder = trans("chat.composerPlaceholder"),
163+
showAttachments = true
164+
}) => {
152165
return (
153166
<ComposerPrimitive.Root className="aui-composer-root">
154-
<ComposerAttachments />
155-
<ComposerAddAttachment />
167+
{showAttachments && (
168+
<>
169+
<ComposerAttachments />
170+
<ComposerAddAttachment />
171+
</>
172+
)}
156173
<ComposerPrimitive.Input
157174
rows={1}
158175
autoFocus
@@ -193,11 +210,11 @@ import { ComposerAddAttachment, ComposerAttachments, UserMessageAttachments } fr
193210
);
194211
};
195212

196-
const UserMessage: FC = () => {
213+
const UserMessage: FC<{ showAttachments?: boolean }> = ({ showAttachments = true }) => {
197214
return (
198215
<MessagePrimitive.Root className="aui-user-message-root">
199216
<UserActionBar />
200-
<UserMessageAttachments />
217+
{showAttachments && <UserMessageAttachments />}
201218

202219
<div className="aui-user-message-content">
203220
<MessagePrimitive.Content />
@@ -273,11 +290,6 @@ import { ComposerAddAttachment, ComposerAttachments, UserMessageAttachments } fr
273290
</MessagePrimitive.If>
274291
</TooltipIconButton>
275292
</ActionBarPrimitive.Copy>
276-
<ActionBarPrimitive.Reload asChild>
277-
<TooltipIconButton tooltip="Refresh">
278-
<RefreshCwIcon />
279-
</TooltipIconButton>
280-
</ActionBarPrimitive.Reload>
281293
</ActionBarPrimitive.Root>
282294
);
283295
};

0 commit comments

Comments
 (0)