|
| 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; |
0 commit comments