11import React , { useCallback , useEffect , useMemo , useRef , useState } from 'react' ;
2- import { Box , Flex , Button , Textarea , useTheme } from '@chakra-ui/react' ;
2+ import { Box , Flex , Button , Textarea } from '@chakra-ui/react' ;
33import {
44 FieldArrayWithId ,
55 UseFieldArrayRemove ,
@@ -19,8 +19,7 @@ import MyModal from '@fastgpt/web/components/common/MyModal';
1919import MyTooltip from '@fastgpt/web/components/common/MyTooltip' ;
2020import { useQuery } from '@tanstack/react-query' ;
2121import { useTranslation } from 'next-i18next' ;
22- import { useRequest , useRequest2 } from '@fastgpt/web/hooks/useRequest' ;
23- import { useConfirm } from '@fastgpt/web/hooks/useConfirm' ;
22+ import { useRequest2 } from '@fastgpt/web/hooks/useRequest' ;
2423import { getSourceNameIcon } from '@fastgpt/global/core/dataset/utils' ;
2524import { DatasetDataIndexItemType } from '@fastgpt/global/core/dataset/type' ;
2625import DeleteIcon from '@fastgpt/web/components/common/Icon/delete' ;
@@ -30,10 +29,12 @@ import MyBox from '@fastgpt/web/components/common/MyBox';
3029import { getErrText } from '@fastgpt/global/common/error/utils' ;
3130import { useSystemStore } from '@/web/common/system/useSystemStore' ;
3231import QuestionTip from '@fastgpt/web/components/common/MyTooltip/QuestionTip' ;
33- import { useSystem } from '@fastgpt/web/hooks/useSystem' ;
3432import LightRowTabs from '@fastgpt/web/components/common/Tabs/LightRowTabs' ;
3533import styles from './styles.module.scss' ;
36- import { getDatasetIndexMapData } from '@fastgpt/global/core/dataset/data/constants' ;
34+ import {
35+ DatasetDataIndexTypeEnum ,
36+ getDatasetIndexMapData
37+ } from '@fastgpt/global/core/dataset/data/constants' ;
3738
3839export type InputDataType = {
3940 q : string ;
@@ -62,11 +63,10 @@ const InputDataModal = ({
6263 onSuccess : ( data : InputDataType & { dataId : string } ) => void ;
6364} ) => {
6465 const { t } = useTranslation ( ) ;
65- const theme = useTheme ( ) ;
6666 const { toast } = useToast ( ) ;
6767 const [ currentTab , setCurrentTab ] = useState ( TabEnum . content ) ;
6868 const { embeddingModelList, defaultModels } = useSystemStore ( ) ;
69- const { isPc } = useSystem ( ) ;
69+
7070 const { register, handleSubmit, reset, control } = useForm < InputDataType > ( ) ;
7171 const {
7272 fields : indexes ,
@@ -112,11 +112,6 @@ const InputDataModal = ({
112112 }
113113 ] ;
114114
115- const { ConfirmModal, openConfirm } = useConfirm ( {
116- content : t ( 'common:dataset.data.Delete Tip' ) ,
117- type : 'delete'
118- } ) ;
119-
120115 const { data : collection = defaultCollectionDetail } = useQuery (
121116 [ 'loadCollectionId' , collectionId ] ,
122117 ( ) => {
@@ -163,8 +158,8 @@ const InputDataModal = ({
163158 } , [ collection . dataset . vectorModel , defaultModels . embedding , embeddingModelList ] ) ;
164159
165160 // import new data
166- const { mutate : sureImportData , isLoading : isImporting } = useRequest ( {
167- mutationFn : async ( e : InputDataType ) => {
161+ const { runAsync : sureImportData , loading : isImporting } = useRequest2 (
162+ async ( e : InputDataType ) => {
168163 if ( ! e . q ) {
169164 setCurrentTab ( TabEnum . content ) ;
170165 return Promise . reject ( t ( 'common:dataset.data.input is empty' ) ) ;
@@ -181,31 +176,29 @@ const InputDataModal = ({
181176 collectionId : collection . _id ,
182177 q : e . q ,
183178 a : e . a ,
184- // remove dataId
185- indexes :
186- e . indexes ?. map ( ( index ) => ( {
187- ...index ,
188- dataId : undefined
189- } ) ) || [ ]
179+ // Contains no default index
180+ indexes : e . indexes
190181 } ) ;
191182
192183 return {
193184 ...data ,
194185 dataId
195186 } ;
196187 } ,
197- successToast : t ( 'common:dataset.data.Input Success Tip' ) ,
198- onSuccess ( e ) {
199- reset ( {
200- ...e ,
201- q : '' ,
202- a : '' ,
203- indexes : [ ]
204- } ) ;
205- onSuccess ( e ) ;
206- } ,
207- errorToast : t ( 'common:common.error.unKnow' )
208- } ) ;
188+ {
189+ successToast : t ( 'common:dataset.data.Input Success Tip' ) ,
190+ onSuccess ( e ) {
191+ reset ( {
192+ ...e ,
193+ q : '' ,
194+ a : '' ,
195+ indexes : [ ]
196+ } ) ;
197+ onSuccess ( e ) ;
198+ } ,
199+ errorToast : t ( 'common:common.error.unKnow' )
200+ }
201+ ) ;
209202
210203 // update
211204 const { runAsync : onUpdateData , loading : isUpdating } = useRequest2 (
@@ -239,6 +232,7 @@ const InputDataModal = ({
239232 ( ) => getSourceNameIcon ( { sourceName : collection . sourceName , sourceId : collection . sourceId } ) ,
240233 [ collection ]
241234 ) ;
235+
242236 return (
243237 < MyModal
244238 isOpen = { true }
@@ -291,9 +285,8 @@ const InputDataModal = ({
291285 p = { 0 }
292286 onClick = { ( ) =>
293287 appendIndexes ( {
294- type : 'custom' ,
295- text : '' ,
296- dataId : `${ Date . now ( ) } `
288+ type : DatasetDataIndexTypeEnum . custom ,
289+ text : ''
297290 } )
298291 }
299292 >
@@ -331,7 +324,6 @@ const InputDataModal = ({
331324 </ MyTooltip >
332325 </ Flex >
333326 </ MyBox >
334- < ConfirmModal />
335327 </ MyModal >
336328 ) ;
337329} ;
0 commit comments