Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI add feature the deletion for projects/features/dataSource #909

Merged
merged 2 commits into from
Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions ui/src/api/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
};
65 changes: 52 additions & 13 deletions ui/src/pages/dataSource/components/DataSourceTable/index.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 (
<Button
type="primary"
ghost
onClick={() => {
navigate(getDetialUrl(record.guid));
}}
>
View Details
</Button>
<Space size="middle">
<Button
type="primary"
ghost
onClick={() => {
navigate(getDetialUrl(guid));
}}
>
View Details
</Button>
<Popconfirm
title="Are you sure to delete this data source?"
placement="topRight"
onConfirm={() => {
return new Promise((resolve) => {
onDelete(guid, resolve);
});
}}
>
<Button type="primary" danger ghost icon={<DeleteOutlined />}>
Detete
</Button>
</Popconfirm>
</Space>
);
},
},
];

const { isLoading, data: tableData } = useQuery<DataSource[]>(
const {
isLoading,
data: tableData,
refetch,
} = useQuery<DataSource[]>(
["dataSources", project],
async () => {
if (project) {
Expand All @@ -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 (
<ResizeTable
rowKey="guid"
Expand Down
78 changes: 59 additions & 19 deletions ui/src/pages/feature/components/FeatureTable/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import React, { forwardRef, useRef } from "react";
import { Button } from "antd";
import { Button, notification, message, Popconfirm, Space } from "antd";
import { useQuery } from "react-query";
import { useNavigate } from "react-router-dom";
import { Feature } from "@/models/model";
import { fetchFeatures } from "@/api";
import { fetchFeatures, deleteEntity } from "@/api";
import ResizeTable, { ResizeColumnType } from "@/components/ResizeTable";
import { DeleteOutlined } from "@ant-design/icons";

export interface DataSourceTableProps {
export interface FeatureTableProps {
project?: string;
keyword?: string;
}
Expand All @@ -16,7 +17,7 @@ export interface SearchModel {
roleName?: string;
}

const DataSourceTable = (props: DataSourceTableProps, ref: any) => {
const FeatureTable = (props: FeatureTableProps, ref: any) => {
const navigate = useNavigate();

const { project, keyword } = props;
Expand Down Expand Up @@ -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 (
<Button
type="primary"
ghost
onClick={() => {
navigate(getDetialUrl(record.guid));
}}
>
View Details
</Button>
<Space size="middle">
<Button
type="primary"
ghost
onClick={() => {
navigate(getDetialUrl(guid));
}}
>
View Details
</Button>
<Popconfirm
title="Are you sure to delete this feature?"
placement="topRight"
onConfirm={() => {
return new Promise((resolve) => {
onDelete(guid, resolve);
});
}}
>
<Button type="primary" danger ghost icon={<DeleteOutlined />}>
Detete
</Button>
</Popconfirm>
</Space>
);
},
},
];

const { isLoading, data: tableData } = useQuery<Feature[]>(
const {
isLoading,
data: tableData,
refetch,
} = useQuery<Feature[]>(
["dataSources", project, keyword],
async () => {
if (project) {
Expand All @@ -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 (
<ResizeTable
rowKey="guid"
Expand All @@ -142,10 +182,10 @@ const DataSourceTable = (props: DataSourceTableProps, ref: any) => {
);
};

const DataSourceTableComponent = forwardRef<unknown, DataSourceTableProps>(
DataSourceTable
const FeatureTableComponent = forwardRef<unknown, FeatureTableProps>(
FeatureTable
);

DataSourceTableComponent.displayName = "DataSourceTableComponent";
FeatureTableComponent.displayName = "FeatureTableComponent";

export default DataSourceTableComponent;
export default FeatureTableComponent;
45 changes: 41 additions & 4 deletions ui/src/pages/project/components/ProjectTable/index.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -54,13 +55,30 @@ const ProjectTable = (props: ProjectTableProps, ref: any) => {
>
View Lineage
</Button>
<Popconfirm
title="Are you sure to delete this project?"
placement="topRight"
onConfirm={() => {
return new Promise((resolve) => {
onDelete(name, resolve);
});
}}
>
<Button type="primary" danger ghost icon={<DeleteOutlined />}>
Detete
</Button>
</Popconfirm>
</Space>
);
},
},
];

const { isLoading, data: tableData } = useQuery<Project[]>(
const {
isLoading,
data: tableData,
refetch,
} = useQuery<Project[]>(
["Projects", project],
async () => {
const reuslt = await fetchProjects();
Expand All @@ -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 (
<ResizeTable
rowKey="name"
Expand Down