问答助手完成子组件反对填写反馈建议模态框确认按钮loading加载,增加confirmLoading状态,并改确认事件为异步,传递至父组件

问答助手解决Popconfirm气泡确认框不触发的问题,为Dify二次开发问答助手前端的Tooltip导致及Popconfirm需在Button按钮的上一级才可触发,将Dify的Tooltip更换成Ant Design的Tooltip,此气泡确认框的作用为取消赞成及取消反对时进行确认,而不是直接取消
This commit is contained in:
wenyongda 2025-07-23 17:28:10 +08:00
parent 36f93db93f
commit 26cd7f7e8f
5 changed files with 60 additions and 31 deletions

View File

@ -4,7 +4,8 @@ import { t } from 'i18next'
import { debounce } from 'lodash-es'
import copy from 'copy-to-clipboard'
import s from './style.module.css'
import Tooltip from '@/app/components/base/tooltip'
// import Tooltip from '@/app/components/base/tooltip'
import { Tooltip } from 'antd';
type ICopyBtnProps = {
value: string
@ -31,8 +32,7 @@ const CopyBtn = ({
return (
<div className={`${className}`}>
<Tooltip
popupContent={(isCopied ? t('appApi.copied') : t('appApi.copy'))}
asChild={false}
title={(isCopied ? t('appApi.copied') : t('appApi.copy'))}
>
<div
onMouseLeave={onMouseLeave}

View File

@ -1,7 +1,8 @@
'use client'
import { t } from 'i18next'
import { Refresh } from '@/app/components/base/icons/src/vender/line/general'
import Tooltip from '@/app/components/base/tooltip'
// import Tooltip from '@/app/components/base/tooltip'
import { Tooltip } from 'antd';
type Props = {
className?: string
@ -12,7 +13,7 @@ const RegenerateBtn = ({ className, onClick }: Props) => {
return (
<div className={`${className}`}>
<Tooltip
popupContent={t('appApi.regenerate') as string}
title={t('appApi.regenerate') as string}
>
<div
className={'box-border p-0.5 flex items-center justify-center rounded-md bg-white cursor-pointer'}

View File

@ -6,7 +6,7 @@ const { TextArea } = Input;
interface FeedbackModalProps {
open: boolean;
onOk: (selectedOption: number | null, feedbackText: string) => void;
onOk: (selectedOption: number | null, feedbackText: string) => Promise<void>;
onCancel: () => void;
}
@ -14,12 +14,20 @@ const FeedbackModal: React.FC<FeedbackModalProps> = ({ open, onOk, onCancel }) =
const [selectedOption, setSelectedOption] = useState<number | null>(null);
const [feedbackText, setFeedbackText] = useState<string>('');
const { t } = useTranslation()
const handleOk = () => {
const [confirmLoading, setConfirmLoading] = useState(false);
const handleOk = async () => {
if (!feedbackText) {
message.warning('请填写反馈建议');
return;
}
onOk(selectedOption, feedbackText);
setConfirmLoading(true)
try {
await onOk(selectedOption, feedbackText);
} finally {
setConfirmLoading(false)
}
};
return (
@ -30,6 +38,7 @@ const FeedbackModal: React.FC<FeedbackModalProps> = ({ open, onOk, onCancel }) =
onCancel={onCancel}
okText={`${t('common.operation.confirm')}`}
cancelText={`${t('common.operation.cancel')}`}
confirmLoading={confirmLoading}
>
{/* <div>
<Checkbox

View File

@ -690,7 +690,6 @@ export const useChatWithHistory = (installedAppInfo?: InstalledApp) => {
}
setIsFeedbackModalVisible(false)
}}
// feedbackText={}
/>
),
};

View File

@ -3,6 +3,7 @@ import {
memo,
useMemo,
useState,
useCallback
} from 'react'
import { useTranslation } from 'react-i18next'
import type { ChatItem } from '../../types'
@ -19,8 +20,9 @@ import {
ThumbsDown,
ThumbsUp,
} from '@/app/components/base/icons/src/vender/line/alertsAndFeedback'
import Tooltip from '@/app/components/base/tooltip'
// import Tooltip from '@/app/components/base/tooltip'
import Log from '@/app/components/chat/log'
import { message, Popconfirm, Tooltip } from 'antd';
interface OperationProps {
item: ChatItem
@ -80,6 +82,14 @@ const Operation: FC<OperationProps> = ({
}
}
const confirmCancelCallback = useCallback(async () => {
try {
await handleFeedback(null)
} finally {
message.success(localFeedback!.rating === 'like' ? `${t('appDebug.operation.cancelAgree')}成功` : `${t('appDebug.operation.cancelDisagree')}成功`)
}
}, [handleFeedback])
const operationWidth = useMemo(() => {
let width = 0
if (!isOpeningStatement)
@ -171,7 +181,7 @@ const Operation: FC<OperationProps> = ({
{
config?.supportFeedback && !localFeedback?.rating && onFeedback && !isOpeningStatement && (
<div className='hidden group-hover:flex shrink-0 items-center px-0.5 bg-white border-[0.5px] border-gray-100 shadow-md text-gray-500 rounded-lg'>
<Tooltip popupContent={t('appDebug.operation.agree')}>
<Tooltip title={t('appDebug.operation.agree')}>
<div
className='flex items-center justify-center mr-0.5 w-6 h-6 rounded-md hover:bg-black/5 hover:text-gray-800 cursor-pointer'
onClick={() => handleFeedback('like')}
@ -180,7 +190,7 @@ const Operation: FC<OperationProps> = ({
</div>
</Tooltip>
<Tooltip
popupContent={t('appDebug.operation.disagree')}
title={t('appDebug.operation.disagree')}
>
<div
className='flex items-center justify-center w-6 h-6 rounded-md hover:bg-black/5 hover:text-gray-800 cursor-pointer'
@ -195,27 +205,37 @@ const Operation: FC<OperationProps> = ({
{
config?.supportFeedback && localFeedback?.rating && onFeedback && !isOpeningStatement && (
<Tooltip
popupContent={localFeedback.rating === 'like' ? t('appDebug.operation.cancelAgree') : t('appDebug.operation.cancelDisagree')}
title={localFeedback.rating === 'like' ? t('appDebug.operation.cancelAgree') : t('appDebug.operation.cancelDisagree')}
>
<div
className={`
flex items-center justify-center w-7 h-7 rounded-[10px] border-[2px] border-white cursor-pointer
${localFeedback.rating === 'like' && 'bg-blue-50 text-blue-600'}
${localFeedback.rating === 'dislike' && 'bg-red-100 text-red-600'}
`}
onClick={() => handleFeedback(null)}
<Popconfirm
title={localFeedback.rating === 'like' ? t('appDebug.operation.cancelAgree') : t('appDebug.operation.cancelDisagree')}
description={localFeedback.rating === 'like' ? `是否${t('appDebug.operation.cancelAgree')}` : `是否${t('appDebug.operation.cancelDisagree')}`}
onConfirm={confirmCancelCallback}
okText={`${t('common.operation.confirm')}`}
cancelText={`${t('common.operation.cancel')}`}
>
{
localFeedback.rating === 'like' && (
<ThumbsUp className='w-4 h-4' />
)
}
{
localFeedback.rating === 'dislike' && (
<ThumbsDown className='w-4 h-4' />
)
}
</div>
<button
type="button"
className={`
flex items-center justify-center w-7 h-7 rounded-[10px] border-[2px] border-white cursor-pointer
${localFeedback.rating === 'like' && 'bg-blue-50 text-blue-600'}
${localFeedback.rating === 'dislike' && 'bg-red-100 text-red-600'}
`}
onClick={(e) => e.stopPropagation()}
>
{
localFeedback.rating === 'like' && (
<ThumbsUp className='w-4 h-4' />
)
}
{
localFeedback.rating === 'dislike' && (
<ThumbsDown className='w-4 h-4' />
)
}
</button>
</Popconfirm>
</Tooltip>
)
}