reverse-proxy-frontend/src/features/session/components/SessionForwardsComponent.js

107 lines
3.9 KiB
JavaScript
Raw Normal View History

2020-05-14 00:55:00 +03:00
import React from "react";
import PropTypes from "prop-types";
2020-05-14 13:45:35 +03:00
import { makeStyles } from "@material-ui/core/styles";
2020-05-14 00:55:00 +03:00
import Table from "@material-ui/core/Table";
import TableBody from "@material-ui/core/TableBody";
import TableContainer from "@material-ui/core/TableContainer";
import TableHead from "@material-ui/core/TableHead";
import TableRow from "@material-ui/core/TableRow";
import Paper from "@material-ui/core/Paper";
2020-05-14 02:06:14 +03:00
import Spinner from "../../../components/common/Spinner";
2020-05-14 03:01:01 +03:00
import DonutLargeRoundedIcon from "@material-ui/icons/DonutLargeRounded";
import IconButton from "@material-ui/core/IconButton";
import Tooltip from "@material-ui/core/Tooltip";
2020-05-14 10:29:53 +03:00
import SessionForwardsHeaderComponent from "./SessionForwardsHeaderComponent";
2020-05-14 03:01:01 +03:00
import { Grid } from "@material-ui/core";
import { useTranslation } from "react-i18next";
2020-05-14 15:29:32 +03:00
import styles from "../../../components/common/styles/tableStyles";
2020-05-14 13:45:35 +03:00
import {
StyledTableCell,
StyledTableRow
} from "../../../components/common/MaterialTable";
2020-05-14 00:55:00 +03:00
2020-05-14 13:45:35 +03:00
const useStyles = makeStyles(styles);
2020-05-14 00:55:00 +03:00
2020-05-14 13:45:35 +03:00
const SessionForwardsComponent = ({ session, forwards, openOptionsDialog }) => {
2020-05-14 00:55:00 +03:00
const classes = useStyles();
2020-05-14 03:01:01 +03:00
const { t } = useTranslation();
2020-05-14 00:55:00 +03:00
2020-05-14 03:01:01 +03:00
return (
<Grid container>
<Grid item xs={12} sm={12} md={12}>
{!forwards || forwards.loading ? (
<Spinner />
) : (
forwards.loaded && (
<TableContainer component={Paper}>
<Table
className={classes.table}
size="small"
aria-label="customized table"
>
<TableHead>
<TableRow>
<StyledTableCell />
<StyledTableCell>
2020-05-14 13:45:35 +03:00
{t("Session.Forwards.From")}
</StyledTableCell>
<StyledTableCell>
{t("Session.Forwards.To")}
2020-05-14 03:01:01 +03:00
</StyledTableCell>
<StyledTableCell align="right">
2020-05-14 13:45:35 +03:00
{t("Session.Forwards.Options.Title")}
2020-05-14 03:01:01 +03:00
</StyledTableCell>
</TableRow>
</TableHead>
<TableBody>
{forwards.map((row) => (
<StyledTableRow key={row.forwardId}>
<StyledTableCell component="th" scope="row">
{forwards.indexOf(row) + 1}
</StyledTableCell>
<StyledTableCell>{row.from}</StyledTableCell>
<StyledTableCell>{row.to}</StyledTableCell>
<StyledTableCell align="right">
{row.options ? (
2020-05-14 13:45:35 +03:00
<Tooltip title={t("Session.Forwards.Options.Title")}>
<IconButton
aria-label="options"
size="small"
onClick={openOptionsDialog({
...row.options,
title: `${row.from} >>> ${row.to}`
})}
>
2020-05-14 03:01:01 +03:00
<DonutLargeRoundedIcon color="primary" />
</IconButton>
</Tooltip>
) : (
""
)}
</StyledTableCell>
</StyledTableRow>
))}
</TableBody>
</Table>
</TableContainer>
)
)}
</Grid>
<Grid item xs={12} sm={12} md={12}>
<br />
</Grid>
<Grid item xs={12} sm={12} md={12}>
2020-05-14 10:29:53 +03:00
<SessionForwardsHeaderComponent session={session} />
2020-05-14 03:01:01 +03:00
</Grid>
</Grid>
2020-05-14 00:55:00 +03:00
);
};
2020-05-14 10:29:53 +03:00
SessionForwardsComponent.propTypes = {
2020-05-14 03:01:01 +03:00
session: PropTypes.object.isRequired,
2020-05-14 13:45:35 +03:00
forwards: PropTypes.array,
openOptionsDialog: PropTypes.func.isRequired
2020-05-14 02:06:14 +03:00
};
2020-05-14 00:55:00 +03:00
2020-05-14 10:29:53 +03:00
export default SessionForwardsComponent;