diff --git a/ui/src/api/api.tsx b/ui/src/api/api.tsx index 6c8b6f665..3fb08bad8 100644 --- a/ui/src/api/api.tsx +++ b/ui/src/api/api.tsx @@ -245,3 +245,20 @@ export const authAxios = async (msalInstance: PublicClientApplication) => { ); return axios; }; + +export const deleteEntity = async (enity: string) => { + const axios = await authAxios(msalInstance); + return axios.delete(`${getApiBaseUrl()}/entity/${enity}`); +}; + +export const getDependent = async (entity: string) => { + const axios = await authAxios(msalInstance); + return await axios + .get(`${getApiBaseUrl()}/dependent/${entity}`) + .then((response) => { + return response; + }) + .catch((error) => { + return error.response; + }); +}; diff --git a/ui/src/pages/dataSource/components/DataSourceTable/index.tsx b/ui/src/pages/dataSource/components/DataSourceTable/index.tsx index 951bd39fd..19f42de6d 100644 --- a/ui/src/pages/dataSource/components/DataSourceTable/index.tsx +++ b/ui/src/pages/dataSource/components/DataSourceTable/index.tsx @@ -1,10 +1,11 @@ import React, { forwardRef, useRef } from "react"; -import { Button } from "antd"; +import { Button, message, notification, Popconfirm, Space } from "antd"; import { useQuery } from "react-query"; import { useNavigate } from "react-router-dom"; import { DataSource } from "@/models/model"; -import { fetchDataSources } from "@/api"; +import { fetchDataSources, deleteEntity } from "@/api"; import ResizeTable, { ResizeColumnType } from "@/components/ResizeTable"; +import { DeleteOutlined } from "@ant-design/icons"; export interface DataSourceTableProps { project?: string; @@ -92,25 +93,45 @@ const DataSourceTable = (props: DataSourceTableProps, ref: any) => { { title: "Action", fixed: "right", - width: 130, + width: 200, resize: false, render: (record: DataSource) => { + const { guid } = record; return ( - + + + { + return new Promise((resolve) => { + onDelete(guid, resolve); + }); + }} + > + + + ); }, }, ]; - const { isLoading, data: tableData } = useQuery( + const { + isLoading, + data: tableData, + refetch, + } = useQuery( ["dataSources", project], async () => { if (project) { @@ -126,6 +147,24 @@ const DataSourceTable = (props: DataSourceTableProps, ref: any) => { } ); + const onDelete = async ( + entity: string, + resolve: (value?: unknown) => void + ) => { + try { + await deleteEntity(entity); + message.success("The date source is deleted successfully."); + refetch(); + } catch (e: any) { + notification.error({ + message: "", + description: e.detail, + placement: "top", + }); + } finally { + resolve(); + } + }; return ( { +const FeatureTable = (props: FeatureTableProps, ref: any) => { const navigate = useNavigate(); const { project, keyword } = props; @@ -97,25 +98,45 @@ const DataSourceTable = (props: DataSourceTableProps, ref: any) => { { title: "Action", fixed: "right", - width: 100, + width: 200, resize: false, render: (record: Feature) => { + const { guid } = record; return ( - + + + { + return new Promise((resolve) => { + onDelete(guid, resolve); + }); + }} + > + + + ); }, }, ]; - const { isLoading, data: tableData } = useQuery( + const { + isLoading, + data: tableData, + refetch, + } = useQuery( ["dataSources", project, keyword], async () => { if (project) { @@ -131,6 +152,25 @@ const DataSourceTable = (props: DataSourceTableProps, ref: any) => { } ); + const onDelete = async ( + entity: string, + resolve: (value?: unknown) => void + ) => { + try { + await deleteEntity(entity); + message.success("The feature is deleted successfully."); + refetch(); + } catch (e: any) { + notification.error({ + message: "", + description: e.detail, + placement: "top", + }); + } finally { + resolve(); + } + }; + return ( { ); }; -const DataSourceTableComponent = forwardRef( - DataSourceTable +const FeatureTableComponent = forwardRef( + FeatureTable ); -DataSourceTableComponent.displayName = "DataSourceTableComponent"; +FeatureTableComponent.displayName = "FeatureTableComponent"; -export default DataSourceTableComponent; +export default FeatureTableComponent; diff --git a/ui/src/pages/project/components/ProjectTable/index.tsx b/ui/src/pages/project/components/ProjectTable/index.tsx index 566d1443c..0a29ccd37 100644 --- a/ui/src/pages/project/components/ProjectTable/index.tsx +++ b/ui/src/pages/project/components/ProjectTable/index.tsx @@ -1,10 +1,11 @@ import React, { forwardRef } from "react"; -import { Button, Space } from "antd"; +import { Button, Space, notification, Popconfirm, message } from "antd"; import { useQuery } from "react-query"; import { useNavigate } from "react-router-dom"; import { Project } from "@/models/model"; -import { fetchProjects } from "@/api"; +import { fetchProjects, deleteEntity } from "@/api"; import ResizeTable, { ResizeColumnType } from "@/components/ResizeTable"; +import { DeleteOutlined } from "@ant-design/icons"; export interface ProjectTableProps { project?: string; @@ -30,7 +31,7 @@ const ProjectTable = (props: ProjectTableProps, ref: any) => { { key: "action", title: "Action", - width: 130, + width: 240, resize: false, render: (record: Project) => { const { name } = record; @@ -54,13 +55,30 @@ const ProjectTable = (props: ProjectTableProps, ref: any) => { > View Lineage + { + return new Promise((resolve) => { + onDelete(name, resolve); + }); + }} + > + + ); }, }, ]; - const { isLoading, data: tableData } = useQuery( + const { + isLoading, + data: tableData, + refetch, + } = useQuery( ["Projects", project], async () => { const reuslt = await fetchProjects(); @@ -79,6 +97,25 @@ const ProjectTable = (props: ProjectTableProps, ref: any) => { } ); + const onDelete = async ( + entity: string, + resolve: (value?: unknown) => void + ) => { + try { + await deleteEntity(entity); + message.success("The project is deleted successfully."); + refetch(); + } catch (e: any) { + notification.error({ + message: "", + description: e.detail, + placement: "top", + }); + } finally { + resolve(); + } + }; + return (