import React, { useCallback, useMemo, 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 'react-i18next'; import { useRouter } from 'next/router'; 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 }: { rawSearch: SearchDataResponseItemType[]; onClose: () => void; }) => { const { t } = useTranslation(); const { isPc } = useSystemStore(); const theme = useTheme(); const router = useRouter(); const { toast } = useToast(); const { setIsLoading, Loading } = useLoading(); const [editInputData, setEditInputData] = useState(); const isShare = useMemo(() => router.pathname === '/chat/share', [router.pathname]); /** * click edit, get new kbDataItem */ 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.length}条) 注意: 修改知识库内容成功后,此处不会显示变更情况。点击编辑后,会显示知识库最新的内容。 } > {rawSearch.map((item, i) => ( {!isShare && ( {t('core.dataset.Go Dataset')} )} {item.q} {item.a} {!isShare && ( {isPc && ( # {item.id} )} {item.q.length + item.a.length} {!isShare && item.score && ( {item.score.toFixed(4)} )} {item.id && ( onclickEdit(item)} /> )} )} ))} {editInputData && editInputData.id && ( setEditInputData(undefined)} onSuccess={() => { console.log('更新引用成功'); }} onDelete={() => { console.log('删除引用成功'); }} datasetId={editInputData.datasetId} defaultValues={editInputData} /> )} ); }; export default QuoteModal;