Skip to content

Commit

Permalink
✨ feat: ChatItemRenderConfig Actions render support more custiom
Browse files Browse the repository at this point in the history
  • Loading branch information
ONLY-yours committed May 14, 2024
1 parent 371bc65 commit 8b404b4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/ChatItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const ChatItem = memo<ChatItemProps>((props) => {
text,
chatItemRenderConfig,
renderErrorMessages,
renderActions,
markdownProps,
onDoubleClick,
originData,
Expand Down Expand Up @@ -113,6 +114,8 @@ const ChatItem = memo<ChatItemProps>((props) => {
]);

const actionsDom = useMemo(() => {
console.log('renderActions', renderActions);

if (chatItemRenderConfig?.actionsRender === false) return null;
if (error) return null;
const dom = (
Expand Down
4 changes: 4 additions & 0 deletions src/ChatItem/type.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ReactNode } from 'react';

import { RenderAction } from '@/ChatList';
import { EditableMessageProps } from '@/EditableMessage';
import { ChatMessageError, DivProps, MetaData } from '@/types';
import { MarkdownProps } from '@ant-design/pro-editor';
Expand Down Expand Up @@ -59,6 +60,9 @@ export interface ChatItemProps<T = Record<string, any>> {
*/
primary?: boolean;
renderMessage?: (content: ReactNode) => ReactNode;
renderActions?: {
[actionKey: string]: RenderAction;
};
/**
* @description Whether to show the title of the chat item
*/
Expand Down
5 changes: 5 additions & 0 deletions src/ChatList/ChatListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,16 @@ const ChatListItem = (props: ChatListItemProps) => {
* @returns 渲染操作按钮的组件。
*/
const Actions = useRefFunction(({ data }: { data: ChatMessage }) => {
console.log('renderActions', renderActions);

if (!renderActions || !item?.role) return;
let RenderFunction;
if (renderActions?.[item.role]) RenderFunction = renderActions[item.role];
if (renderActions?.['default']) RenderFunction = renderActions['default'];
if (!RenderFunction) RenderFunction = ActionsBar;

console.log('data', data);

const handleActionClick: ListItemProps['onActionsClick'] = (action, data) => {
switch (action.key) {
case 'copy': {
Expand Down Expand Up @@ -243,6 +247,7 @@ const ChatListItem = (props: ChatListItemProps) => {
className={chatItemClassName}
data-id={item.id}
actions={<Actions data={item} />}
renderActions={renderActions}
avatar={(item as any).meta}
avatarAddon={groupNav}
editing={editing}
Expand Down

0 comments on commit 8b404b4

Please sign in to comment.