Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

「WIP」:sparkles: feat: ChatItemRenderConfig Actions render 支持更多渲染方式 #208

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading