You've already forked DataMate
feat(dataset): 添加子数据集创建功能
- 在创建页面集成父数据集ID传递逻辑 - 使用useMemo缓存location状态中的parentDatasetId - 添加useEffect同步parentDatasetId到表单状态 - 实现handleCreateChildDataset函数用于导航到创建页面 - 在数据集详情页的操作菜单中添加"创建子数据集"选项 - 为子数据集创建按钮添加PlusOutlined图标 - 定义CreateDatasetLocationState接口规范传递参数类型
This commit is contained in:
@@ -1,24 +1,37 @@
|
||||
import { useState } from "react";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
|
||||
import { ArrowLeft } from "lucide-react";
|
||||
import { Button, Form, App } from "antd";
|
||||
import { Link, useNavigate } from "react-router";
|
||||
import { Link, useLocation, useNavigate } from "react-router";
|
||||
import { createDatasetUsingPost } from "../dataset.api";
|
||||
import { DatasetType } from "../dataset.model";
|
||||
import BasicInformation from "./components/BasicInformation";
|
||||
|
||||
export default function DatasetCreate() {
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
const { message } = App.useApp();
|
||||
const [form] = Form.useForm();
|
||||
|
||||
const [newDataset, setNewDataset] = useState({
|
||||
const parentDatasetId = useMemo(() => {
|
||||
const state = location.state as CreateDatasetLocationState | null;
|
||||
return state?.parentDatasetId || "";
|
||||
}, [location.state]);
|
||||
const [newDataset, setNewDataset] = useState(() => ({
|
||||
name: "",
|
||||
description: "",
|
||||
datasetType: DatasetType.TEXT,
|
||||
tags: [],
|
||||
parentDatasetId: "",
|
||||
});
|
||||
parentDatasetId,
|
||||
}));
|
||||
|
||||
useEffect(() => {
|
||||
if (!parentDatasetId) {
|
||||
return;
|
||||
}
|
||||
setNewDataset((prev) => ({ ...prev, parentDatasetId }));
|
||||
form.setFieldsValue({ parentDatasetId });
|
||||
}, [form, parentDatasetId]);
|
||||
|
||||
const handleSubmit = async () => {
|
||||
const formValues = await form.validateFields();
|
||||
@@ -39,7 +52,7 @@ export default function DatasetCreate() {
|
||||
};
|
||||
|
||||
const handleValuesChange = (_, allValues) => {
|
||||
setNewDataset({ ...newDataset, ...allValues });
|
||||
setNewDataset((prev) => ({ ...prev, ...allValues }));
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -82,3 +95,7 @@ export default function DatasetCreate() {
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
interface CreateDatasetLocationState {
|
||||
parentDatasetId?: string;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { Breadcrumb, App, Tabs } from "antd";
|
||||
import {
|
||||
ReloadOutlined,
|
||||
DownloadOutlined,
|
||||
UploadOutlined,
|
||||
EditOutlined,
|
||||
DeleteOutlined,
|
||||
} from "@ant-design/icons";
|
||||
ReloadOutlined,
|
||||
DownloadOutlined,
|
||||
UploadOutlined,
|
||||
EditOutlined,
|
||||
DeleteOutlined,
|
||||
PlusOutlined,
|
||||
} from "@ant-design/icons";
|
||||
import DetailHeader from "@/components/DetailHeader";
|
||||
import { mapDataset, datasetTypeMap } from "../dataset.const";
|
||||
import type { Dataset } from "@/pages/DataManagement/dataset.model";
|
||||
@@ -45,7 +46,7 @@ export default function DatasetDetail() {
|
||||
const [parentDataset, setParentDataset] = useState<Dataset | null>(null);
|
||||
const filesOperation = useFilesOperation(dataset);
|
||||
|
||||
const [showUploadDialog, setShowUploadDialog] = useState(false);
|
||||
const [showUploadDialog, setShowUploadDialog] = useState(false);
|
||||
const navigateItems = useMemo(() => {
|
||||
const items = [
|
||||
{
|
||||
@@ -66,6 +67,14 @@ export default function DatasetDetail() {
|
||||
});
|
||||
return items;
|
||||
}, [dataset, parentDataset]);
|
||||
const handleCreateChildDataset = () => {
|
||||
if (!dataset?.id) {
|
||||
return;
|
||||
}
|
||||
navigate("/data/management/create", {
|
||||
state: { parentDatasetId: dataset.id },
|
||||
});
|
||||
};
|
||||
const fetchDataset = async () => {
|
||||
if (!id) {
|
||||
return;
|
||||
@@ -158,12 +167,22 @@ export default function DatasetDetail() {
|
||||
];
|
||||
|
||||
// 数据集操作列表
|
||||
const operations = [
|
||||
{
|
||||
key: "edit",
|
||||
label: "编辑",
|
||||
icon: <EditOutlined />,
|
||||
onClick: () => {
|
||||
const operations = [
|
||||
...(dataset?.id && !dataset.parentDatasetId
|
||||
? [
|
||||
{
|
||||
key: "create-child",
|
||||
label: "创建子数据集",
|
||||
icon: <PlusOutlined />,
|
||||
onClick: handleCreateChildDataset,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
{
|
||||
key: "edit",
|
||||
label: "编辑",
|
||||
icon: <EditOutlined />,
|
||||
onClick: () => {
|
||||
setShowEditDialog(true);
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user