Skip to content

Commit c970bc2

Browse files
committed
fix button forward ref + ChatProvider level
1 parent e3fe298 commit c970bc2

4 files changed

Lines changed: 30 additions & 36 deletions

File tree

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

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ import QuerySelectControl from "comps/controls/querySelectControl";
1212
import { eventHandlerControl, EventConfigType } from "comps/controls/eventHandlerControl";
1313
import { AutoHeightControl } from "comps/controls/autoHeightControl";
1414
import { ChatContainer } from "./components/ChatContainer";
15+
import { ChatProvider } from "./components/context/ChatContext";
1516
import { ChatPropertyView } from "./chatPropertyView";
1617
import { createChatStorage } from "./utils/storageFactory";
1718
import { QueryHandler, createMessageHandler } from "./handlers/messageHandlers";
1819
import { useMemo, useRef, useEffect } from "react";
1920
import { changeChildAction } from "lowcoder-core";
2021
import { ChatMessage } from "./types/chatTypes";
2122
import { trans } from "i18n";
23+
import { TooltipProvider } from "@radix-ui/react-tooltip";
2224
import { styleControl } from "comps/controls/styleControl";
2325
import {
2426
ChatStyle,
@@ -302,17 +304,20 @@ const ChatTmpComp = new UICompBuilder(
302304
};
303305

304306
return (
305-
<ChatContainer
306-
storage={storage}
307-
messageHandler={messageHandler}
308-
placeholder={props.placeholder}
309-
autoHeight={props.autoHeight}
310-
sidebarWidth={props.leftPanelWidth}
311-
onMessageUpdate={handleMessageUpdate}
312-
onConversationUpdate={handleConversationUpdate}
313-
onEvent={props.onEvent}
314-
{...styles}
315-
/>
307+
<TooltipProvider>
308+
<ChatProvider storage={storage}>
309+
<ChatContainer
310+
messageHandler={messageHandler}
311+
placeholder={props.placeholder}
312+
autoHeight={props.autoHeight}
313+
sidebarWidth={props.leftPanelWidth}
314+
onMessageUpdate={handleMessageUpdate}
315+
onConversationUpdate={handleConversationUpdate}
316+
onEvent={props.onEvent}
317+
{...styles}
318+
/>
319+
</ChatProvider>
320+
</TooltipProvider>
316321
);
317322
}
318323
)

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

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
import { Thread } from "./assistant-ui/thread";
1515
import { ThreadList } from "./assistant-ui/thread-list";
1616
import {
17-
ChatProvider,
1817
useChatContext,
1918
RegularThreadData,
2019
ArchivedThreadData
@@ -23,7 +22,6 @@ import { MessageHandler, ChatMessage, ChatCoreProps } from "../types/chatTypes";
2322
import styled from "styled-components";
2423
import { trans } from "i18n";
2524
import { universalAttachmentAdapter } from "../utils/attachmentAdapter";
26-
import { TooltipProvider } from "@radix-ui/react-tooltip";
2725

2826
// ============================================================================
2927
// STYLED CONTAINER - FOLLOWING LOWCODER PATTERNS
@@ -122,7 +120,7 @@ const StyledChatContainer = styled.div<ChatCoreProps>`
122120
`;
123121

124122
// ============================================================================
125-
// CHAT CONTAINER - DIRECT RENDERING LIKE ButtonView
123+
// CHAT CONTAINER - USES CONTEXT FROM CHATPROVIDER
126124
// ============================================================================
127125

128126
const generateId = () => Math.random().toString(36).substr(2, 9);
@@ -334,15 +332,7 @@ function ChatContainerView(props: ChatCoreProps) {
334332
}
335333

336334
// ============================================================================
337-
// EXPORT - WITH PROVIDERS (LIKE BUTTON/INPUT PATTERN)
335+
// EXPORT - SIMPLIFIED (PROVIDERS MOVED UP ONE LEVEL)
338336
// ============================================================================
339337

340-
export function ChatContainer(props: ChatCoreProps) {
341-
return (
342-
<TooltipProvider>
343-
<ChatProvider storage={props.storage}>
344-
<ChatContainerView {...props} />
345-
</ChatProvider>
346-
</TooltipProvider>
347-
);
348-
}
338+
export const ChatContainer = ChatContainerView;

client/packages/lowcoder/src/comps/comps/chatComp/components/ui/button.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,25 @@ const buttonVariants = cva("aui-button", {
2121
},
2222
});
2323

24-
function Button({
25-
className,
26-
variant,
27-
size,
28-
asChild = false,
29-
...props
30-
}: React.ComponentProps<"button"> &
31-
VariantProps<typeof buttonVariants> & {
32-
asChild?: boolean;
33-
}) {
24+
const Button = React.forwardRef<
25+
HTMLButtonElement,
26+
React.ComponentProps<"button"> &
27+
VariantProps<typeof buttonVariants> & {
28+
asChild?: boolean;
29+
}
30+
>(({ className, variant, size, asChild = false, ...props }, ref) => {
3431
const Comp = asChild ? Slot : "button";
3532

3633
return (
3734
<Comp
35+
ref={ref}
3836
data-slot="button"
3937
className={cn(buttonVariants({ variant, size, className }))}
4038
{...props}
4139
/>
4240
);
43-
}
41+
});
42+
43+
Button.displayName = "Button";
4444

4545
export { Button, buttonVariants };

client/packages/lowcoder/src/comps/comps/chatComp/types/chatTypes.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ export interface ChatMessage {
7373

7474
// Main Chat Component Props (with full styling support)
7575
export interface ChatCoreProps {
76-
storage: ChatStorage;
7776
messageHandler: MessageHandler;
7877
placeholder?: string;
7978
autoHeight?: boolean;

0 commit comments

Comments
 (0)