-
Notifications
You must be signed in to change notification settings - Fork 160
/
index.tsx
76 lines (75 loc) · 2.43 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { FC } from "react";
import { Photon } from "@lepton-dashboard/interfaces/photon";
import { useNavigate } from "react-router-dom";
import { App, Button, Divider, Popconfirm, Space } from "antd";
import { useInject } from "@lepton-libs/di";
import { PhotonService } from "@lepton-dashboard/services/photon.service";
import { RefreshService } from "@lepton-dashboard/services/refresh.service";
import { CarbonIcon, DeploymentIcon } from "@lepton-dashboard/components/icons";
import { Download } from "@carbon/icons-react";
import { DeleteOutlined } from "@ant-design/icons";
export const Actions: FC<{ photon: Photon; extraActions: boolean }> = ({
photon,
extraActions = false,
}) => {
const navigate = useNavigate();
const { message } = App.useApp();
const photonService = useInject(PhotonService);
const refreshService = useInject(RefreshService);
return (
<Space size={0} split={<Divider type="vertical" />}>
<Button
size="small"
type="text"
icon={<DeploymentIcon />}
onClick={() =>
navigate(`/deployments/create/${photon.id}`, {
relative: "route",
})
}
>
Deploy
</Button>
{extraActions && (
<>
<Button
icon={<CarbonIcon icon={<Download />} />}
type="text"
size="small"
href={photonService.getDownloadUrlById(photon.id)}
download
>
Download
</Button>
<Popconfirm
title="Delete the photon"
description="Are you sure to delete?"
onConfirm={() => {
void message.loading({
content: `Deleting photon ${photon.id}, please wait...`,
key: "delete-photon",
duration: 0,
});
photonService.delete(photon.id).subscribe({
next: () => {
message.destroy("delete-photon");
void message.success(
`Successfully deleted photon ${photon.id}`
);
refreshService.refresh();
},
error: () => {
message.destroy("delete-photon");
},
});
}}
>
<Button danger size="small" type="text" icon={<DeleteOutlined />}>
Delete
</Button>
</Popconfirm>
</>
)}
</Space>
);
};