File tree Expand file tree Collapse file tree 1 file changed +8
-13
lines changed
frontend/src/pages/DataManagement/Create Expand file tree Collapse file tree 1 file changed +8
-13
lines changed Original file line number Diff line number Diff line change @@ -29,26 +29,21 @@ export default function EditDataset({
2929 datasetType : DatasetType . TEXT ,
3030 tags : [ ] ,
3131 } ) ;
32- const fetchDataset = async ( ) => {
33- if ( ! open ) return ;
34- // 如果有id,说明是编辑模式
35- if ( data && data . id ) {
36- const { data : newData } = await queryDatasetByIdUsingGet ( data . id ) ;
32+
33+ // 当对话框打开时,使用传入的 data 初始化表单
34+ useEffect ( ( ) => {
35+ if ( open && data && data . id ) {
3736 const updatedDataset = {
38- ...newData ,
39- type : newData . type ,
40- tags : ( newData . tags || [ ] ) . map ( ( tag ) =>
37+ ...data ,
38+ type : data . type ,
39+ tags : ( data . tags || [ ] ) . map ( ( tag ) =>
4140 typeof tag === "string" ? tag : tag . name
4241 ) ,
4342 } ;
4443 setNewDataset ( updatedDataset ) ;
4544 form . setFieldsValue ( updatedDataset ) ;
4645 }
47- } ;
48-
49- useEffect ( ( ) => {
50- fetchDataset ( ) ;
51- } , [ data ] ) ;
46+ } , [ open , data , form ] ) ;
5247
5348 const handleValuesChange = ( _ , allValues ) => {
5449 setNewDataset ( { ...newDataset , ...allValues } ) ;
You can’t perform that action at this time.
0 commit comments