From 510c295e004db06897f39e1d3825a538ad28a136 Mon Sep 17 00:00:00 2001 From: Philipp Czora Date: Wed, 27 Feb 2019 10:45:10 +0100 Subject: [PATCH] Refactored ErrorNotification/ErrorPage Added i18n for error codes --- .../src/BackendErrorNotification.js | 18 +++---- .../ui-components/src/CollapsibleErrorPage.js | 44 --------------- .../ui-components/src/ErrorNotification.js | 2 +- .../packages/ui-components/src/ErrorPage.js | 13 ++++- .../packages/ui-components/src/index.js | 1 - scm-ui/src/config/containers/GlobalConfig.js | 53 ++++++++++++------- scm-ui/src/repos/containers/RepositoryRoot.js | 17 +++--- .../main/resources/locales/de/plugins.json | 10 +++- .../main/resources/locales/en/plugins.json | 10 +++- 9 files changed, 77 insertions(+), 91 deletions(-) delete mode 100644 scm-ui-components/packages/ui-components/src/CollapsibleErrorPage.js diff --git a/scm-ui-components/packages/ui-components/src/BackendErrorNotification.js b/scm-ui-components/packages/ui-components/src/BackendErrorNotification.js index cf4d0def0d..7540b17030 100644 --- a/scm-ui-components/packages/ui-components/src/BackendErrorNotification.js +++ b/scm-ui-components/packages/ui-components/src/BackendErrorNotification.js @@ -18,13 +18,9 @@ class BackendErrorNotification extends React.Component { const { collapsed } = this.state; const icon = collapsed ? "fa-angle-right" : "fa-angle-down"; - // TODO error page - // we have currently the ErrorNotification, which is often wrapped by the ErrorPage - // the ErrorPage has often a SubTitle like "Unkwown xzy error", which is no longer always the case - // if the error is a BackendError its not fully unknown return (
-

+

{ this.setState({ collapsed: !this.state.collapsed }); @@ -50,12 +46,12 @@ class BackendErrorNotification extends React.Component { }; renderUncollapsed = () => { - const { error } = this.props; + const { error, t } = this.props; if (!this.state.collapsed) { return ( <>

- Context: + {t("errors.context")}

    {error.context.map((context, index) => { @@ -68,8 +64,8 @@ class BackendErrorNotification extends React.Component {
{this.renderMoreInformationLink(error)}
-
ErrorCode: {error.errorCode}
-
TransactionId: {error.transactionId}
+
{t("errors.errorCode")} {error.errorCode}
+
{t("errors.transactionId")} {error.transactionId}
); @@ -78,11 +74,11 @@ class BackendErrorNotification extends React.Component { }; renderMoreInformationLink = (error: BackendError) => { + const { t } = this.props; if (error.url) { - // TODO i18n return (

- For more information, see{" "} + {t("errors.moreInfo")}{" "} {error.errorCode} diff --git a/scm-ui-components/packages/ui-components/src/CollapsibleErrorPage.js b/scm-ui-components/packages/ui-components/src/CollapsibleErrorPage.js deleted file mode 100644 index c7c328fe6d..0000000000 --- a/scm-ui-components/packages/ui-components/src/CollapsibleErrorPage.js +++ /dev/null @@ -1,44 +0,0 @@ -//@flow -import React from "react"; -import ErrorNotification from "./ErrorNotification"; -import { translate } from "react-i18next"; - -type Props = { - error: Error, - title: string, - subtitle?: string, - t: string => string -}; - -type State = { - collapsed: boolean -}; - -class CollapsibleErrorPage extends React.Component { - constructor(props: Props) { - super(props); - this.state = { - collapsed: true - }; - } - - - - render() { - const { title, error, t } = this.props; - - return ( -

-
- {this.setState({collapsed: !this.state.collapsed})}}> -

{title}

-
- - -
-
- ); - } -} - -export default translate("plugins")(CollapsibleErrorPage); diff --git a/scm-ui-components/packages/ui-components/src/ErrorNotification.js b/scm-ui-components/packages/ui-components/src/ErrorNotification.js index ab7d8ad882..380ea04082 100644 --- a/scm-ui-components/packages/ui-components/src/ErrorNotification.js +++ b/scm-ui-components/packages/ui-components/src/ErrorNotification.js @@ -39,4 +39,4 @@ class ErrorNotification extends React.Component { } } -export default translate("commons")(ErrorNotification); +export default translate("commons")(ErrorNotification); diff --git a/scm-ui-components/packages/ui-components/src/ErrorPage.js b/scm-ui-components/packages/ui-components/src/ErrorPage.js index 196319681c..8947e702c8 100644 --- a/scm-ui-components/packages/ui-components/src/ErrorPage.js +++ b/scm-ui-components/packages/ui-components/src/ErrorPage.js @@ -1,6 +1,7 @@ //@flow import React from "react"; import ErrorNotification from "./ErrorNotification"; +import { BackendError } from "./errors"; type Props = { error: Error, @@ -10,18 +11,26 @@ type Props = { class ErrorPage extends React.Component { render() { - const { title, subtitle, error } = this.props; + const { title, error } = this.props; return (

{title}

-

{subtitle}

+ {this.renderSubtitle()}
); } + + renderSubtitle = () => { + const { error, subtitle } = this.props; + if (error instanceof BackendError) { + return null; + } + return

{subtitle}

+ } } export default ErrorPage; diff --git a/scm-ui-components/packages/ui-components/src/index.js b/scm-ui-components/packages/ui-components/src/index.js index 4bf6c57338..b403ea78b7 100644 --- a/scm-ui-components/packages/ui-components/src/index.js +++ b/scm-ui-components/packages/ui-components/src/index.js @@ -9,7 +9,6 @@ export { validation, urls, repositories }; export { default as DateFromNow } from "./DateFromNow.js"; export { default as ErrorNotification } from "./ErrorNotification.js"; export { default as ErrorPage } from "./ErrorPage.js"; -export { default as CollapsibleErrorPage } from "./CollapsibleErrorPage.js"; export { default as Image } from "./Image.js"; export { default as Loading } from "./Loading.js"; export { default as Logo } from "./Logo.js"; diff --git a/scm-ui/src/config/containers/GlobalConfig.js b/scm-ui/src/config/containers/GlobalConfig.js index eac8e27bee..de01e98aab 100644 --- a/scm-ui/src/config/containers/GlobalConfig.js +++ b/scm-ui/src/config/containers/GlobalConfig.js @@ -1,7 +1,11 @@ // @flow import React from "react"; import { translate } from "react-i18next"; -import { Title, ErrorPage, Loading } from "@scm-manager/ui-components"; +import { + Title, + Loading, + ErrorNotification +} from "@scm-manager/ui-components"; import { fetchConfig, getFetchConfigFailure, @@ -73,18 +77,8 @@ class GlobalConfig extends React.Component { }; render() { - const { t, error, loading, config, configUpdatePermission } = this.props; + const { t, loading } = this.props; - if (error) { - return ( - - ); - } if (loading) { return ; } @@ -92,16 +86,37 @@ class GlobalConfig extends React.Component { return (
- {this.renderConfigChangedNotification()} - <ConfigForm - submitForm={config => this.modifyConfig(config)} - config={config} - loading={loading} - configUpdatePermission={configUpdatePermission} - /> + {this.renderError()} + {this.renderContent()} </div> ); } + + renderError = () => { + const { error } = this.props; + if (error) { + return <ErrorNotification error={error} />; + } + return null; + }; + + renderContent = () => { + const { error, loading, config, configUpdatePermission } = this.props; + if (!error) { + return ( + <> + {this.renderConfigChangedNotification()} + <ConfigForm + submitForm={config => this.modifyConfig(config)} + config={config} + loading={loading} + configUpdatePermission={configUpdatePermission} + /> + </> + ); + } + return null; + }; } const mapDispatchToProps = dispatch => { diff --git a/scm-ui/src/repos/containers/RepositoryRoot.js b/scm-ui/src/repos/containers/RepositoryRoot.js index e8874675d5..08d6aa9380 100644 --- a/scm-ui/src/repos/containers/RepositoryRoot.js +++ b/scm-ui/src/repos/containers/RepositoryRoot.js @@ -18,7 +18,7 @@ import { SubNavigation, NavLink, Page, - Section + Section, ErrorPage } from "@scm-manager/ui-components"; import { translate } from "react-i18next"; import RepositoryDetails from "../components/RepositoryDetails"; @@ -81,17 +81,12 @@ class RepositoryRoot extends React.Component<Props> { render() { const { loading, error, indexLinks, repository, t } = this.props; - // if (error) { - // return <ErrorPage - // title={t("repositoryRoot.errorTitle")} - // subtitle={t("repositoryRoot.errorSubtitle")} - // error={error} - // /> - // } if (error) { - return ( - <CollapsibleErrorPage title={t("repositoryRoot.errorTitle")} error={error} /> - ); + return <ErrorPage + title={t("repositoryRoot.errorTitle")} + subtitle={t("repositoryRoot.errorSubtitle")} + error={error} + /> } if (!repository || loading) { diff --git a/scm-webapp/src/main/resources/locales/de/plugins.json b/scm-webapp/src/main/resources/locales/de/plugins.json index 1f2dcc9a41..159194c0dc 100644 --- a/scm-webapp/src/main/resources/locales/de/plugins.json +++ b/scm-webapp/src/main/resources/locales/de/plugins.json @@ -89,6 +89,14 @@ } }, "errors": { - "AGR7UzkhA1": "Nicht gefunden" + "context": "Kontext", + "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" } } diff --git a/scm-webapp/src/main/resources/locales/en/plugins.json b/scm-webapp/src/main/resources/locales/en/plugins.json index 6b1081f2d1..6319c5012e 100644 --- a/scm-webapp/src/main/resources/locales/en/plugins.json +++ b/scm-webapp/src/main/resources/locales/en/plugins.json @@ -89,6 +89,14 @@ } }, "errors": { - "AGR7UzkhA1": "Not found" + "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" } }