import {autobind} from "core-decorators"; import {observable} from "mobx"; import {observer} from "mobx-react"; import * as React from "react"; import {injectStyle} from "../../theming"; import style from "./style/error-center.css"; export type ErrorCenterStyle = Partial; export interface ErrorCenterProps { areErrorsVisible?: boolean; classNames?: ErrorCenterStyle; errors?: string[]; numberDisplayed?: number; source?: {onerror: (e: string) => void}; } @injectStyle("errorCenter") @autobind @observer export class ErrorCenter extends React.Component { @observable areErrorsVisible = this.props.areErrorsVisible || false; @observable errors = this.props.errors || []; componentWillMount() { (this.props.source || window).onerror = (e => this.errors.push(e)); } toggleVisible() { this.areErrorsVisible = !this.areErrorsVisible; } renderErrors() { const {numberDisplayed = 3, classNames} = this.props; const errorLength = this.errors.length; return (
error{errorLength}
{window.location.reload(); }}>refresh {`keyboard_arrow_${this.areErrorsVisible ? "down" : "up"}`} this.errors = []}>delete
    {this.areErrorsVisible ? this.errors.slice(errorLength - numberDisplayed, errorLength).map((e, i) =>
  • {e}
  • ) : null}
); } render() { return 0 < this.errors.length ? this.renderErrors() : null; } }