machines accordion view update

master
Tudor Stanciu 2023-03-22 18:20:14 +02:00
parent 7115649f12
commit 6ad7abf3d1
6 changed files with 74 additions and 24 deletions

View File

@ -0,0 +1,42 @@
import React, { useMemo } from "react";
import PropTypes from "prop-types";
import Typography from "@material-ui/core/Typography";
import { makeStyles } from "@material-ui/core/styles";
const useStyles = makeStyles(theme => ({
panel: {
display: "flex"
},
label: {
marginRight: "4px"
},
data: {
fontWeight: theme.typography.fontWeightMedium
}
}));
const DataLabel = ({ label, data }) => {
const classes = useStyles();
const lbl = useMemo(
() => (label.endsWith(":") ? label : `${label}:`),
[label]
);
return (
<div className={classes.panel}>
<Typography variant="body2" className={classes.label}>
{lbl}
</Typography>
<Typography variant="body2" className={classes.data}>
{data}
</Typography>
</div>
);
};
DataLabel.propTypes = {
label: PropTypes.string.isRequired,
data: PropTypes.string
};
export default DataLabel;

View File

@ -0,0 +1,3 @@
import DataLabel from "./DataLabel";
export { DataLabel };

View File

@ -1,13 +1,15 @@
import React from "react"; import React from "react";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import Accordion from "@material-ui/core/Accordion"; import {
import AccordionSummary from "@material-ui/core/AccordionSummary"; Accordion,
import AccordionDetails from "@material-ui/core/AccordionDetails"; AccordionSummary,
import Checkbox from "@material-ui/core/Checkbox"; AccordionDetails,
import FormControlLabel from "@material-ui/core/FormControlLabel"; Grid
import Typography from "@material-ui/core/Typography"; } from "@material-ui/core";
import ExpandMoreIcon from "@material-ui/icons/ExpandMore"; import ExpandMoreIcon from "@material-ui/icons/ExpandMore";
import withStyles from "@material-ui/core/styles/withStyles"; import withStyles from "@material-ui/core/styles/withStyles";
import MachineLog from "./common/MachineLog";
import { DataLabel } from "../../../components/common";
const IconLeftAccordionSummary = withStyles({ const IconLeftAccordionSummary = withStyles({
expandIcon: { expandIcon: {
@ -15,7 +17,7 @@ const IconLeftAccordionSummary = withStyles({
} }
})(AccordionSummary); })(AccordionSummary);
const MachineAccordion = ({ machine }) => { const MachineAccordion = ({ machine, logs }) => {
return ( return (
<Accordion> <Accordion>
<IconLeftAccordionSummary <IconLeftAccordionSummary
@ -25,26 +27,25 @@ const MachineAccordion = ({ machine }) => {
id="additional-actions1-header" id="additional-actions1-header"
IconButtonProps={{ edge: "start" }} IconButtonProps={{ edge: "start" }}
> >
<FormControlLabel <Grid container>
aria-label="Acknowledge" <Grid item xs={12} md={6}>
onClick={event => event.stopPropagation()} <DataLabel
onFocus={event => event.stopPropagation()} label={"Full machine name"}
control={<Checkbox />} data={machine.fullMachineName}
label="I acknowledge that I should stop the click event propagation"
/> />
</Grid>
</Grid>
</IconLeftAccordionSummary> </IconLeftAccordionSummary>
<AccordionDetails> <AccordionDetails>
<Typography color="textSecondary"> <MachineLog logs={logs} />
The click event of the nested action will propagate up and expand the
accordion unless you explicitly stop it.
</Typography>
</AccordionDetails> </AccordionDetails>
</Accordion> </Accordion>
); );
}; };
MachineAccordion.propTypes = { MachineAccordion.propTypes = {
machine: PropTypes.array.isRequired machine: PropTypes.object.isRequired,
logs: PropTypes.array.isRequired
}; };
export default MachineAccordion; export default MachineAccordion;

View File

@ -150,7 +150,7 @@ const MachineContainer = ({ machine, viewMode }) => {
MachineContainer.propTypes = { MachineContainer.propTypes = {
machine: PropTypes.object.isRequired, machine: PropTypes.object.isRequired,
viewMode: PropTypes.bool.isRequired viewMode: PropTypes.string.isRequired
}; };
export default MachineContainer; export default MachineContainer;

View File

@ -31,7 +31,7 @@ const Machine = ({
}) => { }) => {
const [open, setOpen] = React.useState(false); const [open, setOpen] = React.useState(false);
const classes = useRowStyles(); const classes = useRowStyles();
const { mask, maskElements } = useSensitiveInfo(); const { mask } = useSensitiveInfo();
const topActions = useMemo( const topActions = useMemo(
() => actions.filter(a => a.top === true), () => actions.filter(a => a.top === true),
@ -90,7 +90,7 @@ const Machine = ({
<TableRow> <TableRow>
<TableCell style={{ paddingBottom: 0, paddingTop: 0 }} colSpan={6}> <TableCell style={{ paddingBottom: 0, paddingTop: 0 }} colSpan={6}>
<Collapse in={open} timeout="auto" unmountOnExit> <Collapse in={open} timeout="auto" unmountOnExit>
<MachineLog logs={maskElements(logs)} /> <MachineLog logs={logs} />
</Collapse> </Collapse>
</TableCell> </TableCell>
</TableRow> </TableRow>

View File

@ -1,13 +1,17 @@
import React, { useMemo } from "react"; import React, { useMemo } from "react";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import { Box } from "@material-ui/core"; import { Box } from "@material-ui/core";
import { useSensitiveInfo } from "../../../../hooks";
import { LazyLog, ScrollFollow } from "react-lazylog"; import { LazyLog, ScrollFollow } from "react-lazylog";
const MachineLog = ({ logs }) => { const MachineLog = ({ logs }) => {
const { maskElements } = useSensitiveInfo();
const displayLogs = useMemo( const displayLogs = useMemo(
() => (logs.length > 0 ? logs.join("\n") : "..."), () => (logs.length > 0 ? maskElements(logs).join("\n") : "..."),
[logs] [logs, maskElements]
); );
return ( return (
<Box margin={1}> <Box margin={1}>
<div style={{ height: 200 }}> <div style={{ height: 200 }}>