From 688d9d69d5d2f3ce769dbc63da74d60c543e63d4 Mon Sep 17 00:00:00 2001 From: zteezy11 Date: Tue, 8 Oct 2024 13:50:27 +0800 Subject: [PATCH 01/13] Add delete functionality for samples --- ui/src/pages/Samples/SampleList.jsx | 89 +++++++++++++++-------------- ui/src/pages/Samples/Samples.jsx | 89 +++++++++++++++++------------ ui/src/services/Sample.js | 35 ++++++------ 3 files changed, 120 insertions(+), 93 deletions(-) diff --git a/ui/src/pages/Samples/SampleList.jsx b/ui/src/pages/Samples/SampleList.jsx index 8df98fb6..efbbbc35 100644 --- a/ui/src/pages/Samples/SampleList.jsx +++ b/ui/src/pages/Samples/SampleList.jsx @@ -2,55 +2,60 @@ import Button from "src/components/Button/Button" import { HiOutlinePlusCircle } from "react-icons/hi"; import { FaPen } from "react-icons/fa6" import { BsQuestionSquare } from "react-icons/bs"; +import { FaTrash } from "react-icons/fa"; import Table from "src/components/Table/Table" import style from "./Samples.module.css" import TitleDescription from "src/components/TitleDescription/TitleDescription"; -const SampleList = ({data, onCreate=()=>{}, onEdit = ()=>{}})=>{ - - - const tableColums = [ - { - name: 'Question List', - selector: row =>
{row.description}
, - grow: 1, - }, - { - name: '', - selector: row => <>onEdit(row)}> , - width: "80px" - }, - ] - - const rowExpandComponent = (row)=>{ - return( -
-
- Query : {row.data?.sql_metadata?.query} -
-
- Metadata :{row.data?.sql_metadata?.metadata} -
-
- ) - } - - - return( -
-
- -
-
- -
-
- - +const SampleList = ({ data, onCreate = () => { }, onEdit = () => { }, onDelete = () => { } }) => { + + + const tableColums = [ + { + name: 'Question List', + selector: row =>
{row.description}
, + grow: 1, + }, + { + name: '', + selector: row => ( +
+ onEdit(row)}> + onDelete(row)}> +
+ ), + width: "120px" + }, + ] + const rowExpandComponent = (row) => { + return ( +
+
+ Query : {row.data?.sql_metadata?.query} +
+
+ Metadata :{row.data?.sql_metadata?.metadata}
+
) + } + + + return ( +
+
+ +
+
+ +
+
+
+ + + ) } -export default SampleList \ No newline at end of file +export default SampleList diff --git a/ui/src/pages/Samples/Samples.jsx b/ui/src/pages/Samples/Samples.jsx index f9ef8cd7..6ab764c3 100644 --- a/ui/src/pages/Samples/Samples.jsx +++ b/ui/src/pages/Samples/Samples.jsx @@ -3,48 +3,67 @@ import EmptySample from "./EmptySample" import Modal from "src/components/Modal/Modal" import { useEffect, useState } from "react" import SampleForm from "./SampleForm" -import { getSamples } from "src/services/Sample" +import { getSamples, deleteSample } from "src/services/Sample" import SampleList from "./SampleList" +import { confirmDialog } from "src/utils/confirmDialog" +const Samples = () => { + const [sampleList, setSampleList] = useState([]) + const [showSampleModal, setSampleModal] = useState(false) + const [editSample, setEditSample] = useState({}) -const Samples = ()=>{ + const getAllSamples = () => { + getSamples().then(response => { + setSampleList(response.data?.data?.sql ?? []) + }) + } - const [sampleList, setSampleList] = useState([]) - const [showSampleModal, setSampleModal] = useState(false) - const [editSample, setEditSample] = useState({}) + const onEdit = (sampleData) => { + setSampleModal(true) + setEditSample(sampleData) + } - const getAllSamples = ()=>{ - getSamples().then(response=>{ - setSampleList(response.data?.data?.sql ?? []) - }) - } - - const onEdit = (sampleData)=>{ - setSampleModal(true) - setEditSample(sampleData) - } - - const onCreateNew = ()=>{ - setSampleModal(true) - setEditSample({}) - } + const onCreateNew = () => { + setSampleModal(true) + setEditSample({}) + } + const onDelete = (sampleData) => { + confirmDialog({ + title: "Delete Sample", + message: "Are you sure you want to delete this sample?", + onConfirm: () => { + deleteSample(sampleData.id).then(() => { + getAllSamples() + }).catch(error => { + console.error("Error deleting sample:", error) + // You can add a simple alert here if you want to show an error message + alert("Failed to delete sample. Please try again.") + }) + } + }) + } - useEffect(()=>{ - getAllSamples() - }, []) - - return( - - - { sampleList?.length == 0 && setSampleModal(true)} /> } - { sampleList?.length > 0 && } + useEffect(() => { + getAllSamples() + }, []) - setSampleModal(false)} > - setSampleModal(false)} /> - - - ) + return ( + + {sampleList?.length == 0 && setSampleModal(true)} />} + {sampleList?.length > 0 && ( + + )} + setSampleModal(false)}> + setSampleModal(false)} /> + + + ) } -export default Samples \ No newline at end of file +export default Samples diff --git a/ui/src/services/Sample.js b/ui/src/services/Sample.js index 3031445b..e592d8e4 100644 --- a/ui/src/services/Sample.js +++ b/ui/src/services/Sample.js @@ -1,25 +1,28 @@ import { API_URL } from "src/config/const"; import GetService from "src/utils/http/GetService"; import PostService from "src/utils/http/PostService"; +import DeleteService from "src/utils/http/DeleteService"; -export const getSamples = ()=>{ - return GetService(API_URL + "/sql/list") +export const getSamples = () => { + return GetService(API_URL + "/sql/list") } -export const saveSamples = (sampleId, data)=>{ - let apiURL = "/sql/create"; - if(sampleId){ - apiURL = `/sql/update/${sampleId}`; - } +export const saveSamples = (sampleId, data) => { + let apiURL = "/sql/create"; + if (sampleId) { + apiURL = `/sql/update/${sampleId}`; + } - return PostService(API_URL + apiURL, { - connector_id: data.connect_id, - description: data.question, - sql_metadata: { - query: data.query, - metadata: data.metadata - } - }) + return PostService(API_URL + apiURL, { + connector_id: data.connect_id, + description: data.question, + sql_metadata: { + query: data.query, + metadata: data.metadata + } + }) } - +export const deleteSample = (sampleId) => { + return DeleteService(API_URL + `/api/v1/sqldelete/${sampleId}`); +} From 78c7edf974cdfd5cf6aa60e47efe4d8663bad068 Mon Sep 17 00:00:00 2001 From: zteezy11 Date: Wed, 9 Oct 2024 18:58:41 +0800 Subject: [PATCH 02/13] Add requested changes in Samples.jsx --- ui/src/pages/Samples/Samples.jsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ui/src/pages/Samples/Samples.jsx b/ui/src/pages/Samples/Samples.jsx index 6ab764c3..d1c3d2a1 100644 --- a/ui/src/pages/Samples/Samples.jsx +++ b/ui/src/pages/Samples/Samples.jsx @@ -6,6 +6,7 @@ import SampleForm from "./SampleForm" import { getSamples, deleteSample } from "src/services/Sample" import SampleList from "./SampleList" import { confirmDialog } from "src/utils/confirmDialog" +import { toast } from "react-toastify" const Samples = () => { const [sampleList, setSampleList] = useState([]) @@ -35,10 +36,10 @@ const Samples = () => { onConfirm: () => { deleteSample(sampleData.id).then(() => { getAllSamples() + toast.success("Sample deleted successfully") }).catch(error => { console.error("Error deleting sample:", error) - // You can add a simple alert here if you want to show an error message - alert("Failed to delete sample. Please try again.") + toast.error("Failed to delete sample. Please try again.") }) } }) From f11bef6d5d26d2dc14dea8f17a117458b5fe4056 Mon Sep 17 00:00:00 2001 From: zteezy11 Date: Wed, 9 Oct 2024 19:22:03 +0800 Subject: [PATCH 03/13] Adjust API endpoint --- ui/src/services/Sample.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/src/services/Sample.js b/ui/src/services/Sample.js index e592d8e4..af03e0a6 100644 --- a/ui/src/services/Sample.js +++ b/ui/src/services/Sample.js @@ -24,5 +24,5 @@ export const saveSamples = (sampleId, data) => { } export const deleteSample = (sampleId) => { - return DeleteService(API_URL + `/api/v1/sqldelete/${sampleId}`); + return DeleteService(`${API_URL}/sql/delete/${sampleId}`); } From 3df6ec12823b3a039b16680c4cdee505929cb54f Mon Sep 17 00:00:00 2001 From: zteezy11 Date: Fri, 11 Oct 2024 22:22:10 +0800 Subject: [PATCH 04/13] Fixed Samples.jsx and confirmDialog function --- ui/src/pages/Samples/Samples.jsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ui/src/pages/Samples/Samples.jsx b/ui/src/pages/Samples/Samples.jsx index d1c3d2a1..8f79c969 100644 --- a/ui/src/pages/Samples/Samples.jsx +++ b/ui/src/pages/Samples/Samples.jsx @@ -1,7 +1,6 @@ import DashboardBody from "src/layouts/dashboard/DashboadBody" import EmptySample from "./EmptySample" import Modal from "src/components/Modal/Modal" -import { useEffect, useState } from "react" import SampleForm from "./SampleForm" import { getSamples, deleteSample } from "src/services/Sample" import SampleList from "./SampleList" @@ -33,6 +32,13 @@ const Samples = () => { confirmDialog({ title: "Delete Sample", message: "Are you sure you want to delete this sample?", + deleteButtonIconsvg: ( + + + + ), + cancelButtonIconsvg: null, + confirmButtonText: "Delete", onConfirm: () => { deleteSample(sampleData.id).then(() => { getAllSamples() From 3748dd16868acee521fefec2878a33d620a5081a Mon Sep 17 00:00:00 2001 From: zteezy11 Date: Tue, 15 Oct 2024 01:25:42 +0800 Subject: [PATCH 05/13] Changed Dialog export back --- ui/src/utils/ConfirmDialog.jsx | 262 ++++++++++++++++----------------- 1 file changed, 131 insertions(+), 131 deletions(-) diff --git a/ui/src/utils/ConfirmDialog.jsx b/ui/src/utils/ConfirmDialog.jsx index 78ffc9b5..65d0bf3e 100644 --- a/ui/src/utils/ConfirmDialog.jsx +++ b/ui/src/utils/ConfirmDialog.jsx @@ -1,145 +1,145 @@ -import {confirmAlert} from "react-confirm-alert" +import { confirmAlert } from "react-confirm-alert" import 'react-confirm-alert/src/react-confirm-alert.css'; const defaultValue = { - icon: - - , - cancelButtonText : "Cancel", - confirmButtonText: "Delete", - deleteButtonIconsvg: - + icon: + , - onCancel: ()=>{}, - onConfirm: ()=>{} + cancelButtonText: "Cancel", + confirmButtonText: "Delete", + deleteButtonIconsvg: + + , + onCancel: () => { }, + onConfirm: () => { } } const confirmDialogStyle = { - dialogBody: { - borderRadius: "8px", - boxShadow: "0px 4px 20px 0px rgba(0, 0, 0, 0.12)", - padding: "28px 40px", - width: "329px" - }, - iconContainer: { - textAlign: "center" - }, - icon: { - margin: "auto", - display: "block", - marginBottom: "23px", - }, - dialogText: { - textAlign: "center" - }, - dialogMainText: { - padding: "0px", - margin: "0px", - color: '#32324D', - textAlign: "center", - fontFamily: "Inter", - fontSize: "18px", - fontStyle: "normal", - fontWeight: "600", - lineHeight: "22px" - }, - dialogSubText: { - color: "#32324D", - textAlign: "center", - fontFamily: "Inter", - fontSize: "14px", - fontStyle: "normal", - fontWeight: "400", - lineHeight: "20px", - marginBottom: "30px" - }, - actionContainer: { - textAlign: "center" - }, - cancelButton: { - padding: "3px 13px", - borderRadius: "4px", - background: "#ECF5FF", - border: "none", - focus: "none", - color: "#3893FF", - /* Small text */ - fontFamily: "Inter", - fontSize: "16px", - fontStyle: "normal", - fontWeight: "500", - lineHeight: "150%", - marginRight:"10px" - }, - deleteButton: { - padding: "3px 13px", - borderRadius: "4px", - background: "#FFF2F0", - border: "none", - focus: "none", - color: "#FF7F6D", - /* Small text */ - fontFamily: "Inter", - fontSize: "16px", - fontStyle: "normal", - fontWeight: "500", - lineHeight: "150%", - marginLeft:"10px" - }, - buttonContentAlign:{ - display:"flex", - flexDirection:"row" - }, + dialogBody: { + borderRadius: "8px", + boxShadow: "0px 4px 20px 0px rgba(0, 0, 0, 0.12)", + padding: "28px 40px", + width: "329px" + }, + iconContainer: { + textAlign: "center" + }, + icon: { + margin: "auto", + display: "block", + marginBottom: "23px", + }, + dialogText: { + textAlign: "center" + }, + dialogMainText: { + padding: "0px", + margin: "0px", + color: '#32324D', + textAlign: "center", + fontFamily: "Inter", + fontSize: "18px", + fontStyle: "normal", + fontWeight: "600", + lineHeight: "22px" + }, + dialogSubText: { + color: "#32324D", + textAlign: "center", + fontFamily: "Inter", + fontSize: "14px", + fontStyle: "normal", + fontWeight: "400", + lineHeight: "20px", + marginBottom: "30px" + }, + actionContainer: { + textAlign: "center" + }, + cancelButton: { + padding: "3px 13px", + borderRadius: "4px", + background: "#ECF5FF", + border: "none", + focus: "none", + color: "#3893FF", + /* Small text */ + fontFamily: "Inter", + fontSize: "16px", + fontStyle: "normal", + fontWeight: "500", + lineHeight: "150%", + marginRight: "10px" + }, + deleteButton: { + padding: "3px 13px", + borderRadius: "4px", + background: "#FFF2F0", + border: "none", + focus: "none", + color: "#FF7F6D", + /* Small text */ + fontFamily: "Inter", + fontSize: "16px", + fontStyle: "normal", + fontWeight: "500", + lineHeight: "150%", + marginLeft: "10px" + }, + buttonContentAlign: { + display: "flex", + flexDirection: "row" + }, } -const confirmDailog = (title, message,deleteButtonIconsvg, cancelButtonIconsvg, confirmButtonText = "Delete", onConfirm = ()=>{}, config = {} )=>{ - - let allConfig = {...defaultValue, ...config} - confirmAlert({ - closeOnEscape: true, - customUI: ({onClose})=>{ - return(
-
-
- - - -
-
-
{title}
-

{message}

-
-
- - -
+const confirmDailog = (title, message, deleteButtonIconsvg, cancelButtonIconsvg, confirmButtonText = "Delete", onConfirm = () => { }, config = {}) => { + + let allConfig = { ...defaultValue, ...config } + confirmAlert({ + closeOnEscape: true, + customUI: ({ onClose }) => { + return (
+
+
+ + + +
+
+
{title}
+

{message}

+
+
+ +
+ + +
+
+
) + } + }) } -export default confirmDailog \ No newline at end of file +export default confirmDailog From 8aeda0bb57a12d654b91f35a6ce00485297b02b5 Mon Sep 17 00:00:00 2001 From: zteezy11 Date: Tue, 15 Oct 2024 02:06:32 +0800 Subject: [PATCH 06/13] Fixed Samples.jsx --- ui/src/pages/Samples/Samples.jsx | 47 ++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/ui/src/pages/Samples/Samples.jsx b/ui/src/pages/Samples/Samples.jsx index 8f79c969..8c56a85f 100644 --- a/ui/src/pages/Samples/Samples.jsx +++ b/ui/src/pages/Samples/Samples.jsx @@ -1,10 +1,11 @@ import DashboardBody from "src/layouts/dashboard/DashboadBody" import EmptySample from "./EmptySample" import Modal from "src/components/Modal/Modal" +import { useEffect, useState } from "react" import SampleForm from "./SampleForm" import { getSamples, deleteSample } from "src/services/Sample" import SampleList from "./SampleList" -import { confirmDialog } from "src/utils/confirmDialog" +import { confirmDailog } from "src/utils/confirmDialog" import { toast } from "react-toastify" const Samples = () => { @@ -29,26 +30,30 @@ const Samples = () => { } const onDelete = (sampleData) => { - confirmDialog({ - title: "Delete Sample", - message: "Are you sure you want to delete this sample?", - deleteButtonIconsvg: ( - - - - ), - cancelButtonIconsvg: null, - confirmButtonText: "Delete", - onConfirm: () => { - deleteSample(sampleData.id).then(() => { - getAllSamples() - toast.success("Sample deleted successfully") - }).catch(error => { - console.error("Error deleting sample:", error) - toast.error("Failed to delete sample. Please try again.") - }) - } - }) + const deleteIcon = ( + + + + ) + + const deleteFunction = () => { + deleteSample(sampleData.id).then(() => { + getAllSamples() + toast.success("Sample deleted successfully") + }).catch(error => { + console.error("Error deleting sample:", error) + toast.error("Failed to delete sample. Please try again.") + }) + } + + confirmDailog( + "Are you sure you want to delete this sample?", + "", + deleteIcon, + null, + "Delete", + deleteFunction + ) } useEffect(() => { From 2fe4ff4fcac158e93397468db6f737af33c0f778 Mon Sep 17 00:00:00 2001 From: zteezy11 Date: Tue, 8 Oct 2024 13:50:27 +0800 Subject: [PATCH 07/13] Add delete functionality for samples --- ui/src/pages/Samples/SampleList.jsx | 89 +++++++++++++++-------------- ui/src/pages/Samples/Samples.jsx | 89 +++++++++++++++++------------ ui/src/services/Sample.js | 35 ++++++------ 3 files changed, 120 insertions(+), 93 deletions(-) diff --git a/ui/src/pages/Samples/SampleList.jsx b/ui/src/pages/Samples/SampleList.jsx index 8df98fb6..efbbbc35 100644 --- a/ui/src/pages/Samples/SampleList.jsx +++ b/ui/src/pages/Samples/SampleList.jsx @@ -2,55 +2,60 @@ import Button from "src/components/Button/Button" import { HiOutlinePlusCircle } from "react-icons/hi"; import { FaPen } from "react-icons/fa6" import { BsQuestionSquare } from "react-icons/bs"; +import { FaTrash } from "react-icons/fa"; import Table from "src/components/Table/Table" import style from "./Samples.module.css" import TitleDescription from "src/components/TitleDescription/TitleDescription"; -const SampleList = ({data, onCreate=()=>{}, onEdit = ()=>{}})=>{ - - - const tableColums = [ - { - name: 'Question List', - selector: row =>
{row.description}
, - grow: 1, - }, - { - name: '', - selector: row => <>onEdit(row)}> , - width: "80px" - }, - ] - - const rowExpandComponent = (row)=>{ - return( -
-
- Query : {row.data?.sql_metadata?.query} -
-
- Metadata :{row.data?.sql_metadata?.metadata} -
-
- ) - } - - - return( -
-
- -
-
- -
-
-
- +const SampleList = ({ data, onCreate = () => { }, onEdit = () => { }, onDelete = () => { } }) => { + + + const tableColums = [ + { + name: 'Question List', + selector: row =>
{row.description}
, + grow: 1, + }, + { + name: '', + selector: row => ( +
+ onEdit(row)}> + onDelete(row)}> +
+ ), + width: "120px" + }, + ] + const rowExpandComponent = (row) => { + return ( +
+
+ Query : {row.data?.sql_metadata?.query} +
+
+ Metadata :{row.data?.sql_metadata?.metadata}
+
) + } + + + return ( +
+
+ +
+
+ +
+
+
+ + + ) } -export default SampleList \ No newline at end of file +export default SampleList diff --git a/ui/src/pages/Samples/Samples.jsx b/ui/src/pages/Samples/Samples.jsx index f9ef8cd7..6ab764c3 100644 --- a/ui/src/pages/Samples/Samples.jsx +++ b/ui/src/pages/Samples/Samples.jsx @@ -3,48 +3,67 @@ import EmptySample from "./EmptySample" import Modal from "src/components/Modal/Modal" import { useEffect, useState } from "react" import SampleForm from "./SampleForm" -import { getSamples } from "src/services/Sample" +import { getSamples, deleteSample } from "src/services/Sample" import SampleList from "./SampleList" +import { confirmDialog } from "src/utils/confirmDialog" +const Samples = () => { + const [sampleList, setSampleList] = useState([]) + const [showSampleModal, setSampleModal] = useState(false) + const [editSample, setEditSample] = useState({}) -const Samples = ()=>{ + const getAllSamples = () => { + getSamples().then(response => { + setSampleList(response.data?.data?.sql ?? []) + }) + } - const [sampleList, setSampleList] = useState([]) - const [showSampleModal, setSampleModal] = useState(false) - const [editSample, setEditSample] = useState({}) + const onEdit = (sampleData) => { + setSampleModal(true) + setEditSample(sampleData) + } - const getAllSamples = ()=>{ - getSamples().then(response=>{ - setSampleList(response.data?.data?.sql ?? []) - }) - } - - const onEdit = (sampleData)=>{ - setSampleModal(true) - setEditSample(sampleData) - } - - const onCreateNew = ()=>{ - setSampleModal(true) - setEditSample({}) - } + const onCreateNew = () => { + setSampleModal(true) + setEditSample({}) + } + const onDelete = (sampleData) => { + confirmDialog({ + title: "Delete Sample", + message: "Are you sure you want to delete this sample?", + onConfirm: () => { + deleteSample(sampleData.id).then(() => { + getAllSamples() + }).catch(error => { + console.error("Error deleting sample:", error) + // You can add a simple alert here if you want to show an error message + alert("Failed to delete sample. Please try again.") + }) + } + }) + } - useEffect(()=>{ - getAllSamples() - }, []) - - return( - - - { sampleList?.length == 0 && setSampleModal(true)} /> } - { sampleList?.length > 0 && } + useEffect(() => { + getAllSamples() + }, []) - setSampleModal(false)} > - setSampleModal(false)} /> - - - ) + return ( + + {sampleList?.length == 0 && setSampleModal(true)} />} + {sampleList?.length > 0 && ( + + )} + setSampleModal(false)}> + setSampleModal(false)} /> + + + ) } -export default Samples \ No newline at end of file +export default Samples diff --git a/ui/src/services/Sample.js b/ui/src/services/Sample.js index 3031445b..e592d8e4 100644 --- a/ui/src/services/Sample.js +++ b/ui/src/services/Sample.js @@ -1,25 +1,28 @@ import { API_URL } from "src/config/const"; import GetService from "src/utils/http/GetService"; import PostService from "src/utils/http/PostService"; +import DeleteService from "src/utils/http/DeleteService"; -export const getSamples = ()=>{ - return GetService(API_URL + "/sql/list") +export const getSamples = () => { + return GetService(API_URL + "/sql/list") } -export const saveSamples = (sampleId, data)=>{ - let apiURL = "/sql/create"; - if(sampleId){ - apiURL = `/sql/update/${sampleId}`; - } +export const saveSamples = (sampleId, data) => { + let apiURL = "/sql/create"; + if (sampleId) { + apiURL = `/sql/update/${sampleId}`; + } - return PostService(API_URL + apiURL, { - connector_id: data.connect_id, - description: data.question, - sql_metadata: { - query: data.query, - metadata: data.metadata - } - }) + return PostService(API_URL + apiURL, { + connector_id: data.connect_id, + description: data.question, + sql_metadata: { + query: data.query, + metadata: data.metadata + } + }) } - +export const deleteSample = (sampleId) => { + return DeleteService(API_URL + `/api/v1/sqldelete/${sampleId}`); +} From 7c9e6510650048a74ec29b2196cd0311d2cfaf7f Mon Sep 17 00:00:00 2001 From: zteezy11 Date: Wed, 9 Oct 2024 18:58:41 +0800 Subject: [PATCH 08/13] Add requested changes in Samples.jsx --- ui/src/pages/Samples/Samples.jsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ui/src/pages/Samples/Samples.jsx b/ui/src/pages/Samples/Samples.jsx index 6ab764c3..d1c3d2a1 100644 --- a/ui/src/pages/Samples/Samples.jsx +++ b/ui/src/pages/Samples/Samples.jsx @@ -6,6 +6,7 @@ import SampleForm from "./SampleForm" import { getSamples, deleteSample } from "src/services/Sample" import SampleList from "./SampleList" import { confirmDialog } from "src/utils/confirmDialog" +import { toast } from "react-toastify" const Samples = () => { const [sampleList, setSampleList] = useState([]) @@ -35,10 +36,10 @@ const Samples = () => { onConfirm: () => { deleteSample(sampleData.id).then(() => { getAllSamples() + toast.success("Sample deleted successfully") }).catch(error => { console.error("Error deleting sample:", error) - // You can add a simple alert here if you want to show an error message - alert("Failed to delete sample. Please try again.") + toast.error("Failed to delete sample. Please try again.") }) } }) From 9c9104157aefe6af6f63495144dfd6d032cb16cd Mon Sep 17 00:00:00 2001 From: zteezy11 Date: Wed, 9 Oct 2024 19:22:03 +0800 Subject: [PATCH 09/13] Adjust API endpoint --- ui/src/services/Sample.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/src/services/Sample.js b/ui/src/services/Sample.js index e592d8e4..af03e0a6 100644 --- a/ui/src/services/Sample.js +++ b/ui/src/services/Sample.js @@ -24,5 +24,5 @@ export const saveSamples = (sampleId, data) => { } export const deleteSample = (sampleId) => { - return DeleteService(API_URL + `/api/v1/sqldelete/${sampleId}`); + return DeleteService(`${API_URL}/sql/delete/${sampleId}`); } From 4a85a33e171e400e2c14838d2f931c6034807152 Mon Sep 17 00:00:00 2001 From: zteezy11 Date: Fri, 11 Oct 2024 22:22:10 +0800 Subject: [PATCH 10/13] Fixed Samples.jsx and confirmDialog function --- ui/src/pages/Samples/Samples.jsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ui/src/pages/Samples/Samples.jsx b/ui/src/pages/Samples/Samples.jsx index d1c3d2a1..8f79c969 100644 --- a/ui/src/pages/Samples/Samples.jsx +++ b/ui/src/pages/Samples/Samples.jsx @@ -1,7 +1,6 @@ import DashboardBody from "src/layouts/dashboard/DashboadBody" import EmptySample from "./EmptySample" import Modal from "src/components/Modal/Modal" -import { useEffect, useState } from "react" import SampleForm from "./SampleForm" import { getSamples, deleteSample } from "src/services/Sample" import SampleList from "./SampleList" @@ -33,6 +32,13 @@ const Samples = () => { confirmDialog({ title: "Delete Sample", message: "Are you sure you want to delete this sample?", + deleteButtonIconsvg: ( + + + + ), + cancelButtonIconsvg: null, + confirmButtonText: "Delete", onConfirm: () => { deleteSample(sampleData.id).then(() => { getAllSamples() From 9af0b753996424840947c9119a604f8f207a750a Mon Sep 17 00:00:00 2001 From: zteezy11 Date: Tue, 15 Oct 2024 02:06:32 +0800 Subject: [PATCH 11/13] Fixed Samples.jsx --- ui/src/pages/Samples/Samples.jsx | 47 ++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/ui/src/pages/Samples/Samples.jsx b/ui/src/pages/Samples/Samples.jsx index 8f79c969..8c56a85f 100644 --- a/ui/src/pages/Samples/Samples.jsx +++ b/ui/src/pages/Samples/Samples.jsx @@ -1,10 +1,11 @@ import DashboardBody from "src/layouts/dashboard/DashboadBody" import EmptySample from "./EmptySample" import Modal from "src/components/Modal/Modal" +import { useEffect, useState } from "react" import SampleForm from "./SampleForm" import { getSamples, deleteSample } from "src/services/Sample" import SampleList from "./SampleList" -import { confirmDialog } from "src/utils/confirmDialog" +import { confirmDailog } from "src/utils/confirmDialog" import { toast } from "react-toastify" const Samples = () => { @@ -29,26 +30,30 @@ const Samples = () => { } const onDelete = (sampleData) => { - confirmDialog({ - title: "Delete Sample", - message: "Are you sure you want to delete this sample?", - deleteButtonIconsvg: ( - - - - ), - cancelButtonIconsvg: null, - confirmButtonText: "Delete", - onConfirm: () => { - deleteSample(sampleData.id).then(() => { - getAllSamples() - toast.success("Sample deleted successfully") - }).catch(error => { - console.error("Error deleting sample:", error) - toast.error("Failed to delete sample. Please try again.") - }) - } - }) + const deleteIcon = ( + + + + ) + + const deleteFunction = () => { + deleteSample(sampleData.id).then(() => { + getAllSamples() + toast.success("Sample deleted successfully") + }).catch(error => { + console.error("Error deleting sample:", error) + toast.error("Failed to delete sample. Please try again.") + }) + } + + confirmDailog( + "Are you sure you want to delete this sample?", + "", + deleteIcon, + null, + "Delete", + deleteFunction + ) } useEffect(() => { From e2716b0051af3500cf761b0614aeb327fc12e53b Mon Sep 17 00:00:00 2001 From: zteezy11 Date: Fri, 18 Oct 2024 02:24:53 +0800 Subject: [PATCH 12/13] Fixed import bug --- ui/src/pages/Samples/Samples.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/src/pages/Samples/Samples.jsx b/ui/src/pages/Samples/Samples.jsx index 8c56a85f..a365d4f3 100644 --- a/ui/src/pages/Samples/Samples.jsx +++ b/ui/src/pages/Samples/Samples.jsx @@ -5,7 +5,7 @@ import { useEffect, useState } from "react" import SampleForm from "./SampleForm" import { getSamples, deleteSample } from "src/services/Sample" import SampleList from "./SampleList" -import { confirmDailog } from "src/utils/confirmDialog" +import { confirmDialog } from "src/utils/confirmDialog" import { toast } from "react-toastify" const Samples = () => { @@ -46,7 +46,7 @@ const Samples = () => { }) } - confirmDailog( + confirmDialog( "Are you sure you want to delete this sample?", "", deleteIcon, From 86f3073a5cade1837a64c6b5b3e1236f04d00421 Mon Sep 17 00:00:00 2001 From: zteezy11 Date: Fri, 18 Oct 2024 02:26:26 +0800 Subject: [PATCH 13/13] Fixed sqldelete api typo --- ui/src/services/Sample.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/src/services/Sample.js b/ui/src/services/Sample.js index af03e0a6..6c1f60b4 100644 --- a/ui/src/services/Sample.js +++ b/ui/src/services/Sample.js @@ -24,5 +24,5 @@ export const saveSamples = (sampleId, data) => { } export const deleteSample = (sampleId) => { - return DeleteService(`${API_URL}/sql/delete/${sampleId}`); + return DeleteService(`${API_URL}/sqldelete/${sampleId}`); }