diff --git a/packages/web/components/common/Image/PhotoView.tsx b/packages/web/components/common/Image/PhotoView.tsx index c198049e2..8d7e06054 100644 --- a/packages/web/components/common/Image/PhotoView.tsx +++ b/packages/web/components/common/Image/PhotoView.tsx @@ -5,9 +5,14 @@ import { Box, Image, ImageProps } from '@chakra-ui/react'; import { useSystem } from '../../../hooks/useSystem'; import Loading from '../MyLoading'; -const MyPhotoView = (props: ImageProps) => { +const MyPhotoView = ({ + forbidImgPreview, + ...props +}: ImageProps & { forbidImgPreview?: boolean }) => { const { isPc } = useSystem(); - return ( + return forbidImgPreview ? ( + + ) : ( = ButtonProps & { value?: T; @@ -32,7 +32,7 @@ export type SelectProps = ButtonProps & { value: T; }[]; isLoading?: boolean; - onchange?: (val: T) => void; + onchange?: (val: T) => any | Promise; }; const MySelect = ( @@ -82,6 +82,10 @@ const MySelect = ( } }, [isOpen]); + const { runAsync: onChange, loading } = useRequest2((val: T) => onchange?.(val)); + + const isSelecting = loading || isLoading; + return ( ( > ( {...props} > - {isLoading && } + {isSelecting && } {selectItem?.alias || selectItem?.label || placeholder} @@ -160,8 +164,8 @@ const MySelect = ( color: 'myGray.900' })} onClick={() => { - if (onchange && value !== item.value) { - onchange(item.value); + if (onChange && value !== item.value) { + onChange(item.value); } }} whiteSpace={'pre-wrap'} diff --git a/packages/web/components/common/Tabs/LightRowTabs.tsx b/packages/web/components/common/Tabs/LightRowTabs.tsx index 7395fe5a3..1a9ca5ffa 100644 --- a/packages/web/components/common/Tabs/LightRowTabs.tsx +++ b/packages/web/components/common/Tabs/LightRowTabs.tsx @@ -1,5 +1,5 @@ import React, { useMemo } from 'react'; -import { Box, Flex, Grid, Image } from '@chakra-ui/react'; +import { Box, Flex, Grid } from '@chakra-ui/react'; import type { FlexProps, GridProps } from '@chakra-ui/react'; import { useTranslation } from 'next-i18next'; import Avatar from '../Avatar'; @@ -9,7 +9,7 @@ type Props = Omit & { value: ValueType; size?: 'sm' | 'md' | 'lg'; inlineStyles?: FlexProps; - activatedColor?: string; + activeColor?: string; onChange: (value: ValueType) => void; }; @@ -17,7 +17,7 @@ const LightRowTabs = ({ list, size = 'md', value, - activatedColor = 'primary.600', + activeColor = 'primary.600', onChange, inlineStyles, ...props @@ -68,10 +68,10 @@ const LightRowTabs = ({ whiteSpace={'nowrap'} {...(value === item.value ? { - color: activatedColor, + color: activeColor, cursor: 'default', fontWeight: 'bold', - borderBottomColor: activatedColor + borderBottomColor: activeColor } : { cursor: 'pointer' diff --git a/projects/app/src/components/Markdown/img/Image.tsx b/projects/app/src/components/Markdown/img/Image.tsx index f86655019..ee4102d2e 100644 --- a/projects/app/src/components/Markdown/img/Image.tsx +++ b/projects/app/src/components/Markdown/img/Image.tsx @@ -3,7 +3,7 @@ import { Box, ImageProps, Skeleton } from '@chakra-ui/react'; import MyPhotoView from '@fastgpt/web/components/common/Image/PhotoView'; import { useBoolean } from 'ahooks'; -const MdImage = ({ src, ...props }: { src?: string } & ImageProps) => { +const MdImage = ({ src, ...props }: { src?: string; forbidImgPreview?: boolean } & ImageProps) => { const [isLoaded, { setTrue }] = useBoolean(false); const [renderSrc, setRenderSrc] = useState(src); @@ -11,7 +11,6 @@ const MdImage = ({ src, ...props }: { src?: string } & ImageProps) => { if (src?.includes('base64') && !src.startsWith('data:image')) { return Invalid base64 image; } - return ( import('./chat/QuestionGuide'), { ssr: false const Markdown = ({ source = '', - showAnimation = false + showAnimation = false, + forbidImgPreview = false }: { source?: string; showAnimation?: boolean; + forbidImgPreview?: boolean; }) => { const components = useMemo( () => ({ - img: Image, + img: (props: any) => , pre: RewritePre, p: (pProps: any) =>

, code: Code, a: A }), - [] + [forbidImgPreview] ); const formatSource = useMemo(() => { @@ -74,7 +76,7 @@ const Markdown = ({ export default React.memo(Markdown); /* Custom dom */ -const Code = React.memo(function Code(e: any) { +function Code(e: any) { const { className, codeBlock, children } = e; const match = /language-(\w+)/.exec(className || ''); const codeType = match?.[1]; @@ -103,11 +105,13 @@ const Code = React.memo(function Code(e: any) { }, [codeType, className, codeBlock, match, children, strChildren]); return Component; -}); -const Image = React.memo(function Image({ src }: { src?: string }) { - return ; -}); -const A = React.memo(function A({ children, ...props }: any) { +} + +function Image({ src, forbidImgPreview }: { forbidImgPreview: boolean; src?: string }) { + return ; +} + +function A({ children, ...props }: any) { const { t } = useTranslation(); // empty href link @@ -152,7 +156,7 @@ const A = React.memo(function A({ children, ...props }: any) { } return {children}; -}); +} function RewritePre({ children }: any) { const modifiedChildren = React.Children.map(children, (child) => { diff --git a/projects/app/src/components/Select/AIModelSelector.tsx b/projects/app/src/components/Select/AIModelSelector.tsx index 0c93ff4e2..6619549ca 100644 --- a/projects/app/src/components/Select/AIModelSelector.tsx +++ b/projects/app/src/components/Select/AIModelSelector.tsx @@ -61,7 +61,7 @@ const AIModelSelector = ({ list, onchange, disableTip, ...props }: Props) => { router.push(AI_POINT_USAGE_CARD_ROUTE); return; } - onchange?.(e); + return onchange?.(e); }, [onchange, router] ); diff --git a/projects/app/src/components/support/permission/DefaultPerList/index.tsx b/projects/app/src/components/support/permission/DefaultPerList/index.tsx index 2a282543f..f97a8efa6 100644 --- a/projects/app/src/components/support/permission/DefaultPerList/index.tsx +++ b/projects/app/src/components/support/permission/DefaultPerList/index.tsx @@ -1,4 +1,4 @@ -import { Box, BoxProps, ButtonProps } from '@chakra-ui/react'; +import { Box, BoxProps } from '@chakra-ui/react'; import MySelect from '@fastgpt/web/components/common/MySelect'; import React from 'react'; import type { PermissionValueType } from '@fastgpt/global/support/permission/type'; @@ -20,7 +20,6 @@ type Props = Omit & { writePer?: PermissionValueType; onChange: (v: PermissionValueType) => Promise | any; isInheritPermission?: boolean; - isDisabled?: boolean; hasParent?: boolean; }; @@ -42,15 +41,12 @@ const DefaultPermissionList = ({ { label: t('user:permission.team_write'), value: writePer } ]; - const { runAsync: onRequestChange, loading } = useRequest2((v: PermissionValueType) => - onChange(v) - ); + const { runAsync: onRequestChange } = useRequest2((v: PermissionValueType) => onChange(v)); return ( <> { diff --git a/projects/app/src/pages/dataset/detail/components/CollectionCard/Header.tsx b/projects/app/src/pages/dataset/detail/components/CollectionCard/Header.tsx index f2e063d88..d85f610bd 100644 --- a/projects/app/src/pages/dataset/detail/components/CollectionCard/Header.tsx +++ b/projects/app/src/pages/dataset/detail/components/CollectionCard/Header.tsx @@ -1,5 +1,14 @@ import React, { useCallback, useRef } from 'react'; -import { Box, Flex, MenuButton, Button, Link, useTheme, useDisclosure } from '@chakra-ui/react'; +import { + Box, + Flex, + MenuButton, + Button, + Link, + useTheme, + useDisclosure, + HStack +} from '@chakra-ui/react'; import { getDatasetCollectionPathById, postDatasetCollection, @@ -114,55 +123,55 @@ const Header = ({}: {}) => { const isWebSite = datasetDetail?.type === DatasetTypeEnum.websiteDataset; return ( - - - ({ - parentId: path.parentId, - parentName: i === paths.length - 1 ? `${path.parentName}` : path.parentName - }))} - FirstPathDom={ - - - {!isWebSite && } - {t(DatasetTypeMap[datasetDetail?.type]?.collectionLabel as any)}({total}) - - {datasetDetail?.websiteConfig?.url && ( - - {t('common:core.dataset.website.Base Url')}: - - {datasetDetail.websiteConfig.url} - + + + + ({ + parentId: path.parentId, + parentName: i === paths.length - 1 ? `${path.parentName}` : path.parentName + }))} + FirstPathDom={ + + + {!isWebSite && } + {t(DatasetTypeMap[datasetDetail?.type]?.collectionLabel as any)}({total}) - )} - - } - onClick={(e) => { - router.replace({ - query: { - ...router.query, - parentId: e - } - }); - }} - /> - + {datasetDetail?.websiteConfig?.url && ( + + {t('common:core.dataset.website.Base Url')}: + + {datasetDetail.websiteConfig.url} + + + )} + + } + onClick={(e) => { + router.replace({ + query: { + ...router.query, + parentId: e + } + }); + }} + /> + - {/* search input */} - {isPc && ( - + {/* search input */} + {isPc && ( { } }} /> - - )} + )} + + {/* Tag */} + {datasetDetail.permission.hasWritePer && feConfigs?.isPlus && } + {/* diff collection button */} {datasetDetail.permission.hasWritePer && ( - - {feConfigs?.isPlus && } - + {datasetDetail?.type === DatasetTypeEnum.dataset && ( { ]} /> )} - + )} {/* modal */} @@ -427,7 +437,7 @@ const Header = ({}: {}) => { )} {isOpenFileSourceSelector && } - + ); }; diff --git a/projects/app/src/pages/dataset/detail/components/CollectionCard/TagManageModal.tsx b/projects/app/src/pages/dataset/detail/components/CollectionCard/TagManageModal.tsx index fa607c7a8..bcf20d6f7 100644 --- a/projects/app/src/pages/dataset/detail/components/CollectionCard/TagManageModal.tsx +++ b/projects/app/src/pages/dataset/detail/components/CollectionCard/TagManageModal.tsx @@ -29,7 +29,7 @@ const TagManageModal = ({ onClose }: { onClose: () => void }) => { const datasetDetail = useContextSelector(DatasetPageContext, (v) => v.datasetDetail); const loadDatasetTags = useContextSelector(DatasetPageContext, (v) => v.loadDatasetTags); const loadAllDatasetTags = useContextSelector(DatasetPageContext, (v) => v.loadAllDatasetTags); - const { getData, collections } = useContextSelector(CollectionPageContext, (v) => v); + const { getData, pageNum, collections } = useContextSelector(CollectionPageContext, (v) => v); const tagInputRef = useRef(null); const editInputRef = useRef(null); @@ -73,42 +73,43 @@ const TagManageModal = ({ onClose }: { onClose: () => void }) => { errorToast: t('common:common.Create Failed') }); - const { mutate: onDeleteCollectionTag, isLoading: isDeleteCollectionTagLoading } = useRequest({ - mutationFn: async (tag: string) => { - const id = await delDatasetCollectionTag({ + const { runAsync: onDeleteCollectionTag, loading: isDeleteCollectionTagLoading } = useRequest2( + (tag: string) => { + return delDatasetCollectionTag({ datasetId: datasetDetail._id, id: tag }); - return id; }, + { + onSuccess() { + fetchData(1); + loadDatasetTags({ id: datasetDetail._id, searchKey: '' }); + loadAllDatasetTags({ id: datasetDetail._id }); + }, + successToast: t('common:common.Delete Success'), + errorToast: t('common:common.Delete Failed') + } + ); - onSuccess() { - fetchData(1); - loadDatasetTags({ id: datasetDetail._id, searchKey: '' }); - loadAllDatasetTags({ id: datasetDetail._id }); - }, - successToast: t('common:common.Delete Success'), - errorToast: t('common:common.Delete Failed') - }); - - const { mutate: onUpdateCollectionTag, isLoading: isUpdateCollectionTagLoading } = useRequest({ - mutationFn: async (tag: DatasetTagType) => { - const id = await updateDatasetCollectionTag({ + const { runAsync: onUpdateCollectionTag, loading: isUpdateCollectionTagLoading } = useRequest2( + async (tag: DatasetTagType) => { + return updateDatasetCollectionTag({ datasetId: datasetDetail._id, tagId: tag._id, tag: tag.tag }); - return id; }, - onSuccess() { - fetchData(1); - loadDatasetTags({ id: datasetDetail._id, searchKey: '' }); - loadAllDatasetTags({ id: datasetDetail._id }); + { + onSuccess() { + fetchData(1); + loadDatasetTags({ id: datasetDetail._id, searchKey: '' }); + loadAllDatasetTags({ id: datasetDetail._id }); + } } - }); + ); - const { mutate: onSaveCollectionTag, isLoading: isSaveCollectionTagLoading } = useRequest({ - mutationFn: async ({ + const { runAsync: onSaveCollectionTag, loading: isSaveCollectionTagLoading } = useRequest2( + async ({ tag, originCollectionIds, collectionIds @@ -117,22 +118,21 @@ const TagManageModal = ({ onClose }: { onClose: () => void }) => { originCollectionIds: string[]; collectionIds: string[]; }) => { - try { - await postAddTagsToCollections({ - tag, - originCollectionIds, - collectionIds, - datasetId: datasetDetail._id - }); - } catch (error) {} + return postAddTagsToCollections({ + tag, + originCollectionIds, + collectionIds, + datasetId: datasetDetail._id + }); }, - - onSuccess() { - getData(1); - }, - successToast: t('common:common.Save Success'), - errorToast: t('common:common.Save Failed') - }); + { + onFinally() { + getData(pageNum); + }, + successToast: t('common:common.Save Success'), + errorToast: t('common:common.Save Failed') + } + ); const { list, @@ -379,11 +379,9 @@ const AddTagToCollections = ({ const { t } = useTranslation(); const datasetDetail = useContextSelector(DatasetPageContext, (v) => v.datasetDetail); - const [selectedCollections, setSelectedCollections] = useState([]); - - useEffect(() => { - setSelectedCollections(currentAddTag.collections); - }, []); + const [selectedCollections, setSelectedCollections] = useState( + currentAddTag.collections + ); const [searchText, setSearchText] = useState(''); diff --git a/projects/app/src/pages/dataset/detail/components/CollectionCard/index.tsx b/projects/app/src/pages/dataset/detail/components/CollectionCard/index.tsx index 6a93416d0..41b8e40f9 100644 --- a/projects/app/src/pages/dataset/detail/components/CollectionCard/index.tsx +++ b/projects/app/src/pages/dataset/detail/components/CollectionCard/index.tsx @@ -21,7 +21,7 @@ import { useQuery } from '@tanstack/react-query'; import { useConfirm } from '@fastgpt/web/hooks/useConfirm'; import { useTranslation } from 'next-i18next'; import MyIcon from '@fastgpt/web/components/common/Icon'; -import { useRequest, useRequest2 } from '@fastgpt/web/hooks/useRequest'; +import { useRequest2 } from '@fastgpt/web/hooks/useRequest'; import { useRouter } from 'next/router'; import MyMenu from '@fastgpt/web/components/common/MyMenu'; import { useEditTitle } from '@/web/common/hooks/useEditTitle'; @@ -119,23 +119,22 @@ const CollectionCard = () => { successToast: t('common:common.Update Success') } ); - const { mutate: onDelCollection, isLoading: isDeleting } = useRequest({ - mutationFn: (collectionId: string) => { + const { runAsync: onDelCollection, loading: isDeleting } = useRequest2( + (collectionId: string) => { return delDatasetCollectionById({ id: collectionId }); }, - onSuccess() { - getData(pageNum); - }, - successToast: t('common:common.Delete Success'), - errorToast: t('common:common.Delete Failed') - }); + { + onSuccess() { + getData(pageNum); + }, + successToast: t('common:common.Delete Success'), + errorToast: t('common:common.Delete Failed') + } + ); - const { mutate: onclickStartSync, isLoading: isSyncing } = useRequest({ - mutationFn: (collectionId: string) => { - return postLinkCollectionSync(collectionId); - }, + const { runAsync: onclickStartSync, loading: isSyncing } = useRequest2(postLinkCollectionSync, { onSuccess(res: DatasetCollectionSyncResultEnum) { getData(pageNum); toast({ @@ -186,12 +185,12 @@ const CollectionCard = () => { return ( - + {/* header */}

{/* collection table */} - + @@ -237,7 +236,7 @@ const CollectionCard = () => { >
- + { offset={[-70, 5]} Button={ { { { label: ( - + {t('common:core.dataset.collection.Sync')} ), @@ -331,7 +334,7 @@ const CollectionCard = () => { { label: ( - + {t('common:Move')} ), @@ -341,7 +344,7 @@ const CollectionCard = () => { { label: ( - + {t('common:Rename')} ), @@ -365,7 +368,7 @@ const CollectionCard = () => { {t('common:common.Delete')} diff --git a/projects/app/src/pages/dataset/detail/components/DataCard.tsx b/projects/app/src/pages/dataset/detail/components/DataCard.tsx index 93deb5ea2..88884ec2d 100644 --- a/projects/app/src/pages/dataset/detail/components/DataCard.tsx +++ b/projects/app/src/pages/dataset/detail/components/DataCard.tsx @@ -47,7 +47,7 @@ import { useSystem } from '@fastgpt/web/hooks/useSystem'; import TagsPopOver from './CollectionCard/TagsPopOver'; import { useSystemStore } from '@/web/common/system/useSystemStore'; import MyDivider from '@fastgpt/web/components/common/MyDivider'; -import index from '../../../index'; +import Markdown from '@/components/Markdown'; const DataCard = () => { const BoxRef = useRef(null); @@ -232,6 +232,7 @@ const DataCard = () => { setEditDataId(item._id); }} > + {/* Data tag */} { ID:{item._id} - - {/* {item.forbid ? ( - - {datasetT('Disabled')} - - ) : ( - - {datasetT('Enabled')} - - )} - { - e.stopPropagation(); - }} - h={'12px'} - > - { - e.stopPropagation(); - onUpdate({ - dataId: item._id, - forbid: !e.target.checked - }); - }} - /> - */} - - - {item.q} - - {item.a} - {/* Mask */} + {/* Data content */} + + + {!!item.a && ( + <> + + + + )} + + + {/* Mask */} + - - - {item.q.length + (item.a?.length || 0)} - - {canWrite && ( - } - variant={'whiteDanger'} - size={'xsSquare'} - aria-label={'delete'} - onClick={(e) => { - e.stopPropagation(); - openConfirm(async () => { - try { - await delOneDatasetDataById(item._id); - getData(pageNum); - } catch (error) { - toast({ - title: getErrText(error), - status: 'error' - }); - } - })(); - }} - /> - )} + name="common/text/t" + w={'14px'} + mr={1} + /> + {item.q.length + (item.a?.length || 0)} - + {canWrite && ( + } + variant={'whiteDanger'} + size={'xsSquare'} + aria-label={'delete'} + onClick={(e) => { + e.stopPropagation(); + openConfirm(async () => { + try { + await delOneDatasetDataById(item._id); + getData(pageNum); + } catch (error) { + toast({ + title: getErrText(error), + status: 'error' + }); + } + })(); + }} + /> + )} + ))} diff --git a/projects/app/src/pages/dataset/detail/components/Info.tsx b/projects/app/src/pages/dataset/detail/components/Info.tsx index 42d4df4f1..7cd49a79a 100644 --- a/projects/app/src/pages/dataset/detail/components/Info.tsx +++ b/projects/app/src/pages/dataset/detail/components/Info.tsx @@ -1,7 +1,6 @@ import React, { useState } from 'react'; import { useRouter } from 'next/router'; -import { Box, Flex, Button, IconButton, Input, Textarea, HStack } from '@chakra-ui/react'; -import { DeleteIcon } from '@chakra-ui/icons'; +import { Box, Flex, Input } from '@chakra-ui/react'; import { delDatasetById } from '@/web/core/dataset/api'; import { useSelectFile } from '@/web/common/file/hooks/useSelectFile'; import { useConfirm } from '@fastgpt/web/hooks/useConfirm'; @@ -9,7 +8,6 @@ import { useForm } from 'react-hook-form'; import { compressImgFileAndUpload } from '@/web/common/file/controller'; import type { DatasetItemType } from '@fastgpt/global/core/dataset/type.d'; import Avatar from '@fastgpt/web/components/common/Avatar'; -import MyTooltip from '@fastgpt/web/components/common/MyTooltip'; import { useTranslation } from 'next-i18next'; import { useSystemStore } from '@/web/common/system/useSystemStore'; import { useRequest, useRequest2 } from '@fastgpt/web/hooks/useRequest'; @@ -56,7 +54,6 @@ const Info = ({ datasetId }: { datasetId: string }) => { defaultValues: datasetDetail }); - const avatar = watch('avatar'); const vectorModel = watch('vectorModel'); const agentModel = watch('agentModel'); const defaultPermission = watch('defaultPermission'); @@ -77,8 +74,20 @@ const Info = ({ datasetId }: { datasetId: string }) => { multiple: false }); - const { mutate: onSave, isLoading: isSaving } = useRequest({ - mutationFn: (data: DatasetItemType) => { + /* 点击删除 */ + const { mutate: onclickDelete, isLoading: isDeleting } = useRequest({ + mutationFn: () => { + return delDatasetById(datasetId); + }, + onSuccess() { + router.replace(`/dataset/list`); + }, + successToast: t('common:common.Delete Success'), + errorToast: t('common:common.Delete Failed') + }); + + const { runAsync: onSave, loading: isSaving } = useRequest2( + (data: DatasetItemType) => { return updateDataset({ id: datasetId, agentModel: data.agentModel, @@ -86,12 +95,14 @@ const Info = ({ datasetId }: { datasetId: string }) => { defaultPermission: data.defaultPermission }); }, - successToast: t('common:common.Update Success'), - errorToast: t('common:common.Update Failed') - }); + { + successToast: t('common:common.Update Success'), + errorToast: t('common:common.Update Failed') + } + ); - const { mutate: onSelectFile, isLoading: isSelecting } = useRequest({ - mutationFn: (e: File[]) => { + const { runAsync: onSelectFile, loading: isSelecting } = useRequest2( + (e: File[]) => { const file = e[0]; if (!file) return Promise.resolve(null); return compressImgFileAndUpload({ @@ -101,37 +112,41 @@ const Info = ({ datasetId }: { datasetId: string }) => { maxH: 300 }); }, - onSuccess(src: string | null) { - if (src) { - setValue('avatar', src); - } - }, - errorToast: t('common:common.avatar.Select Failed') - }); + { + onSuccess(src: string | null) { + if (src) { + setValue('avatar', src); + } + }, + errorToast: t('common:common.avatar.Select Failed') + } + ); - const { mutate: onRebuilding, isLoading: isRebuilding } = useRequest({ - mutationFn: (vectorModel: VectorModelItemType) => { + const { runAsync: onRebuilding, loading: isRebuilding } = useRequest2( + (vectorModel: VectorModelItemType) => { return postRebuildEmbedding({ datasetId, vectorModel: vectorModel.model }); }, - onSuccess() { - refetchDatasetTraining(); - loadDatasetDetail(datasetId); - }, - successToast: t('dataset:rebuild_embedding_start_tip'), - errorToast: t('common:common.Update Failed') - }); + { + onSuccess() { + refetchDatasetTraining(); + loadDatasetDetail(datasetId); + }, + successToast: t('dataset:rebuild_embedding_start_tip'), + errorToast: t('common:common.Update Failed') + } + ); - const { runAsync: onEditBaseInfo } = useRequest2((data) => updateDataset(data), { - manual: true, + const { runAsync: onEditBaseInfo } = useRequest2(updateDataset, { + onSuccess() { + setEditedDataset(undefined); + }, successToast: t('common:common.Update Success'), errorToast: t('common:common.Update Failed') }); - const totalLoading = isSelecting || isSaving || isRebuilding; - return ( @@ -225,7 +240,7 @@ const Info = ({ datasetId }: { datasetId: string }) => { if (!vectorModel) return; return onOpenConfirmRebuild(() => { setValue('vectorModel', vectorModel); - onRebuilding(vectorModel); + return onRebuilding(vectorModel); })(); }} /> @@ -260,7 +275,6 @@ const Info = ({ datasetId }: { datasetId: string }) => { setValue('agentModel', agentModel); return handleSubmit((data) => onSave({ ...data, agentModel: agentModel }))(); }} - isDisabled={totalLoading} /> @@ -311,7 +325,6 @@ const Info = ({ datasetId }: { datasetId: string }) => { fontSize={'mini'} per={defaultPermission} defaultPer={DatasetDefaultPermissionVal} - isDisabled={totalLoading} onChange={(v) => { setValue('defaultPermission', v); return handleSubmit((data) => onSave({ ...data, defaultPermission: v }))(); @@ -349,18 +362,15 @@ const Info = ({ datasetId }: { datasetId: string }) => { { - setEditedDataset(undefined); - }} - onEdit={async (data) => { - await onEditBaseInfo({ + onClose={() => setEditedDataset(undefined)} + onEdit={(data) => + onEditBaseInfo({ id: editedDataset.id, name: data.name, intro: data.intro, avatar: data.avatar - }); - setEditedDataset(undefined); - }} + }) + } /> )} diff --git a/projects/app/src/pages/dataset/detail/components/NavBar.tsx b/projects/app/src/pages/dataset/detail/components/NavBar.tsx index fb4c328e3..4fd981e5c 100644 --- a/projects/app/src/pages/dataset/detail/components/NavBar.tsx +++ b/projects/app/src/pages/dataset/detail/components/NavBar.tsx @@ -115,7 +115,7 @@ const NavBar = ({ currentTab }: { currentTab: TabEnum }) => { w={'100%'} list={tabList} value={currentTab} - activatedColor="blue.700" + activeColor="primary.700" onChange={setCurrentTab} inlineStyles={{ fontSize: '1rem', @@ -193,7 +193,7 @@ const NavBar = ({ currentTab }: { currentTab: TabEnum }) => { ) : ( - + m={'auto'} w={'full'} diff --git a/projects/app/src/pages/dataset/detail/components/Test.tsx b/projects/app/src/pages/dataset/detail/components/Test.tsx index 58c4768d1..a19ebf099 100644 --- a/projects/app/src/pages/dataset/detail/components/Test.tsx +++ b/projects/app/src/pages/dataset/detail/components/Test.tsx @@ -4,7 +4,7 @@ import { useDatasetStore } from '@/web/core/dataset/store/dataset'; import { useSearchTestStore, SearchTestStoreItemType } from '@/web/core/dataset/store/searchTest'; import { postSearchText } from '@/web/core/dataset/api'; import MyIcon from '@fastgpt/web/components/common/Icon'; -import { useRequest } from '@fastgpt/web/hooks/useRequest'; +import { useRequest, useRequest2 } from '@fastgpt/web/hooks/useRequest'; import { formatTimeToChatTime } from '@fastgpt/global/common/string/time'; import { getErrText } from '@fastgpt/global/common/error/utils'; import { useToast } from '@fastgpt/web/hooks/useToast'; @@ -48,7 +48,6 @@ type FormType = { const Test = ({ datasetId }: { datasetId: string }) => { const { t } = useTranslation(); - const theme = useTheme(); const { toast } = useToast(); const { llmModelList } = useSystemStore(); const datasetDetail = useContextSelector(DatasetPageContext, (v) => v.datasetDetail); @@ -86,40 +85,42 @@ const Test = ({ datasetId }: { datasetId: string }) => { onClose: onCloseSelectMode } = useDisclosure(); - const { mutate: onTextTest, isLoading: textTestIsLoading } = useRequest({ - mutationFn: ({ inputText, searchParams }: FormType) => + const { runAsync: onTextTest, loading: textTestIsLoading } = useRequest2( + ({ inputText, searchParams }: FormType) => postSearchText({ datasetId, text: inputText.trim(), ...searchParams }), - onSuccess(res: SearchTestResponse) { - if (!res || res.list.length === 0) { - return toast({ - status: 'warning', - title: t('common:dataset.test.noResult') + { + onSuccess(res: SearchTestResponse) { + if (!res || res.list.length === 0) { + return toast({ + status: 'warning', + title: t('common:dataset.test.noResult') + }); + } + + const testItem: SearchTestStoreItemType = { + id: nanoid(), + datasetId, + text: getValues('inputText').trim(), + time: new Date(), + results: res.list, + duration: res.duration, + searchMode: res.searchMode, + usingReRank: res.usingReRank, + limit: res.limit, + similarity: res.similarity, + queryExtensionModel: res.queryExtensionModel + }; + pushDatasetTestItem(testItem); + setDatasetTestItem(testItem); + }, + onError(err) { + toast({ + title: getErrText(err), + status: 'error' }); } - - const testItem: SearchTestStoreItemType = { - id: nanoid(), - datasetId, - text: getValues('inputText').trim(), - time: new Date(), - results: res.list, - duration: res.duration, - searchMode: res.searchMode, - usingReRank: res.usingReRank, - limit: res.limit, - similarity: res.similarity, - queryExtensionModel: res.queryExtensionModel - }; - pushDatasetTestItem(testItem); - setDatasetTestItem(testItem); - }, - onError(err) { - toast({ - title: getErrText(err), - status: 'error' - }); } - }); + ); const onSelectFile = async (files: File[]) => { const file = files[0]; @@ -329,6 +330,7 @@ const TestHistories = React.memo(function TestHistories({ () => datasetTestList.filter((item) => item.datasetId === datasetId), [datasetId, datasetTestList] ); + return ( <> diff --git a/projects/app/src/pages/dataset/detail/index.tsx b/projects/app/src/pages/dataset/detail/index.tsx index 072cf7825..fa9ea4fb3 100644 --- a/projects/app/src/pages/dataset/detail/index.tsx +++ b/projects/app/src/pages/dataset/detail/index.tsx @@ -1,8 +1,7 @@ import React from 'react'; import { useRouter } from 'next/router'; -import { Box, Flex } from '@chakra-ui/react'; +import { Box, Flex, FlexProps } from '@chakra-ui/react'; import { useToast } from '@fastgpt/web/hooks/useToast'; -import { useQuery } from '@tanstack/react-query'; import { getErrText } from '@fastgpt/global/common/error/utils'; import dynamic from 'next/dynamic'; import PageContainer from '@/components/PageContainer'; @@ -36,6 +35,13 @@ export enum TabEnum { } type Props = { datasetId: string; currentTab: TabEnum }; +const sliderStyles: FlexProps = { + bg: 'white', + borderRadius: 'md', + overflowY: 'scroll', + boxShadow: 2 +}; + const Detail = ({ datasetId, currentTab }: Props) => { const { t } = useTranslation(); const { toast } = useToast(); @@ -64,20 +70,10 @@ const Detail = ({ datasetId, currentTab }: Props) => { {isPc ? ( - - + + {currentTab !== TabEnum.import && } - + {currentTab === TabEnum.collectionCard && ( @@ -88,27 +84,24 @@ const Detail = ({ datasetId, currentTab }: Props) => { {currentTab === TabEnum.import && } - {currentTab !== TabEnum.import && ( - - {currentTab === TabEnum.dataCard ? ( + + {/* Slider */} + <> + {currentTab === TabEnum.dataCard && ( + - ) : ( + + )} + {[TabEnum.collectionCard, TabEnum.test].includes(currentTab) && ( + - )} - - )} + + )} + ) : ( - + {!!datasetDetail._id && ( diff --git a/projects/app/src/web/core/dataset/api.ts b/projects/app/src/web/core/dataset/api.ts index c881601c2..81d758d0d 100644 --- a/projects/app/src/web/core/dataset/api.ts +++ b/projects/app/src/web/core/dataset/api.ts @@ -120,7 +120,7 @@ export const putDatasetCollectionById = (data: UpdateDatasetCollectionParams) => export const delDatasetCollectionById = (params: { id: string }) => DELETE(`/core/dataset/collection/delete`, params); export const postLinkCollectionSync = (collectionId: string) => - POST<`${DatasetCollectionSyncResultEnum}`>(`/core/dataset/collection/sync/link`, { + POST(`/core/dataset/collection/sync/link`, { collectionId });