Skip to content

Commit e0d9ab5

Browse files
authored
💾 add component for PersistentVolumeClaim (cyclops-ui#320)
* feat(ui): add component for PersistentVolumeClaim * fix: remove comments about moving function to useEffect
1 parent 11185d7 commit e0d9ab5

File tree

2 files changed

+100
-1
lines changed

2 files changed

+100
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import axios from "axios";
2+
import { useEffect, useState } from "react";
3+
import { mapResponseError } from "../../utils/api/errors";
4+
import { Alert, Descriptions, Divider } from "antd";
5+
6+
interface Props {
7+
name: string;
8+
namespace: string;
9+
}
10+
11+
interface pvc {
12+
size: string;
13+
accessModes: string;
14+
}
15+
16+
const PersistentVolumeClaim = ({ name, namespace }: Props) => {
17+
const [pvc, setPvc] = useState<pvc>({
18+
size: "",
19+
accessModes: "",
20+
});
21+
const [error, setError] = useState({
22+
message: "",
23+
description: "",
24+
});
25+
26+
useEffect(() => {
27+
function fetchPersistentVolumeClaim() {
28+
axios
29+
.get(`/api/resources`, {
30+
params: {
31+
group: ``,
32+
version: `v1`,
33+
kind: `PersistentVolumeClaim`,
34+
name: name,
35+
namespace: namespace,
36+
},
37+
})
38+
.then((res) => {
39+
setPvc({
40+
size: res.data.size,
41+
accessModes: res.data.accessmodes.join(","),
42+
});
43+
})
44+
.catch((error) => {
45+
setError(mapResponseError(error));
46+
});
47+
}
48+
49+
fetchPersistentVolumeClaim();
50+
const interval = setInterval(() => fetchPersistentVolumeClaim(), 15000);
51+
return () => {
52+
clearInterval(interval);
53+
};
54+
}, [name, namespace]);
55+
56+
return (
57+
<div>
58+
{error.message.length !== 0 && (
59+
<Alert
60+
message={error.message}
61+
description={error.description}
62+
type="error"
63+
closable
64+
afterClose={() => {
65+
setError({
66+
message: "",
67+
description: "",
68+
});
69+
}}
70+
style={{ marginBottom: "20px" }}
71+
/>
72+
)}
73+
<Divider />
74+
<Descriptions style={{ width: "100%" }} bordered>
75+
{Object.entries(pvc).map(([key, dataValue]) => (
76+
<Descriptions.Item
77+
key={key}
78+
labelStyle={{ width: "20%" }}
79+
label={key}
80+
span={24}
81+
>
82+
{dataValue}
83+
</Descriptions.Item>
84+
))}
85+
</Descriptions>
86+
</div>
87+
);
88+
};
89+
90+
export default PersistentVolumeClaim;

cyclops-ui/src/components/pages/ModuleDetails.tsx

+10-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121
CaretRightOutlined,
2222
CheckCircleTwoTone,
2323
CloseSquareTwoTone,
24-
LinkOutlined,
2524
SearchOutlined,
2625
WarningTwoTone,
2726
} from "@ant-design/icons";
@@ -34,6 +33,8 @@ import StatefulSet from "../k8s-resources/StatefulSet";
3433
import Pod from "../k8s-resources/Pod";
3534
import Service from "../k8s-resources/Service";
3635
import ConfigMap from "../k8s-resources/ConfigMap";
36+
import PersistentVolumeClaim from "../k8s-resources/PersistentVolumeClaim";
37+
3738
import {
3839
moduleTemplateReferenceView,
3940
templateRef,
@@ -395,6 +396,14 @@ const ModuleDetails = () => {
395396
<ConfigMap name={resource.name} namespace={resource.namespace} />
396397
);
397398
break;
399+
case "PersistentVolumeClaim":
400+
resourceDetails = (
401+
<PersistentVolumeClaim
402+
name={resource.name}
403+
namespace={resource.namespace}
404+
/>
405+
);
406+
break;
398407
}
399408

400409
let deletedWarning = <p />;

0 commit comments

Comments
 (0)