Added error descriptions & removed collapsability (according to review)

This commit is contained in:
Philipp Czora
2019-03-01 13:16:54 +01:00
parent 536c5a74c6
commit 5d375b7fb4
3 changed files with 85 additions and 60 deletions

View File

@@ -1,79 +1,74 @@
// @flow
import React from "react";
import {BackendError} from "./errors";
import classNames from "classnames";
import { BackendError } from "./errors";
import Notification from "./Notification";
import {translate} from "react-i18next";
import { translate } from "react-i18next";
type Props = { error: BackendError, t: string => string };
type State = { collapsed: boolean };
class BackendErrorNotification extends React.Component<Props, State> {
class BackendErrorNotification extends React.Component<Props> {
constructor(props: Props) {
super(props);
this.state = { collapsed: true };
}
render() {
const { collapsed } = this.state;
const icon = collapsed ? "fa-angle-right" : "fa-angle-down";
return (
<Notification type="danger">
<div className="content">
<p className="subtitle">
<span
onClick={() => {
this.setState({ collapsed: !this.state.collapsed });
}}
>
<i className={classNames("fa", icon)} />
{this.renderErrorMessage()}
</span>
</p>
{this.renderUncollapsed()}
</div>
<div className="content">
<p className="subtitle">{this.renderErrorName()}</p>
<p>{this.renderErrorDescription()}</p>
{this.renderMetadata()}
</div>
</Notification>
);
}
renderErrorMessage = () => {
renderErrorName = () => {
const { error, t } = this.props;
const translation = t("errors." + error.errorCode);
const translation = t("errors." + error.errorCode + ".displayName");
if (translation === error.errorCode) {
return error.message;
}
return translation;
};
renderUncollapsed = () => {
renderErrorDescription = () => {
const { error, t } = this.props;
if (!this.state.collapsed) {
return (
<>
<p>
<strong>{t("errors.context")}</strong>
</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">
<div className="left">{t("errors.errorCode")} {error.errorCode}</div>
<div className="right">{t("errors.transactionId")} {error.transactionId}</div>
</div>
</>
);
const translation = t("errors." + error.errorCode + ".description");
if (translation === error.errorCode) {
return "";
}
return null;
return translation;
};
renderMetadata = () => {
const { error, t } = this.props;
return (
<>
<p>
<strong>{t("errors.context")}</strong>
</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">
<div className="left">
{t("errors.transactionId")} {error.transactionId}
</div>
<div className="right">
{t("errors.errorCode")} {error.errorCode}
</div>
</div>
</>
);
};
renderMoreInformationLink = (error: BackendError) => {

View File

@@ -93,10 +93,25 @@
"errorCode": "Fehlercode",
"transactionId": "Transaktions-ID",
"moreInfo": "Für mehr Informationen, siehe",
"AGR7UzkhA1": "Nicht gefunden",
"FtR7UznKU1": "Existiert bereits",
"9BR7qpDAe1": "Passwortänderung nicht erlaubt",
"2wR7UzpPG1": "Konkurrierende Änderungen",
"9SR8G0kmU1": "Feature nicht unterstützt"
"AGR7UzkhA1": {
"displayName": "Nicht gefunden",
"description": "Die angefragte Entität konnte nicht gefunden werden. Möglicherweise wurde es in einer weiteren Session gelöscht."
},
"FtR7UznKU1": {
"displayName": "Existiert bereits",
"description": "Eine Entität mit den gegebenen Schlüsselwerten existiert bereits"
},
"9BR7qpDAe1": {
"displayName": "Passwortänderung nicht erlaubt",
"description": "Sie haben nicht die Berechtigung, das Passwort zu ändern"
},
"2wR7UzpPG1": {
"displayName": "Konkurrierende Änderungen",
"description": "Die Entität wurde konkurrierend von einem anderen Benutzer oder einem anderen Prozess modifiziert. Bitte laden sie die Entität erneut."
},
"9SR8G0kmU1": {
"displayName": "Feature nicht unterstützt",
"description": "Das Versionsverwaltungssystem dieses Repo unterstützt das angefragte Feature nicht."
}
}
}

View File

@@ -89,14 +89,29 @@
}
},
"errors": {
"context": "context",
"context": "Context",
"errorCode": "Error Code",
"transactionId": "Transaction ID",
"moreInfo": "For more information, see",
"AGR7UzkhA1": "Not found",
"FtR7UznKU1": "Already exists",
"9BR7qpDAe1": "Password change not allowed",
"2wR7UzpPG1": "Concurrent modifications",
"9SR8G0kmU1": "Feature not supported"
"AGR7UzkhA1": {
"displayName": "Not found",
"description": "The requested entity could not be found. It may have been deleted in another session."
},
"FtR7UznKU1": {
"displayName": "Already exists",
"description": "There is already an entity with the same key values."
},
"9BR7qpDAe1": {
"displayName": "Password change not allowed",
"description": "You do not have the permission to change the password."
},
"2wR7UzpPG1": {
"displayName": "Concurrent modifications",
"description": "The entity has been modified concurrently by another user or another process. Please reload the entity."
},
"9SR8G0kmU1": {
"displayName": "Feature not supported",
"description": "The version control system for this repository does not support the requested feature."
}
}
}