Skip to content

Commit e4bbc7b

Browse files
committed
fixbug: 修复数据集bug
1 parent 78614d7 commit e4bbc7b

13 files changed

Lines changed: 170 additions & 239 deletions

File tree

frontend/src/components/TagManagement.tsx

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Edit, Save, TagIcon, X, Trash } from "lucide-react";
55
import { TagItem } from "@/pages/DataManagement/dataset.model";
66

77
function Tag({
8-
isEditable,
8+
isEditable = false,
99
tag,
1010
editingTag,
1111
editingTagValue,
@@ -27,7 +27,7 @@ function Tag({
2727
onChange={(e) => setEditingTagValue(e.target.value)}
2828
onKeyPress={(e) => {
2929
if (e.key === "Enter") {
30-
handleEditTag(tag.name, editingTagValue);
30+
handleEditTag(tag, editingTagValue);
3131
}
3232
if (e.key === "Escape") {
3333
setEditingTag(null);
@@ -98,7 +98,7 @@ const TagManager: React.FC = ({
9898
onUpdate,
9999
}: {
100100
onFetch: () => Promise<any>;
101-
onCreate: (tag: TagItem) => Promise<{ ok: boolean }>;
101+
onCreate: (tag: Pick<TagItem, "name">) => Promise<{ ok: boolean }>;
102102
onDelete: (tagId: number) => Promise<{ ok: boolean }>;
103103
onUpdate: (oldTagId: number, newTag: string) => Promise<{ ok: boolean }>;
104104
}) => {
@@ -125,17 +125,11 @@ const TagManager: React.FC = ({
125125
// 添加标签
126126
const addTag = async (tag: string) => {
127127
try {
128-
const response = await onCreate?.({
128+
await onCreate?.({
129129
name: tag,
130-
color: "#111111",
131-
description: "23",
132130
});
133-
if (response.ok) {
134-
fetchTags();
135-
message.success("标签添加成功");
136-
} else {
137-
message.error("添加标签失败");
138-
}
131+
fetchTags();
132+
message.success("标签添加成功");
139133
} catch (error) {
140134
message.error("添加标签失败");
141135
}
@@ -144,27 +138,19 @@ const TagManager: React.FC = ({
144138
// 删除标签
145139
const deleteTag = async (tag: string) => {
146140
try {
147-
const response = await onDelete?.(tag.id);
148-
if (response.ok) {
149-
fetchTags();
150-
message.success("标签删除成功");
151-
} else {
152-
message.error("删除标签失败");
153-
}
141+
await onDelete?.(tag.id);
142+
fetchTags();
143+
message.success("标签删除成功");
154144
} catch (error) {
155145
message.error("删除标签失败");
156146
}
157147
};
158148

159-
const updateTag = async (oldTag: string, newTag: string) => {
149+
const updateTag = async (oldTag: TagItem, newTag: string) => {
160150
try {
161-
const response = await onUpdate?.(oldTag.id, newTag);
162-
if (response.ok) {
163-
fetchTags();
164-
message.success("标签更新成功");
165-
} else {
166-
message.error("更新标签失败");
167-
}
151+
await onUpdate?.(oldTag.id, newTag);
152+
fetchTags();
153+
message.success("标签更新成功");
168154
} catch (error) {
169155
message.error("更新标签失败");
170156
}
@@ -179,7 +165,7 @@ const TagManager: React.FC = ({
179165

180166
const handleEditTag = (tag: string, value: string) => {
181167
if (value.trim()) {
182-
updateTag(tag.id, value.trim());
168+
updateTag(tag, value.trim());
183169
setEditingTag(null);
184170
setEditingTagValue("");
185171
}
@@ -197,8 +183,8 @@ const TagManager: React.FC = ({
197183
};
198184

199185
useEffect(() => {
200-
fetchTags();
201-
}, []);
186+
if (showTagManager) fetchTags();
187+
}, [showTagManager]);
202188

203189
return (
204190
<>

frontend/src/mock/mock-seed/data-management.cjs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,7 @@ function datasetItem() {
1616
return {
1717
id: Mock.Random.guid().replace(/[^a-zA-Z0-9]/g, ""),
1818
name: Mock.Random.ctitle(5, 20),
19-
type: Mock.Random.pick([
20-
"TEXT_DOCUMENT",
21-
"TEXT_WEB",
22-
"TEXT_DIALOG",
23-
"IMAGE_IMAGE",
24-
"IMAGE_CAPTION",
25-
"AUDIO_AUDIO",
26-
"AUDIO_JSONL",
27-
"VIDEO_VIDEO",
28-
"VIDEO_JSONL",
29-
]),
19+
type: Mock.Random.pick(["TEXT", "IMAGE", "AUDIO", "VIDEO"]),
3020
status: Mock.Random.pick(["ACTIVE", "INACTIVE", "PROCESSING"]),
3121
tags: Mock.Random.shuffle(tagList).slice(0, Mock.Random.integer(1, 3)),
3222
totalSize: Mock.Random.integer(1024, 1024 * 1024 * 1024), // in bytes

frontend/src/pages/DataManagement/Create/CreateDataset.tsx

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,17 @@ import { Link, useNavigate } from "react-router";
66
import { createDatasetUsingPost } from "../dataset.api";
77
import { DatasetType, DataSource } from "../dataset.model";
88
import BasicInformation from "./components/BasicInformation";
9-
import ImportConfiguration from "./components/ImportConfiguration";
10-
import { useImportFile } from "../hooks";
119

1210
export default function DatasetCreate() {
1311
const navigate = useNavigate();
1412
const { message } = App.useApp();
1513
const [form] = Form.useForm();
16-
const { importFileRender, handleUpload } = useImportFile();
1714

1815
const [newDataset, setNewDataset] = useState({
1916
name: "",
2017
description: "",
2118
datasetType: DatasetType.TEXT,
2219
tags: [],
23-
config: {
24-
source: DataSource.UPLOAD,
25-
target: DataSource.UPLOAD,
26-
nasHost: "",
27-
sharePath: "",
28-
username: "",
29-
password: "",
30-
endpoint: "",
31-
bucket: "",
32-
accessKey: "",
33-
secretKey: "",
34-
databaseType: "",
35-
databaseName: "",
36-
tableName: "",
37-
dbType: "",
38-
connectionString: "",
39-
},
4020
});
4121

4222
const handleSubmit = async () => {
@@ -46,13 +26,8 @@ export default function DatasetCreate() {
4626
...formValues,
4727
files: undefined,
4828
};
49-
let dataset;
5029
try {
51-
const { data } = await createDatasetUsingPost(params);
52-
dataset = data;
53-
if (formValues?.config?.source === DataSource.UPLOAD) {
54-
handleUpload(dataset);
55-
}
30+
await createDatasetUsingPost(params);
5631
message.success(`数据集创建成功`);
5732
navigate("/data/management");
5833
} catch (error) {
@@ -90,12 +65,6 @@ export default function DatasetCreate() {
9065
layout="vertical"
9166
>
9267
<BasicInformation data={newDataset} setData={setNewDataset} />
93-
94-
{/* Import Configuration */}
95-
<ImportConfiguration
96-
data={newDataset}
97-
importFileRender={importFileRender}
98-
/>
9968
</Form>
10069
</div>
10170
<div className="flex gap-2 justify-end p-6 border-t border-gray-200">

frontend/src/pages/DataManagement/Create/EditDataset.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
} from "../dataset.api";
66
import { useEffect, useState } from "react";
77
import { Dataset, DatasetType } from "../dataset.model";
8-
import { App, Button, Drawer, Form } from "antd";
8+
import { App, Button, Drawer, Form, Modal } from "antd";
99

1010
export default function EditDataset({
1111
open,
@@ -69,19 +69,19 @@ export default function EditDataset({
6969
};
7070

7171
return (
72-
<Drawer
72+
<Modal
7373
title={`编辑数据集${data?.name}`}
74-
onClose={onClose}
74+
onCancel={onClose}
7575
open={open}
7676
width={600}
7777
maskClosable={false}
7878
footer={
79-
<div className="flex gap-2 justify-end p-6">
79+
<>
8080
<Button onClick={onClose}>取消</Button>
8181
<Button type="primary" onClick={handleSubmit}>
8282
确定
8383
</Button>
84-
</div>
84+
</>
8585
}
8686
>
8787
<Form
@@ -96,6 +96,6 @@ export default function EditDataset({
9696
hidden={["datasetType"]}
9797
/>
9898
</Form>
99-
</Drawer>
99+
</Modal>
100100
);
101101
}

frontend/src/pages/DataManagement/Create/components/BasicInformation.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ export default function BasicInformation({
5656
}, []);
5757
return (
5858
<>
59-
<h2 className="font-medium text-gray-900 text-base mb-2">基本信息</h2>
6059
<Form.Item
6160
label="名称"
6261
name="name"

frontend/src/pages/DataManagement/Detail/DatasetDetail.tsx

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
import { useEffect, useMemo, useState } from "react";
2-
import { Breadcrumb, Modal, App, Tabs } from "antd";
2+
import { Breadcrumb, App, Tabs } from "antd";
33
import {
44
ReloadOutlined,
55
DownloadOutlined,
66
UploadOutlined,
7-
FileTextOutlined,
8-
DatabaseOutlined,
9-
FileImageOutlined,
107
EditOutlined,
118
} from "@ant-design/icons";
129
import DetailHeader from "@/components/DetailHeader";
1310
import { mapDataset, datasetTypeMap } from "../dataset.const";
1411
import type { Dataset } from "@/pages/DataManagement/dataset.model";
1512
import { Link, useParams } from "react-router";
16-
import { useFilesOperation, useImportFile } from "../hooks";
13+
import { useFilesOperation } from "../hooks";
1714
import {
1815
createDatasetTagUsingPost,
1916
downloadFile,
@@ -26,6 +23,7 @@ import DataLineageFlow from "./components/DataLineageFlow";
2623
import Overview from "./components/Overview";
2724
import { Activity, Clock, File, FileType } from "lucide-react";
2825
import EditDataset from "../Create/EditDataset";
26+
import ImportConfiguration from "./components/ImportConfiguration";
2927

3028
const tabList = [
3129
{
@@ -49,7 +47,6 @@ export default function DatasetDetail() {
4947
const [showEditDialog, setShowEditDialog] = useState(false);
5048

5149
const [dataset, setDataset] = useState<Dataset>({} as Dataset);
52-
const { importFileRender, handleUpload } = useImportFile();
5350
const filesOperation = useFilesOperation(dataset);
5451

5552
const [showUploadDialog, setShowUploadDialog] = useState(false);
@@ -81,7 +78,7 @@ export default function DatasetDetail() {
8178
};
8279

8380
const handleExportFormat = async ({ type }) => {
84-
await downloadFile(dataset.id, type, `${dataset.name}-${type}.txt`);
81+
await downloadFile(dataset.id, type, `${dataset.name}-${type}.zip`);
8582
message.success("文件下载成功");
8683
};
8784

@@ -138,21 +135,21 @@ export default function DatasetDetail() {
138135

139136
{
140137
key: "upload",
141-
label: "上传文件",
138+
label: "导入数据",
142139
icon: <UploadOutlined />,
143140
onClick: () => setShowUploadDialog(true),
144141
},
145142
{
146143
key: "export",
147144
label: "导出",
148145
icon: <DownloadOutlined />,
149-
isDropdown: true,
150-
items: [
151-
{ key: "alpaca", label: "Alpaca 格式", icon: <FileTextOutlined /> },
152-
{ key: "jsonl", label: "JSONL 格式", icon: <DatabaseOutlined /> },
153-
{ key: "csv", label: "CSV 格式", icon: <FileTextOutlined /> },
154-
{ key: "coco", label: "COCO 格式", icon: <FileImageOutlined /> },
155-
],
146+
// isDropdown: true,
147+
// items: [
148+
// { key: "alpaca", label: "Alpaca 格式", icon: <FileTextOutlined /> },
149+
// { key: "jsonl", label: "JSONL 格式", icon: <DatabaseOutlined /> },
150+
// { key: "csv", label: "CSV 格式", icon: <FileTextOutlined /> },
151+
// { key: "coco", label: "COCO 格式", icon: <FileImageOutlined /> },
152+
// ],
156153
onMenuClick: handleExportFormat,
157154
},
158155
{
@@ -207,20 +204,12 @@ export default function DatasetDetail() {
207204
{activeTab === "quality" && <DataQuality />}
208205
</div>
209206
</div>
210-
211-
{/* Upload Dialog */}
212-
<Modal
213-
title="上传文件"
207+
<ImportConfiguration
208+
data={dataset}
214209
open={showUploadDialog}
215-
onCancel={() => setShowUploadDialog(false)}
216-
onOk={async () => {
217-
await handleUpload(dataset);
218-
setShowUploadDialog(false);
219-
filesOperation.fetchFiles();
220-
}}
221-
>
222-
{importFileRender()}
223-
</Modal>
210+
onClose={() => setShowUploadDialog(false)}
211+
onRefresh={handleRefresh}
212+
/>
224213
<EditDataset
225214
data={dataset}
226215
open={showEditDialog}

0 commit comments

Comments
 (0)