mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-28 09:03:53 +00:00
4.8.10 test (#2568)
* perf: i18n perf * fix: detail=fasle response * fix: dataset tag load repeat * feat :doc * perf: rename fun * code comment
This commit is contained in:
@@ -19,10 +19,8 @@ import { useQuery } from '@tanstack/react-query';
|
||||
import { getPromotionInitData, getPromotionRecords } from '@/web/support/activity/promotion/api';
|
||||
import { useUserStore } from '@/web/support/user/useUserStore';
|
||||
|
||||
import MyTooltip from '@fastgpt/web/components/common/MyTooltip';
|
||||
import { useCopyData } from '@/web/common/hooks/useCopyData';
|
||||
import type { PromotionRecordType } from '@/global/support/api/userRes.d';
|
||||
import MyIcon from '@fastgpt/web/components/common/Icon';
|
||||
import dayjs from 'dayjs';
|
||||
import { usePagination } from '@fastgpt/web/hooks/usePagination';
|
||||
import { useLoading } from '@fastgpt/web/hooks/useLoading';
|
||||
@@ -116,7 +114,7 @@ const Promotion = () => {
|
||||
<Td>
|
||||
{item.createTime ? dayjs(item.createTime).format('YYYY/MM/DD HH:mm:ss') : '-'}
|
||||
</Td>
|
||||
<Td>{t(`user.promotion.${item.type}` as any)}</Td>
|
||||
<Td>{t(`user:promotion.${item.type}` as any)}</Td>
|
||||
<Td>{item.amount}</Td>
|
||||
</Tr>
|
||||
))}
|
||||
|
@@ -2,13 +2,11 @@ import type { NextApiRequest, NextApiResponse } from 'next';
|
||||
import { jsonRes } from '@fastgpt/service/common/response';
|
||||
import { connectToDatabase } from '@/service/mongo';
|
||||
import { authCert } from '@fastgpt/service/support/permission/auth/common';
|
||||
import { MongoDataset } from '@fastgpt/service/core/dataset/schema';
|
||||
import { DatasetDefaultPermissionVal } from '@fastgpt/global/support/permission/dataset/constant';
|
||||
import { MongoAppVersion } from '@fastgpt/service/core/app/version/schema';
|
||||
import { FastGPTProUrl } from '@fastgpt/service/common/system/constants';
|
||||
import { POST } from '@fastgpt/service/common/api/plusRequest';
|
||||
|
||||
/* pg 中的数据搬到 mongo dataset.datas 中,并做映射 */
|
||||
/* 初始化发布的版本 */
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
try {
|
||||
await connectToDatabase();
|
||||
|
@@ -30,7 +30,11 @@ async function handler(req: NextApiRequest, res: NextApiResponse<any>) {
|
||||
});
|
||||
const { file, bucketName, metadata } = await upload.doUpload(req, res);
|
||||
filePaths.push(file.path);
|
||||
const { teamId, tmbId, outLinkUid } = await authChatCert({ req, authToken: true });
|
||||
const { teamId, tmbId, outLinkUid } = await authChatCert({
|
||||
req,
|
||||
authToken: true,
|
||||
authApiKey: true
|
||||
});
|
||||
|
||||
await authUploadLimit(outLinkUid || tmbId);
|
||||
|
||||
|
@@ -368,6 +368,14 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
if (assistantResponses.length === 0) return '';
|
||||
if (assistantResponses.length === 1 && assistantResponses[0].text?.content)
|
||||
return assistantResponses[0].text?.content;
|
||||
|
||||
if (!detail) {
|
||||
return assistantResponses
|
||||
.map((item) => item?.text?.content)
|
||||
.filter(Boolean)
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
return assistantResponses;
|
||||
})();
|
||||
|
||||
|
@@ -125,7 +125,7 @@ const Header = ({}: {}) => {
|
||||
return (
|
||||
<Box display={['block', 'flex']} alignItems={'center'} gap={2}>
|
||||
<HStack flex={1}>
|
||||
<Box flex={1} fontWeight={'500'} color={'myGray.900'}>
|
||||
<Box flex={1} fontWeight={'500'} color={'myGray.900'} whiteSpace={'nowrap'}>
|
||||
<ParentPath
|
||||
paths={paths.map((path, i) => ({
|
||||
parentId: path.parentId,
|
||||
@@ -173,7 +173,8 @@ const Header = ({}: {}) => {
|
||||
{/* search input */}
|
||||
{isPc && (
|
||||
<MyInput
|
||||
w={['100%', '250px']}
|
||||
maxW={'250px'}
|
||||
flex={1}
|
||||
size={'sm'}
|
||||
h={'36px'}
|
||||
placeholder={t('common:common.Search') || ''}
|
||||
|
@@ -2,12 +2,10 @@ import { Box, Button, Checkbox, Flex, Input, useDisclosure } from '@chakra-ui/re
|
||||
import MyPopover from '@fastgpt/web/components/common/MyPopover';
|
||||
import MyIcon from '@fastgpt/web/components/common/Icon';
|
||||
import MyBox from '@fastgpt/web/components/common/MyBox';
|
||||
import { postCreateDatasetCollectionTag } from '@/web/core/dataset/api';
|
||||
import { useContextSelector } from 'use-context-selector';
|
||||
import { DatasetPageContext } from '@/web/core/dataset/context/datasetPageContext';
|
||||
import { useTranslation } from 'next-i18next';
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import { useRequest } from '@fastgpt/web/hooks/useRequest';
|
||||
import { useCallback, useState } from 'react';
|
||||
import { CollectionPageContext } from './Context';
|
||||
import { debounce, isEqual } from 'lodash';
|
||||
import TagManageModal from './TagManageModal';
|
||||
@@ -15,27 +13,17 @@ import { DatasetTagType } from '@fastgpt/global/core/dataset/type';
|
||||
|
||||
const HeaderTagPopOver = () => {
|
||||
const { t } = useTranslation();
|
||||
const [searchTag, setSearchTag] = useState('');
|
||||
const [checkedTags, setCheckedTags] = useState<string[]>([]);
|
||||
|
||||
const { datasetDetail, datasetTags, loadDatasetTags, checkedDatasetTag, setCheckedDatasetTag } =
|
||||
useContextSelector(DatasetPageContext, (v) => v);
|
||||
|
||||
const { mutate: onCreateCollectionTag, isLoading: isCreateCollectionTagLoading } = useRequest({
|
||||
mutationFn: async (tag: string) => {
|
||||
const id = await postCreateDatasetCollectionTag({
|
||||
datasetId: datasetDetail._id,
|
||||
tag
|
||||
});
|
||||
return id;
|
||||
},
|
||||
|
||||
onSuccess() {
|
||||
setSearchTag('');
|
||||
},
|
||||
successToast: t('common:common.Create Success'),
|
||||
errorToast: t('common:common.Create Failed')
|
||||
});
|
||||
const {
|
||||
searchDatasetTagsResult,
|
||||
searchTagKey,
|
||||
setSearchTagKey,
|
||||
checkedDatasetTag,
|
||||
setCheckedDatasetTag,
|
||||
onCreateCollectionTag,
|
||||
isCreateCollectionTagLoading
|
||||
} = useContextSelector(DatasetPageContext, (v) => v);
|
||||
|
||||
const { filterTags, setFilterTags, getData } = useContextSelector(
|
||||
CollectionPageContext,
|
||||
@@ -48,10 +36,6 @@ const HeaderTagPopOver = () => {
|
||||
[]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
loadDatasetTags({ id: datasetDetail._id, searchKey: searchTag });
|
||||
}, [searchTag]);
|
||||
|
||||
const {
|
||||
isOpen: isTagManageModalOpen,
|
||||
onOpen: onOpenTagManageModal,
|
||||
@@ -122,35 +106,34 @@ const HeaderTagPopOver = () => {
|
||||
pl={2}
|
||||
h={8}
|
||||
borderRadius={'xs'}
|
||||
value={searchTag}
|
||||
value={searchTagKey}
|
||||
placeholder={t('dataset:tag.searchOrAddTag')}
|
||||
onChange={(e) => setSearchTag(e.target.value)}
|
||||
onChange={(e) => setSearchTagKey(e.target.value)}
|
||||
/>
|
||||
</Box>
|
||||
|
||||
<Box my={1} px={1.5} maxH={'240px'} overflow={'auto'}>
|
||||
{searchTag && !datasetTags.map((item) => item.tag).includes(searchTag) && (
|
||||
<Flex
|
||||
alignItems={'center'}
|
||||
fontSize={'sm'}
|
||||
px={1}
|
||||
cursor={'pointer'}
|
||||
_hover={{ bg: '#1118240D', color: 'primary.700' }}
|
||||
borderRadius={'xs'}
|
||||
onClick={() => {
|
||||
onCreateCollectionTag(searchTag);
|
||||
}}
|
||||
>
|
||||
<MyIcon name={'common/addLight'} w={'16px'} />
|
||||
<Box ml={2} py={2}>
|
||||
{t('dataset:tag.add') + ` "${searchTag}"`}
|
||||
</Box>
|
||||
</Flex>
|
||||
)}
|
||||
{searchTagKey &&
|
||||
!searchDatasetTagsResult.map((item) => item.tag).includes(searchTagKey) && (
|
||||
<Flex
|
||||
alignItems={'center'}
|
||||
fontSize={'sm'}
|
||||
px={1}
|
||||
cursor={'pointer'}
|
||||
_hover={{ bg: '#1118240D', color: 'primary.700' }}
|
||||
borderRadius={'xs'}
|
||||
onClick={() => onCreateCollectionTag(searchTagKey)}
|
||||
>
|
||||
<MyIcon name={'common/addLight'} w={'16px'} />
|
||||
<Box ml={2} py={2}>
|
||||
{t('dataset:tag.add') + ` "${searchTagKey}"`}
|
||||
</Box>
|
||||
</Flex>
|
||||
)}
|
||||
|
||||
{[
|
||||
...new Map(
|
||||
[...checkedDatasetTag, ...datasetTags].map((item) => [item._id, item])
|
||||
[...checkedDatasetTag, ...searchDatasetTagsResult].map((item) => [item._id, item])
|
||||
).values()
|
||||
].map((item) => {
|
||||
const checked = checkedTags.includes(item._id);
|
||||
@@ -197,6 +180,7 @@ const HeaderTagPopOver = () => {
|
||||
borderBottomLeftRadius={'md'}
|
||||
variant={'unstyled'}
|
||||
onClick={() => {
|
||||
setSearchTagKey('');
|
||||
setCheckedTags([]);
|
||||
setFilterTags([]);
|
||||
debounceRefetch();
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { Input, Button, Flex, Box, Checkbox, BoxProps } from '@chakra-ui/react';
|
||||
import React, { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { Input, Button, Flex, Box, Checkbox } from '@chakra-ui/react';
|
||||
import MyModal from '@fastgpt/web/components/common/MyModal';
|
||||
import { useTranslation } from 'next-i18next';
|
||||
import MyIcon from '@fastgpt/web/components/common/Icon';
|
||||
@@ -13,10 +13,9 @@ import {
|
||||
getScrollCollectionList,
|
||||
getTagUsage,
|
||||
postAddTagsToCollections,
|
||||
postCreateDatasetCollectionTag,
|
||||
updateDatasetCollectionTag
|
||||
} from '@/web/core/dataset/api';
|
||||
import { useRequest, useRequest2 } from '@fastgpt/web/hooks/useRequest';
|
||||
import { useRequest2 } from '@fastgpt/web/hooks/useRequest';
|
||||
import MyInput from '@/components/MyInput';
|
||||
import { DatasetTagType } from '@fastgpt/global/core/dataset/type';
|
||||
import { ScrollListType, useScrollPagination } from '@fastgpt/web/hooks/useScrollPagination';
|
||||
@@ -26,9 +25,13 @@ import { DatasetCollectionsListItemType } from '@/global/core/dataset/type';
|
||||
|
||||
const TagManageModal = ({ onClose }: { onClose: () => void }) => {
|
||||
const { t } = useTranslation();
|
||||
const datasetDetail = useContextSelector(DatasetPageContext, (v) => v.datasetDetail);
|
||||
const loadDatasetTags = useContextSelector(DatasetPageContext, (v) => v.loadDatasetTags);
|
||||
const loadAllDatasetTags = useContextSelector(DatasetPageContext, (v) => v.loadAllDatasetTags);
|
||||
const {
|
||||
datasetDetail,
|
||||
onCreateCollectionTag,
|
||||
isCreateCollectionTagLoading,
|
||||
loadAllDatasetTags,
|
||||
setSearchTagKey
|
||||
} = useContextSelector(DatasetPageContext, (v) => v);
|
||||
const { getData, pageNum, collections } = useContextSelector(CollectionPageContext, (v) => v);
|
||||
|
||||
const tagInputRef = useRef<HTMLInputElement>(null);
|
||||
@@ -56,36 +59,17 @@ const TagManageModal = ({ onClose }: { onClose: () => void }) => {
|
||||
}
|
||||
}, [currentEditTag]);
|
||||
|
||||
const { mutate: onCreateCollectionTag, isLoading: isCreateCollectionTagLoading } = useRequest({
|
||||
mutationFn: async (tag: string) => {
|
||||
const id = await postCreateDatasetCollectionTag({
|
||||
datasetId: datasetDetail._id,
|
||||
tag
|
||||
});
|
||||
return id;
|
||||
},
|
||||
|
||||
onSuccess() {
|
||||
fetchData(1);
|
||||
loadDatasetTags({ id: datasetDetail._id, searchKey: '' });
|
||||
loadAllDatasetTags({ id: datasetDetail._id });
|
||||
},
|
||||
successToast: t('common:common.Create Success'),
|
||||
errorToast: t('common:common.Create Failed')
|
||||
});
|
||||
|
||||
const { runAsync: onDeleteCollectionTag, loading: isDeleteCollectionTagLoading } = useRequest2(
|
||||
(tag: string) => {
|
||||
return delDatasetCollectionTag({
|
||||
(tag: string) =>
|
||||
delDatasetCollectionTag({
|
||||
datasetId: datasetDetail._id,
|
||||
id: tag
|
||||
});
|
||||
},
|
||||
}),
|
||||
{
|
||||
onSuccess() {
|
||||
fetchData(1);
|
||||
loadDatasetTags({ id: datasetDetail._id, searchKey: '' });
|
||||
loadAllDatasetTags({ id: datasetDetail._id });
|
||||
setSearchTagKey('');
|
||||
loadAllDatasetTags();
|
||||
},
|
||||
successToast: t('common:common.Delete Success'),
|
||||
errorToast: t('common:common.Delete Failed')
|
||||
@@ -103,8 +87,8 @@ const TagManageModal = ({ onClose }: { onClose: () => void }) => {
|
||||
{
|
||||
onSuccess() {
|
||||
fetchData(1);
|
||||
loadDatasetTags({ id: datasetDetail._id, searchKey: '' });
|
||||
loadAllDatasetTags({ id: datasetDetail._id });
|
||||
setSearchTagKey('');
|
||||
loadAllDatasetTags();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
@@ -2,12 +2,11 @@ import { Box, Checkbox, Flex, Input } from '@chakra-ui/react';
|
||||
import MyPopover from '@fastgpt/web/components/common/MyPopover';
|
||||
import MyIcon from '@fastgpt/web/components/common/Icon';
|
||||
import MyBox from '@fastgpt/web/components/common/MyBox';
|
||||
import { postCreateDatasetCollectionTag, putDatasetCollectionById } from '@/web/core/dataset/api';
|
||||
import { putDatasetCollectionById } from '@/web/core/dataset/api';
|
||||
import { useContextSelector } from 'use-context-selector';
|
||||
import { DatasetPageContext } from '@/web/core/dataset/context/datasetPageContext';
|
||||
import { useTranslation } from 'next-i18next';
|
||||
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { useRequest } from '@fastgpt/web/hooks/useRequest';
|
||||
import { useMemo, useRef, useState } from 'react';
|
||||
import { useDeepCompareEffect } from 'ahooks';
|
||||
import { DatasetCollectionItemType, DatasetTagType } from '@fastgpt/global/core/dataset/type';
|
||||
import { isEqual } from 'lodash';
|
||||
@@ -19,25 +18,20 @@ const TagsPopOver = ({
|
||||
currentCollection: DatasetCollectionItemType | DatasetCollectionsListItemType;
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const datasetDetail = useContextSelector(DatasetPageContext, (v) => v.datasetDetail);
|
||||
const datasetTags = useContextSelector(DatasetPageContext, (v) => v.datasetTags);
|
||||
const loadDatasetTags = useContextSelector(DatasetPageContext, (v) => v.loadDatasetTags);
|
||||
const allDatasetTags = useContextSelector(DatasetPageContext, (v) => v.allDatasetTags);
|
||||
const loadAllDatasetTags = useContextSelector(DatasetPageContext, (v) => v.loadAllDatasetTags);
|
||||
const {
|
||||
searchTagKey,
|
||||
setSearchTagKey,
|
||||
searchDatasetTagsResult,
|
||||
allDatasetTags,
|
||||
onCreateCollectionTag,
|
||||
isCreateCollectionTagLoading
|
||||
} = useContextSelector(DatasetPageContext, (v) => v);
|
||||
|
||||
const [collectionTags, setCollectionTags] = useState<string[]>([]);
|
||||
const [searchTag, setSearchTag] = useState('');
|
||||
const [collectionTags, setCollectionTags] = useState<string[]>(currentCollection.tags ?? []);
|
||||
const [checkedTags, setCheckedTags] = useState<DatasetTagType[]>([]);
|
||||
|
||||
const [showTagManage, setShowTagManage] = useState(false);
|
||||
const [isFocusInput, setIsFocusInput] = useState(false);
|
||||
const [isUpdateLoading, setIsUpdateLoading] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (!currentCollection.tags) return;
|
||||
setCollectionTags(currentCollection.tags);
|
||||
}, [currentCollection]);
|
||||
|
||||
const tagList = useMemo(
|
||||
() =>
|
||||
(collectionTags
|
||||
@@ -52,12 +46,6 @@ const TagsPopOver = ({
|
||||
[collectionTags, allDatasetTags]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isFocusInput) return;
|
||||
loadDatasetTags({ id: datasetDetail._id, searchKey: searchTag });
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [datasetDetail._id, isFocusInput, searchTag]);
|
||||
|
||||
const [visibleTags, setVisibleTags] = useState<DatasetTagType[]>(tagList);
|
||||
const [overflowTags, setOverflowTags] = useState<DatasetTagType[]>([]);
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
@@ -96,24 +84,6 @@ const TagsPopOver = ({
|
||||
};
|
||||
}, [tagList]);
|
||||
|
||||
const { mutate: onCreateCollectionTag, isLoading: isCreateCollectionTagLoading } = useRequest({
|
||||
mutationFn: async (tag: string) => {
|
||||
const id = await postCreateDatasetCollectionTag({
|
||||
datasetId: datasetDetail._id,
|
||||
tag
|
||||
});
|
||||
return id;
|
||||
},
|
||||
|
||||
onSuccess() {
|
||||
setSearchTag('');
|
||||
loadDatasetTags({ id: datasetDetail._id, searchKey: '' });
|
||||
loadAllDatasetTags({ id: datasetDetail._id });
|
||||
},
|
||||
successToast: t('common:common.Create Success'),
|
||||
errorToast: t('common:common.Create Failed')
|
||||
});
|
||||
|
||||
return (
|
||||
<MyPopover
|
||||
placement={showTagManage ? 'bottom' : 'bottom-end'}
|
||||
@@ -176,6 +146,8 @@ const TagsPopOver = ({
|
||||
</MyBox>
|
||||
}
|
||||
onCloseFunc={async () => {
|
||||
setSearchTagKey('');
|
||||
|
||||
setShowTagManage(false);
|
||||
if (isEqual(checkedTags, tagList) || !showTagManage) return;
|
||||
setIsUpdateLoading(true);
|
||||
@@ -194,36 +166,33 @@ const TagsPopOver = ({
|
||||
<MyBox isLoading={isCreateCollectionTagLoading} onClick={(e) => e.stopPropagation()}>
|
||||
<Box px={1.5} pt={1.5}>
|
||||
<Input
|
||||
onFocus={() => setIsFocusInput(true)}
|
||||
onBlur={() => setIsFocusInput(false)}
|
||||
pl={2}
|
||||
h={7}
|
||||
borderRadius={'xs'}
|
||||
value={searchTag}
|
||||
value={searchTagKey}
|
||||
placeholder={t('dataset:tag.searchOrAddTag')}
|
||||
onChange={(e) => setSearchTag(e.target.value)}
|
||||
onChange={(e) => setSearchTagKey(e.target.value)}
|
||||
/>
|
||||
</Box>
|
||||
<Box my={1} px={1.5} maxH={'200px'} overflow={'auto'}>
|
||||
{searchTag && !datasetTags.map((item) => item.tag).includes(searchTag) && (
|
||||
<Flex
|
||||
alignItems={'center'}
|
||||
fontSize={'xs'}
|
||||
px={1}
|
||||
cursor={'pointer'}
|
||||
_hover={{ bg: '#1118240D', color: '#2B5FD9' }}
|
||||
borderRadius={'xs'}
|
||||
onClick={() => {
|
||||
onCreateCollectionTag(searchTag);
|
||||
}}
|
||||
>
|
||||
<MyIcon name={'common/addLight'} w={'16px'} />
|
||||
<Box ml={1} py={1}>
|
||||
{t('dataset:tag.add') + ` "${searchTag}"`}
|
||||
</Box>
|
||||
</Flex>
|
||||
)}
|
||||
{datasetTags?.map((item) => {
|
||||
{searchTagKey &&
|
||||
!searchDatasetTagsResult.map((item) => item.tag).includes(searchTagKey) && (
|
||||
<Flex
|
||||
alignItems={'center'}
|
||||
fontSize={'xs'}
|
||||
px={1}
|
||||
cursor={'pointer'}
|
||||
_hover={{ bg: '#1118240D', color: '#2B5FD9' }}
|
||||
borderRadius={'xs'}
|
||||
onClick={() => onCreateCollectionTag(searchTagKey)}
|
||||
>
|
||||
<MyIcon name={'common/addLight'} w={'1rem'} />
|
||||
<Box ml={1} py={1}>
|
||||
{t('dataset:tag.add') + ` "${searchTagKey}"`}
|
||||
</Box>
|
||||
</Flex>
|
||||
)}
|
||||
{searchDatasetTagsResult?.map((item) => {
|
||||
const tagsList = checkedTags.map((tag) => tag.tag);
|
||||
return (
|
||||
<Flex
|
||||
|
@@ -49,12 +49,8 @@ const Detail = ({ datasetId, currentTab }: Props) => {
|
||||
const { isPc } = useSystem();
|
||||
const datasetDetail = useContextSelector(DatasetPageContext, (v) => v.datasetDetail);
|
||||
const loadDatasetDetail = useContextSelector(DatasetPageContext, (v) => v.loadDatasetDetail);
|
||||
const loadAllDatasetTags = useContextSelector(DatasetPageContext, (v) => v.loadAllDatasetTags);
|
||||
|
||||
useRequest2(() => loadDatasetDetail(datasetId), {
|
||||
onSuccess: () => {
|
||||
loadAllDatasetTags({ id: datasetId });
|
||||
},
|
||||
onError(err: any) {
|
||||
router.replace(`/dataset/list`);
|
||||
toast({
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { ReactNode, SetStateAction, useMemo, useState } from 'react';
|
||||
import { Dispatch, ReactNode, SetStateAction, useEffect, useMemo, useState } from 'react';
|
||||
import { useTranslation } from 'next-i18next';
|
||||
import { createContext } from 'use-context-selector';
|
||||
import {
|
||||
@@ -8,24 +8,30 @@ import {
|
||||
getDatasetCollectionTags,
|
||||
getDatasetTrainingQueue,
|
||||
getTrainingQueueLen,
|
||||
postCreateDatasetCollectionTag,
|
||||
putDatasetById
|
||||
} from '../api';
|
||||
import { defaultDatasetDetail } from '../constants';
|
||||
import { DatasetUpdateBody } from '@fastgpt/global/core/dataset/api';
|
||||
import { DatasetItemType, DatasetTagType } from '@fastgpt/global/core/dataset/type';
|
||||
import { useSystemStore } from '@/web/common/system/useSystemStore';
|
||||
import { useRequest2 } from '@fastgpt/web/hooks/useRequest';
|
||||
|
||||
type DatasetPageContextType = {
|
||||
datasetId: string;
|
||||
datasetDetail: DatasetItemType;
|
||||
loadDatasetDetail: (id: string) => Promise<DatasetItemType>;
|
||||
updateDataset: (data: DatasetUpdateBody) => Promise<void>;
|
||||
datasetTags: DatasetTagType[];
|
||||
loadDatasetTags: (data: { id: string; searchKey: string }) => Promise<void>;
|
||||
|
||||
searchDatasetTagsResult: DatasetTagType[];
|
||||
allDatasetTags: DatasetTagType[];
|
||||
loadAllDatasetTags: (data: { id: string }) => Promise<void>;
|
||||
loadAllDatasetTags: () => Promise<DatasetTagType[]>;
|
||||
checkedDatasetTag: DatasetTagType[];
|
||||
setCheckedDatasetTag: React.Dispatch<SetStateAction<DatasetTagType[]>>;
|
||||
onCreateCollectionTag: (tag: string) => Promise<void>;
|
||||
isCreateCollectionTagLoading: boolean;
|
||||
searchTagKey: string;
|
||||
setSearchTagKey: Dispatch<SetStateAction<string>>;
|
||||
|
||||
vectorTrainingMap: {
|
||||
colorSchema: string;
|
||||
@@ -62,17 +68,22 @@ export const DatasetPageContext = createContext<DatasetPageContextType>({
|
||||
updateDataset: function (data: DatasetUpdateBody): Promise<void> {
|
||||
throw new Error('Function not implemented.');
|
||||
},
|
||||
datasetTags: [],
|
||||
loadDatasetTags: function (data: { id: string; searchKey: string }): Promise<void> {
|
||||
throw new Error('Function not implemented.');
|
||||
},
|
||||
searchDatasetTagsResult: [],
|
||||
allDatasetTags: [],
|
||||
loadAllDatasetTags: function (data: { id: string }): Promise<void> {
|
||||
throw new Error('Function not implemented.');
|
||||
},
|
||||
checkedDatasetTag: [],
|
||||
setCheckedDatasetTag: function (): void {
|
||||
throw new Error('Function not implemented.');
|
||||
},
|
||||
loadAllDatasetTags: function (): Promise<DatasetTagType[]> {
|
||||
throw new Error('Function not implemented.');
|
||||
},
|
||||
onCreateCollectionTag: function (tag: string): Promise<void> {
|
||||
throw new Error('Function not implemented.');
|
||||
},
|
||||
isCreateCollectionTagLoading: false,
|
||||
searchTagKey: '',
|
||||
setSearchTagKey: function (value: SetStateAction<string>): void {
|
||||
throw new Error('Function not implemented.');
|
||||
}
|
||||
});
|
||||
|
||||
@@ -108,28 +119,53 @@ export const DatasetPageContextProvider = ({
|
||||
};
|
||||
|
||||
// dataset tags
|
||||
const [datasetTags, setDatasetTags] = useState<DatasetTagType[]>([]);
|
||||
|
||||
const loadDatasetTags = async ({ id, searchKey }: { id: string; searchKey: string }) => {
|
||||
const { list } = await getDatasetCollectionTags({
|
||||
datasetId: id,
|
||||
searchText: searchKey,
|
||||
current: 1,
|
||||
pageSize: 15
|
||||
});
|
||||
setDatasetTags(list);
|
||||
};
|
||||
|
||||
const [checkedDatasetTag, setCheckedDatasetTag] = useState<DatasetTagType[]>([]);
|
||||
const [searchTagKey, setSearchTagKey] = useState('');
|
||||
|
||||
const [allDatasetTags, setAllDatasetTags] = useState<DatasetTagType[]>([]);
|
||||
const { runAsync: loadAllDatasetTags, data: allDatasetTags = [] } = useRequest2(
|
||||
async () => {
|
||||
if (!feConfigs?.isPlus || !datasetDetail._id) return [];
|
||||
|
||||
const loadAllDatasetTags = async ({ id }: { id: string }) => {
|
||||
if (!feConfigs?.isPlus) return;
|
||||
|
||||
const { list } = await getAllTags(id);
|
||||
setAllDatasetTags(list);
|
||||
};
|
||||
const { list } = await getAllTags(datasetDetail._id);
|
||||
return list;
|
||||
},
|
||||
{
|
||||
manual: false,
|
||||
refreshDeps: [datasetDetail._id]
|
||||
}
|
||||
);
|
||||
const { data: searchDatasetTagsResult = [] } = useRequest2(
|
||||
async () => {
|
||||
if (!searchTagKey) return allDatasetTags;
|
||||
const { list } = await getDatasetCollectionTags({
|
||||
datasetId: datasetDetail._id,
|
||||
searchText: searchTagKey,
|
||||
current: 1,
|
||||
pageSize: 15
|
||||
});
|
||||
return list;
|
||||
},
|
||||
{
|
||||
manual: false,
|
||||
throttleWait: 300,
|
||||
refreshDeps: [datasetDetail._id, searchTagKey, allDatasetTags]
|
||||
}
|
||||
);
|
||||
const { runAsync: onCreateCollectionTag, loading: isCreateCollectionTagLoading } = useRequest2(
|
||||
(tag: string) =>
|
||||
postCreateDatasetCollectionTag({
|
||||
datasetId: datasetDetail._id,
|
||||
tag
|
||||
}),
|
||||
{
|
||||
refreshDeps: [datasetDetail._id],
|
||||
onSuccess() {
|
||||
loadAllDatasetTags();
|
||||
},
|
||||
successToast: t('common:common.Create Success'),
|
||||
errorToast: t('common:common.Create Failed')
|
||||
}
|
||||
);
|
||||
|
||||
// global queue
|
||||
const { data: { vectorTrainingCount = 0, agentTrainingCount = 0 } = {} } = useQuery(
|
||||
@@ -199,12 +235,16 @@ export const DatasetPageContextProvider = ({
|
||||
rebuildingCount,
|
||||
trainingCount,
|
||||
refetchDatasetTraining,
|
||||
datasetTags,
|
||||
loadDatasetTags,
|
||||
|
||||
searchDatasetTagsResult,
|
||||
checkedDatasetTag,
|
||||
setCheckedDatasetTag,
|
||||
allDatasetTags,
|
||||
loadAllDatasetTags
|
||||
loadAllDatasetTags,
|
||||
onCreateCollectionTag,
|
||||
isCreateCollectionTagLoading,
|
||||
searchTagKey,
|
||||
setSearchTagKey
|
||||
};
|
||||
|
||||
return <DatasetPageContext.Provider value={contextValue}>{children}</DatasetPageContext.Provider>;
|
||||
|
Reference in New Issue
Block a user