From e1196ac6a0ec07f55fad43da0b5212877456820b Mon Sep 17 00:00:00 2001 From: Eduard Heimbuch Date: Mon, 20 Jun 2022 17:49:41 +0200 Subject: [PATCH] Show dedicated Notfound page for invalid routes (#2070) --- gradle/changelog/404.yaml | 2 + scm-ui/ui-extensions/src/binder.ts | 2 +- .../ui-webapp/public/locales/de/commons.json | 3 +- .../ui-webapp/public/locales/en/commons.json | 3 +- .../ui-webapp/src/containers/NotFoundPage.tsx | 37 +++++++++++++++++++ scm-ui/ui-webapp/src/index.tsx | 2 + 6 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 gradle/changelog/404.yaml create mode 100644 scm-ui/ui-webapp/src/containers/NotFoundPage.tsx diff --git a/gradle/changelog/404.yaml b/gradle/changelog/404.yaml new file mode 100644 index 0000000000..d33a421fa3 --- /dev/null +++ b/gradle/changelog/404.yaml @@ -0,0 +1,2 @@ +- type: added + description: Show dedicated notfound page for invalid routes ([#2070](https://github.com/scm-manager/scm-manager/pull/2070)) diff --git a/scm-ui/ui-extensions/src/binder.ts b/scm-ui/ui-extensions/src/binder.ts index a41de04a14..9afd0a2f34 100644 --- a/scm-ui/ui-extensions/src/binder.ts +++ b/scm-ui/ui-extensions/src/binder.ts @@ -133,7 +133,7 @@ export class Binder { predicate, extension, extensionName: extensionName ? extensionName : "", - priority, + priority: priority || 0, } as ExtensionRegistration; this.extensionPoints[extensionPoint].push(registration); } diff --git a/scm-ui/ui-webapp/public/locales/de/commons.json b/scm-ui/ui-webapp/public/locales/de/commons.json index fb1c740342..ebd0278c70 100644 --- a/scm-ui/ui-webapp/public/locales/de/commons.json +++ b/scm-ui/ui-webapp/public/locales/de/commons.json @@ -260,5 +260,6 @@ }, "tag": { "delete": "Löschen" - } + }, + "pageNotFound": "Die angefragte Seite existiert nicht." } diff --git a/scm-ui/ui-webapp/public/locales/en/commons.json b/scm-ui/ui-webapp/public/locales/en/commons.json index 8665937830..465a41b789 100644 --- a/scm-ui/ui-webapp/public/locales/en/commons.json +++ b/scm-ui/ui-webapp/public/locales/en/commons.json @@ -261,5 +261,6 @@ }, "tag": { "delete": "Delete" - } + }, + "pageNotFound": "The requested page does not exist." } diff --git a/scm-ui/ui-webapp/src/containers/NotFoundPage.tsx b/scm-ui/ui-webapp/src/containers/NotFoundPage.tsx new file mode 100644 index 0000000000..44c600d71e --- /dev/null +++ b/scm-ui/ui-webapp/src/containers/NotFoundPage.tsx @@ -0,0 +1,37 @@ +/* + * MIT License + * + * Copyright (c) 2020-present Cloudogu GmbH and Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +import React, { FC } from "react"; +import { Notification, Page } from "@scm-manager/ui-components"; +import { useTranslation } from "react-i18next"; + +const NotFoundPage: FC = () => { + const [t] = useTranslation("commons"); + return ( + + 404: {t("pageNotFound")} + + ); +}; +export default NotFoundPage; diff --git a/scm-ui/ui-webapp/src/index.tsx b/scm-ui/ui-webapp/src/index.tsx index 95cef5f44e..ffacb27003 100644 --- a/scm-ui/ui-webapp/src/index.tsx +++ b/scm-ui/ui-webapp/src/index.tsx @@ -36,8 +36,10 @@ import ChangesetShortLink from "./repos/components/changesets/ChangesetShortLink import "./tokenExpired"; import { ApiProvider } from "@scm-manager/ui-api"; +import NotFoundPage from "./containers/NotFoundPage"; binder.bind("changeset.description.tokens", ChangesetShortLink); +binder.bind("main.route", NotFoundPage, { priority: -1 }); const root = document.getElementById("root"); if (!root) {