Skip to content

Commit fcbb821

Browse files
committed
refactor(FR-896): chat card state managment and naming convention (#3573)
Resolves #3574 (FR-896) # Refactor Chat Components for Better State Management - Refactored `AIAgentSelect` to use the `useAIAgent` hook directly instead of requiring agents to be passed as props - Simplified `ChatCard` component by removing redundant state management and using controlled components - Added `onUpdateChat` callback to `ChatCard` to propagate changes to parent components - Improved `ChatHeader` component by making it more declarative with explicit callbacks - Enhanced `Conversation` component to properly update chat state using the new callback pattern -Fetch default endpoint selection in `ChatPage` to improve initial user experience - Removed unnecessary state variables and transitions for better performance - Fixed prop types and interfaces across components for better type safety
1 parent 51835df commit fcbb821

7 files changed

Lines changed: 227 additions & 251 deletions

File tree

react/src/components/Chat/AIAgentSelect.tsx

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
import { AIAgent } from '../../hooks/useAIAgent';
1+
import { AIAgent, useAIAgent } from '../../hooks/useAIAgent';
22
import Flex from '../Flex';
33
import { FluentEmojiIcon } from '../FluentEmojiIcon';
44
import { useControllableValue } from 'ahooks';
55
import { Select, SelectProps, theme } from 'antd';
66
import React, { useState, useTransition } from 'react';
77

8-
interface ChatAgentSelectProps extends Omit<SelectProps, 'options'> {
9-
agents: AIAgent[];
10-
selectedAgent?: AIAgent;
11-
}
8+
interface ChatAgentSelectProps extends Omit<SelectProps, 'options'> {}
129

1310
function makeAgentOptions(agents: AIAgent[], filter?: string) {
1411
return agents
@@ -24,21 +21,17 @@ function makeAgentOptions(agents: AIAgent[], filter?: string) {
2421

2522
const AIAgentSelect: React.FC<ChatAgentSelectProps> = ({
2623
loading,
27-
agents,
28-
selectedAgent,
2924
...props
3025
}) => {
3126
const { token } = theme.useToken();
32-
const [controllableValue, setControllableValue] =
33-
useControllableValue<AIAgent>(props, {
34-
valuePropName: 'value',
35-
trigger: 'onChange',
36-
defaultValue: props.value,
37-
});
27+
const [controllableValue, setControllableValue] = useControllableValue(props);
3828

3929
const [searchAgent, setSearchAgent] = useState<string>();
4030
const [isSearchPending, startSearchTransition] = useTransition();
4131

32+
const { agents } = useAIAgent();
33+
const selectedAgent = agents.find((agent) => agent.id === controllableValue);
34+
4235
return (
4336
<>
4437
{selectedAgent && (

0 commit comments

Comments
 (0)