|
| 1 | +// This file is part of MinIO Console Server |
| 2 | +// Copyright (c) 2021 MinIO, Inc. |
| 3 | +// |
| 4 | +// This program is free software: you can redistribute it and/or modify |
| 5 | +// it under the terms of the GNU Affero General Public License as published by |
| 6 | +// the Free Software Foundation, either version 3 of the License, or |
| 7 | +// (at your option) any later version. |
| 8 | +// |
| 9 | +// This program is distributed in the hope that it will be useful, |
| 10 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +// GNU Affero General Public License for more details. |
| 13 | +// |
| 14 | +// You should have received a copy of the GNU Affero General Public License |
| 15 | +// along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +import React, { Fragment, useEffect, useState } from "react"; |
| 18 | +import { Theme } from "@mui/material/styles"; |
| 19 | +import createStyles from "@mui/styles/createStyles"; |
| 20 | +import withStyles from "@mui/styles/withStyles"; |
| 21 | +import { containerForHeader } from "../../Common/FormComponents/common/styleLibrary"; |
| 22 | +import Grid from "@mui/material/Grid"; |
| 23 | +import { Link } from "react-router-dom"; |
| 24 | +import { setErrorSnackMessage } from "../../../../actions"; |
| 25 | +import api from "../../../../common/api"; |
| 26 | +import { IEvent } from "../ListTenants/types"; |
| 27 | +import { niceDays } from "../../../../common/utils"; |
| 28 | +import { ErrorResponseHandler } from "../../../../common/types"; |
| 29 | +import TableWrapper from "../../Common/TableWrapper/TableWrapper"; |
| 30 | + |
| 31 | +interface IPVCDetailsProps { |
| 32 | + classes: any; |
| 33 | + match: any; |
| 34 | + setErrorSnackMessage: typeof setErrorSnackMessage; |
| 35 | +} |
| 36 | + |
| 37 | +const styles = (theme: Theme) => |
| 38 | + createStyles({ |
| 39 | + breadcrumLink: { |
| 40 | + textDecoration: "none", |
| 41 | + color: "black", |
| 42 | + }, |
| 43 | + ...containerForHeader(theme.spacing(4)), |
| 44 | + }); |
| 45 | + |
| 46 | +const PVCDetails = ({ |
| 47 | + classes, |
| 48 | + match, |
| 49 | + setErrorSnackMessage, |
| 50 | +}: IPVCDetailsProps) => { |
| 51 | + const [loading, setLoading] = useState<boolean>(true); |
| 52 | + const tenantNamespace = match.params["tenantNamespace"]; |
| 53 | + const tenantName = match.params["tenantName"]; |
| 54 | + const PVCName = match.params["PVCName"]; |
| 55 | + const [event, setEvent] = useState<IEvent[]>([]); |
| 56 | + |
| 57 | + useEffect(() => { |
| 58 | + if (loading) { |
| 59 | + api |
| 60 | + .invoke( |
| 61 | + "GET", |
| 62 | + `/api/v1/namespaces/${tenantNamespace}/tenants/${tenantName}/pvcs/${PVCName}/events` |
| 63 | + ) |
| 64 | + .then((res: IEvent[]) => { |
| 65 | + for (let i = 0; i < res.length; i++) { |
| 66 | + let currentTime = (Date.now() / 1000) | 0; |
| 67 | + |
| 68 | + res[i].seen = niceDays((currentTime - res[i].last_seen).toString()); |
| 69 | + } |
| 70 | + setEvent(res); |
| 71 | + setLoading(false); |
| 72 | + }) |
| 73 | + .catch((err: ErrorResponseHandler) => { |
| 74 | + setErrorSnackMessage(err); |
| 75 | + setLoading(false); |
| 76 | + }); |
| 77 | + } |
| 78 | + }, [loading, PVCName, tenantNamespace, tenantName, setErrorSnackMessage]); |
| 79 | + |
| 80 | + return ( |
| 81 | + <Fragment> |
| 82 | + <Grid item xs={12}> |
| 83 | + <h1 className={classes.sectionTitle}> |
| 84 | + <Link |
| 85 | + to={`/namespaces/${tenantNamespace}/tenants/${tenantName}/volumes`} |
| 86 | + className={classes.breadcrumLink} |
| 87 | + > |
| 88 | + PVCs |
| 89 | + </Link>{" "} |
| 90 | + > {PVCName} |
| 91 | + </h1> |
| 92 | + </Grid> |
| 93 | + <Grid container> |
| 94 | + <h1 className={classes.sectionTitle}>Events</h1> |
| 95 | + <TableWrapper |
| 96 | + itemActions={[]} |
| 97 | + columns={[ |
| 98 | + { label: "Namespace", elementKey: "namespace" }, |
| 99 | + { label: "Last Seen", elementKey: "seen" }, |
| 100 | + { label: "Message", elementKey: "message" }, |
| 101 | + { label: "Event Type", elementKey: "event_type" }, |
| 102 | + { label: "Reason", elementKey: "reason" }, |
| 103 | + ]} |
| 104 | + isLoading={loading} |
| 105 | + records={event} |
| 106 | + entityName="Events" |
| 107 | + idField="event" |
| 108 | + /> |
| 109 | + </Grid> |
| 110 | + </Fragment> |
| 111 | + ); |
| 112 | +}; |
| 113 | + |
| 114 | +export default withStyles(styles)(PVCDetails); |
0 commit comments