import React, { useCallback, useState } from 'react'; import { ModalBody, Box, useTheme, Flex, Progress, Link } from '@chakra-ui/react'; import { getDatasetDataItemById } from '@/web/core/dataset/api'; import { useLoading } from '@/web/common/hooks/useLoading'; import { useToast } from '@/web/common/hooks/useToast'; import { getErrText } from '@fastgpt/global/common/error/utils'; import MyIcon from '@/components/Icon'; import InputDataModal, { RawSourceText, type InputDataType } from '@/pages/dataset/detail/components/InputDataModal'; import MyModal from '../MyModal'; import { useTranslation } from 'next-i18next'; import type { SearchDataResponseItemType } from '@fastgpt/global/core/dataset/type'; import MyTooltip from '../MyTooltip'; import NextLink from 'next/link'; import { useSystemStore } from '@/web/common/system/useSystemStore'; const QuoteModal = ({ rawSearch = [], onClose, isShare }: { rawSearch: SearchDataResponseItemType[]; onClose: () => void; isShare: boolean; }) => { const { t } = useTranslation(); return ( <> {t('core.chat.Quote Amount', { amount: rawSearch.length })} {t('core.chat.quote.Quote Tip')} } > ); }; export default QuoteModal; export const QuoteList = React.memo(function QuoteList({ rawSearch = [], isShare }: { rawSearch: SearchDataResponseItemType[]; isShare: boolean; }) { const { t } = useTranslation(); const { isPc } = useSystemStore(); const theme = useTheme(); const { toast } = useToast(); const { setIsLoading, Loading } = useLoading(); const [editInputData, setEditInputData] = useState(); /** * click edit, get new DataItem */ const onclickEdit = useCallback( async (item: InputDataType) => { if (!item.id) return; try { setIsLoading(true); const data = await getDatasetDataItemById(item.id); if (!data) { throw new Error('该数据已被删除'); } setEditInputData(data); } catch (err) { toast({ status: 'warning', title: getErrText(err) }); } setIsLoading(false); }, [setIsLoading, toast] ); return ( <> {rawSearch.map((item, i) => ( {!isShare && ( {t('core.dataset.Go Dataset')} )} {item.q} {item.a} {!isShare && ( {isPc && ( # {item.id} )} {item.q.length + (item.a?.length || 0)} {!isShare && item.score && ( {item.score.toFixed(4)} )} {item.id && ( onclickEdit(item)} /> )} )} ))} {editInputData && editInputData.id && ( setEditInputData(undefined)} onSuccess={() => { console.log('更新引用成功'); }} onDelete={() => { console.log('删除引用成功'); }} defaultValue={editInputData} collectionId={editInputData.collectionId} /> )} ); });