network-resurrector-frontend/src/features/machines/components/Machine.js

92 lines
2.6 KiB
JavaScript
Raw Normal View History

2021-04-17 02:21:49 +03:00
import React from "react";
import PropTypes from "prop-types";
2021-04-17 02:39:05 +03:00
import {
TableCell,
TableRow,
IconButton,
Collapse,
Tooltip
} from "@material-ui/core";
2021-04-17 03:05:52 +03:00
import { KeyboardArrowDown, KeyboardArrowUp } from "@material-ui/icons";
2021-04-17 02:21:49 +03:00
import { makeStyles } from "@material-ui/core/styles";
import MachineLog from "./MachineLog";
2021-04-17 02:39:05 +03:00
import { useTranslation } from "react-i18next";
2021-04-17 02:21:49 +03:00
const useRowStyles = makeStyles({
root: {
"& > *": {
borderBottom: "unset"
}
}
});
2021-04-17 18:45:56 +03:00
const Machine = ({ machine, actions, logs }) => {
2021-04-17 02:21:49 +03:00
const [open, setOpen] = React.useState(false);
const classes = useRowStyles();
2021-04-17 02:39:05 +03:00
const { t } = useTranslation();
2021-04-17 02:21:49 +03:00
return (
<React.Fragment>
<TableRow className={classes.root}>
<TableCell>
<IconButton
aria-label="expand row"
size="small"
onClick={() => setOpen(!open)}
>
2021-04-17 02:39:05 +03:00
{open ? <KeyboardArrowUp /> : <KeyboardArrowDown />}
2021-04-17 02:21:49 +03:00
</IconButton>
</TableCell>
<TableCell component="th" scope="row">
{machine.fullMachineName}
</TableCell>
<TableCell>{machine.machineName}</TableCell>
<TableCell>{machine.iPv4Address}</TableCell>
2021-04-17 02:39:05 +03:00
<TableCell align="right">
<>
2021-04-17 03:05:52 +03:00
{actions.map(action => (
2021-04-17 14:07:53 +03:00
<Tooltip
title={t(action.tooltip)}
key={`machine-item-${machine.machineId}-${action.code}-tooltip`}
>
2021-04-17 03:05:52 +03:00
<span>
<IconButton
id={`machine-item-${machine.machineId}-${action.code}`}
size={"small"}
disabled={false}
onClick={action.effect(machine)}
>
<action.icon />
</IconButton>
</span>
</Tooltip>
))}
2021-04-17 02:39:05 +03:00
</>
</TableCell>
2021-04-17 02:21:49 +03:00
</TableRow>
<TableRow>
<TableCell style={{ paddingBottom: 0, paddingTop: 0 }} colSpan={6}>
<Collapse in={open} timeout="auto" unmountOnExit>
2021-04-17 18:45:56 +03:00
<MachineLog logs={logs} />
2021-04-17 02:21:49 +03:00
</Collapse>
</TableCell>
</TableRow>
</React.Fragment>
);
};
2021-04-17 18:45:56 +03:00
Machine.propTypes = {
2021-04-17 02:21:49 +03:00
machine: PropTypes.shape({
machineId: PropTypes.number.isRequired,
machineName: PropTypes.string.isRequired,
fullMachineName: PropTypes.string.isRequired,
macAddress: PropTypes.string.isRequired,
iPv4Address: PropTypes.string,
description: PropTypes.string
2021-04-17 03:05:52 +03:00
}).isRequired,
2021-04-17 18:45:56 +03:00
actions: PropTypes.array.isRequired,
logs: PropTypes.array.isRequired
2021-04-17 02:21:49 +03:00
};
2021-04-17 18:45:56 +03:00
export default Machine;