From b4d06d86ccb06d71c62e7c56dbc28583d6074fca Mon Sep 17 00:00:00 2001 From: Shahrukh Khan Date: Mon, 24 Jun 2024 19:43:10 +0500 Subject: [PATCH 1/2] datasets added --- .../settings/datasets/[id]/DatasetCard.tsx | 229 ++++++++++++++++++ client/app/settings/datasets/[id]/page.tsx | 41 ++++ client/app/settings/datasets/add/page.tsx | 141 +++++++++++ .../settings/datasets/datasets-interface.ts | 38 +++ client/app/settings/datasets/page.tsx | 78 ++++++ client/app/settings/layout.tsx | 43 ++++ client/app/settings/page.tsx | 4 + .../AddFormsDataSets/CsvDataSets.tsx | 143 +++++++++++ client/components/Buttons/Button.tsx | 21 -- client/components/CardConnector/index.tsx | 79 +----- client/components/Icons/AddWorkSpaceLarge.tsx | 20 ++ client/components/Icons/UploadIcon.tsx | 21 ++ client/components/SettingsLayout/LeftBar.tsx | 63 +++++ client/components/SettingsMenu/index.tsx | 20 ++ client/components/Skeletons/index.tsx | 25 ++ client/components/card/index.tsx | 19 ++ client/components/ui/textarea.tsx | 24 ++ client/hooks/useDatasets.tsx | 62 +++++ client/services/datasets.ts | 57 +++++ client/utils/apiUtils.ts | 11 +- server/api/v1/__init__.py | 2 +- server/api/v1/datasets/datasets.py | 58 ++++- server/app/controllers/datasets.py | 109 ++++++++- server/app/repositories/dataset.py | 12 +- server/app/repositories/workspace.py | 16 +- server/app/schemas/requests/datasets.py | 14 ++ server/app/schemas/responses/datasets.py | 5 +- 27 files changed, 1248 insertions(+), 107 deletions(-) create mode 100644 client/app/settings/datasets/[id]/DatasetCard.tsx create mode 100644 client/app/settings/datasets/[id]/page.tsx create mode 100644 client/app/settings/datasets/add/page.tsx create mode 100644 client/app/settings/datasets/datasets-interface.ts create mode 100644 client/app/settings/datasets/page.tsx create mode 100644 client/app/settings/layout.tsx create mode 100644 client/app/settings/page.tsx create mode 100644 client/components/AddFormsDataSets/CsvDataSets.tsx delete mode 100644 client/components/Buttons/Button.tsx create mode 100644 client/components/Icons/AddWorkSpaceLarge.tsx create mode 100644 client/components/Icons/UploadIcon.tsx create mode 100644 client/components/SettingsLayout/LeftBar.tsx create mode 100644 client/components/card/index.tsx create mode 100644 client/components/ui/textarea.tsx create mode 100644 client/hooks/useDatasets.tsx create mode 100644 client/services/datasets.ts create mode 100644 server/app/schemas/requests/datasets.py diff --git a/client/app/settings/datasets/[id]/DatasetCard.tsx b/client/app/settings/datasets/[id]/DatasetCard.tsx new file mode 100644 index 000000000..5dcf5eade --- /dev/null +++ b/client/app/settings/datasets/[id]/DatasetCard.tsx @@ -0,0 +1,229 @@ +import { Button } from "@/components/ui/button"; +import { Input } from "@/components/ui/input"; +import { Textarea } from "@/components/ui/textarea"; +import ConfirmationDialog from "components/ConfirmationDialog"; +import Card from "components/card"; +import { useRouter } from "next/navigation"; +import React, { useState } from "react"; +import { toast } from "react-toastify"; +import { IDatasetDetails } from "../datasets-interface"; +import { convertToCSV } from "@/utils/convertToCSV"; +import { useDeleteDataset, useUpdateDatasetCard } from "@/hooks/useDatasets"; +import { Loader } from "@/components/loader/Loader"; +import { DeleteDataset } from "@/services/datasets"; +import { axiosInstance } from "@/utils/apiUtils"; + +interface IProps { + dataframe: IDatasetDetails; +} + +const DatasetCard = ({ dataframe }: IProps) => { + const [isEditFormOpen, setIsEditFormOpen] = useState(false); + const [isDeleteLoading, setIsDeleteLoading] = useState(false); + const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false); + const [isDownloadLoading, setIsDownloadLoading] = useState(false); + + const { mutateAsync: editDatasetCard, isPending: isEditDatasetLoading } = + useUpdateDatasetCard(); + const { mutateAsync: deleteDatasetCard, isPending: isDeleteDatasetLoading } = + useDeleteDataset(); + + const [datasetForm, setDatasetForm] = useState({ + name: dataframe?.name, + description: dataframe?.description, + }); + + const router = useRouter(); + + const handleChange = (e) => { + const { name, value } = e.target; + setDatasetForm({ + ...datasetForm, + [name]: value, + }); + }; + + const onSuccess = (response: any) => { + toast.success(response?.data?.message); + setIsEditFormOpen(false); + setIsDeleteModalOpen(false); + }; + + const onError = (error: any) => { + toast.error( + error?.response?.data?.message + ? error?.response?.data?.message + : error.message + ); + }; + + const handleSubmit = async () => { + const dataSet = { + name: datasetForm.name, + description: datasetForm.description, + }; + editDatasetCard( + { + id: dataframe.id, + body: dataSet, + }, + { onSuccess, onError } + ); + }; + + const handleDownload = async () => { + setIsDownloadLoading(true); + await axiosInstance + .get(`/v1/datasets/download/${dataframe.id}`, { + responseType: "blob", + }) + .then((response) => { + const url = window.URL.createObjectURL(new Blob([response.data])); + const link = document.createElement("a"); + link.href = url; + link.setAttribute("download", `${dataframe.id}.csv`); + document.body.appendChild(link); + link.click(); + // Cleanup + link.parentNode.removeChild(link); + window.URL.revokeObjectURL(url); + }) + .catch((error) => { + toast.error( + error?.response?.data?.message + ? error?.response?.data?.message + : error?.message + ); + }); + }; + + const handleDelete = async () => { + deleteDatasetCard( + { + id: dataframe.id, + }, + { + onSuccess(response) { + toast.success(response?.data?.message); + setIsDeleteModalOpen(false); + router.push("/settings/datasets"); + }, + onError(error: any) { + toast.error( + error?.response?.data?.message + ? error?.response?.data?.message + : error?.message + ); + }, + } + ); + }; + + return ( + <> + {!isEditFormOpen ? ( + +
+
+

+ {datasetForm?.name} +

+

+ {datasetForm?.description} +

+
+
+ + + +
+
+
+ ) : ( + +
+
+ +
+
+