2019-02-26 17:08:33 +01:00
|
|
|
// @flow
|
|
|
|
|
import React from "react";
|
2019-02-27 14:28:20 +01:00
|
|
|
import {BackendError} from "./errors";
|
2019-02-26 17:08:33 +01:00
|
|
|
import classNames from "classnames";
|
2019-02-27 14:28:20 +01:00
|
|
|
import Notification from "./Notification";
|
2019-02-26 17:08:33 +01:00
|
|
|
|
2019-02-27 14:28:20 +01:00
|
|
|
import {translate} from "react-i18next";
|
2019-02-26 17:08:33 +01:00
|
|
|
|
|
|
|
|
type Props = { error: BackendError, t: string => string };
|
|
|
|
|
type State = { collapsed: boolean };
|
|
|
|
|
|
|
|
|
|
class BackendErrorNotification extends React.Component<Props, State> {
|
|
|
|
|
constructor(props: Props) {
|
|
|
|
|
super(props);
|
|
|
|
|
this.state = { collapsed: true };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
const { collapsed } = this.state;
|
|
|
|
|
const icon = collapsed ? "fa-angle-right" : "fa-angle-down";
|
|
|
|
|
|
|
|
|
|
return (
|
2019-02-27 14:28:20 +01:00
|
|
|
<Notification type="danger">
|
2019-02-26 17:08:33 +01:00
|
|
|
<div className="content">
|
2019-02-27 10:45:10 +01:00
|
|
|
<p className="subtitle">
|
2019-02-26 17:08:33 +01:00
|
|
|
<span
|
|
|
|
|
onClick={() => {
|
|
|
|
|
this.setState({ collapsed: !this.state.collapsed });
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<i className={classNames("fa", icon)} />
|
|
|
|
|
|
|
|
|
|
{this.renderErrorMessage()}
|
|
|
|
|
</span>
|
|
|
|
|
</p>
|
|
|
|
|
{this.renderUncollapsed()}
|
|
|
|
|
</div>
|
2019-02-27 14:28:20 +01:00
|
|
|
</Notification>
|
2019-02-26 17:08:33 +01:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderErrorMessage = () => {
|
|
|
|
|
const { error, t } = this.props;
|
|
|
|
|
const translation = t("errors." + error.errorCode);
|
|
|
|
|
if (translation === error.errorCode) {
|
|
|
|
|
return error.message;
|
|
|
|
|
}
|
|
|
|
|
return translation;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
renderUncollapsed = () => {
|
2019-02-27 10:45:10 +01:00
|
|
|
const { error, t } = this.props;
|
2019-02-26 17:08:33 +01:00
|
|
|
if (!this.state.collapsed) {
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<p>
|
2019-02-27 10:45:10 +01:00
|
|
|
<strong>{t("errors.context")}</strong>
|
2019-02-26 17:08:33 +01:00
|
|
|
</p>
|
|
|
|
|
<ul>
|
|
|
|
|
{error.context.map((context, index) => {
|
|
|
|
|
return (
|
|
|
|
|
<li key={index}>
|
|
|
|
|
<strong>{context.type}:</strong> {context.id}
|
|
|
|
|
</li>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</ul>
|
|
|
|
|
{this.renderMoreInformationLink(error)}
|
|
|
|
|
<div className="level is-size-7">
|
2019-02-27 10:45:10 +01:00
|
|
|
<div className="left">{t("errors.errorCode")} {error.errorCode}</div>
|
|
|
|
|
<div className="right">{t("errors.transactionId")} {error.transactionId}</div>
|
2019-02-26 17:08:33 +01:00
|
|
|
</div>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
renderMoreInformationLink = (error: BackendError) => {
|
2019-02-27 10:45:10 +01:00
|
|
|
const { t } = this.props;
|
2019-02-26 17:08:33 +01:00
|
|
|
if (error.url) {
|
|
|
|
|
return (
|
|
|
|
|
<p>
|
2019-02-27 10:45:10 +01:00
|
|
|
{t("errors.moreInfo")}{" "}
|
2019-02-26 17:08:33 +01:00
|
|
|
<a href={error.url} target="_blank">
|
|
|
|
|
{error.errorCode}
|
|
|
|
|
</a>
|
|
|
|
|
</p>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default translate("plugins")(BackendErrorNotification);
|