-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from Agenta-AI/delete-dataset
delete dataset
- Loading branch information
Showing
7 changed files
with
172 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 0 additions & 65 deletions
65
agenta-web/src/pages/apps/[app_name]/datasets/DatasetsTable.tsx
This file was deleted.
Oops, something went wrong.
124 changes: 113 additions & 11 deletions
124
agenta-web/src/pages/apps/[app_name]/datasets/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,132 @@ | ||
|
||
import { UploadOutlined } from "@ant-design/icons"; | ||
import { Button, Form, Input, Select, Spin, Upload, message } from "antd"; | ||
import { useState } from 'react'; | ||
import DatasetsTable from "./DatasetsTable"; | ||
import { Button, Spin, Table } from "antd"; | ||
|
||
import { Dataset } from "@/lib/Types"; | ||
import Link from "next/link"; | ||
import { useRouter } from "next/router"; | ||
import { ColumnsType } from 'antd/es/table'; | ||
import { useState, useEffect } from 'react'; | ||
import { formatDate } from '@/lib/helpers/dateTimeHelper'; | ||
import { DeleteOutlined } from "@ant-design/icons"; | ||
import { deleteDatasets } from "@/lib/services/api"; | ||
|
||
type DatasetTableDatatype = { | ||
key: string; | ||
created_at: string; | ||
name: string; | ||
} | ||
|
||
const fetchData = async (url: string): Promise<any> => { | ||
const response = await fetch(url); | ||
return response.json(); | ||
} | ||
|
||
export default function Datasets() { | ||
const router = useRouter(); | ||
const [dataset, setDataset] = useState<Dataset>({ | ||
id: '1', | ||
name: 'Example Dataset', | ||
}); | ||
const { app_name } = router.query; | ||
const [datasetsList, setDatasetsList] = useState<DatasetTableDatatype[]>([]); | ||
const [loading, setLoading] = useState<boolean>(true); | ||
const [selectionType, setSelectionType] = useState<'checkbox' | 'radio'>('checkbox'); | ||
const [selectedRowKeys, setSelectedRowKeys] = useState<React.Key[]>([]); | ||
|
||
useEffect(() => { | ||
if (!app_name) { | ||
return; | ||
} | ||
fetchData(`http://localhost/api/datasets?app_name=${app_name}`) | ||
.then(data => { | ||
console.log(data); | ||
let newDatasetsList = data.map((obj:Dataset) => { | ||
|
||
let newObj:DatasetTableDatatype = { | ||
key: obj._id, | ||
created_at: obj.created_at, | ||
name: obj.name | ||
} | ||
return newObj; | ||
}); | ||
console.log(newDatasetsList); | ||
setLoading(false); | ||
setDatasetsList(newDatasetsList); | ||
}). | ||
catch(error => { | ||
console.log(error); | ||
}); | ||
}, [app_name]); | ||
|
||
const columns: ColumnsType<DatasetTableDatatype> = [ | ||
{ | ||
title: 'Name', | ||
dataIndex: 'name', | ||
key: 'name' | ||
}, | ||
{ | ||
title: 'Creation date', | ||
dataIndex: 'created_at', | ||
key: 'created_at', | ||
render: (date: string) => { | ||
return formatDate(date); | ||
} | ||
}, | ||
]; | ||
|
||
const rowSelection = { | ||
onChange: (selectedRowKeys: React.Key[], selectedRows: DatasetTableDatatype[]) => { | ||
console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows); | ||
setSelectedRowKeys(selectedRowKeys); | ||
}, | ||
getCheckboxProps: (record: DatasetTableDatatype) => ({ | ||
disabled: record.name === 'Disabled User', // Column configuration not to be checked | ||
name: record.name, | ||
}), | ||
}; | ||
|
||
const onDelete = async () => { | ||
const datasetsIds = selectedRowKeys.map(key => key.toString()); | ||
setLoading(true); | ||
try { | ||
const deletedIds = await deleteDatasets(datasetsIds); | ||
setDatasetsList(prevDatasetsList => prevDatasetsList.filter(dataset => !deletedIds.includes(dataset.key))); | ||
|
||
setSelectedRowKeys([]); | ||
} catch (e) { | ||
console.log(e) | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
return ( | ||
<div> | ||
<div style={{ marginBottom: 40 }}> | ||
<Link href={`${router.asPath}/new`}> | ||
<Button >Add a dataset</Button> | ||
</Link> | ||
{ | ||
selectedRowKeys.length > 0 && ( | ||
<Button style={{marginLeft: 10}} onClick={onDelete}> | ||
<DeleteOutlined key="delete" style={{ color: 'red' }} /> | ||
Delete | ||
</Button> | ||
) | ||
} | ||
</div> | ||
|
||
<DatasetsTable dataset={dataset} /> | ||
<div> | ||
{loading ? ( | ||
<Spin /> | ||
) : ( | ||
<Table | ||
rowSelection={{ | ||
type: selectionType, | ||
...rowSelection, | ||
}} | ||
columns={columns} | ||
dataSource={datasetsList} | ||
loading={loading} | ||
/> | ||
)} | ||
</div> | ||
</div> | ||
|
||
|
||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters