import Button from '@material-ui/core/Button'; import CircularProgress from '@material-ui/core/CircularProgress'; import Dialog from '@material-ui/core/Dialog'; import DialogActions from '@material-ui/core/DialogActions'; import DialogContent from '@material-ui/core/DialogContent'; import DialogTitle from '@material-ui/core/DialogTitle'; import ErrorIcon from '@material-ui/icons/Error'; import Grid from '@material-ui/core/Grid'; import PropTypes from 'prop-types'; import React from 'react'; import Switch from '@material-ui/core/Switch'; import Tooltip from '@material-ui/core/Tooltip'; import Typography from '@material-ui/core/Typography'; import _each from 'lodash/each'; import _get from 'lodash/get'; import _isEmpty from 'lodash/isEmpty'; import _map from 'lodash/map'; import _reduce from 'lodash/reduce'; import _take from 'lodash/take'; import { friendlyTitle } from './util/Utils.js'; // max characters we display for error messages before truncating them const maxErrorLength = 500; class ErrorModal extends React.Component { state = { truncateErrors: true, open: false, scroll: 'paper', }; handleClickOpen = () => { this.setState({ open: true }); }; handleClose = () => { this.setState({ open: false }); }; toggleTruncateErrors = () => { this.setState({ truncateErrors: !this.state.truncateErrors }); } processErrorData = errorsByPod => { let shouldTruncate = false; let byPodAndContainer = _map(errorsByPod, (podErrors, pod) => { let byContainer = _reduce(podErrors.errors, (errors, err) => { if (!_isEmpty(err.container)) { let c = err.container; if (_isEmpty(errors[c.container])) { errors[c.container] = []; } let errMsg = c.message; if (errMsg.length > maxErrorLength) { shouldTruncate = true; c.truncatedMessage = _take(errMsg, maxErrorLength).join("") + "..."; } errors[c.container].push(c); } return errors; }, {}); return { pod, byContainer }; }); return { byPodAndContainer, shouldTruncate }; } renderContainerErrors = (pod, errorsByContainer) => { if (_isEmpty(errorsByContainer)) { return "No messages to display"; } return _map(errorsByContainer, (errors, container) => (
{!er.reason ? null : er.reason + ": "} {message}