From c3a5dd4ffbcecdf4dc600f007cd23a596f7a5f04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Pfeuffer?= Date: Wed, 24 Feb 2021 16:22:35 +0100 Subject: [PATCH] Add page for import logs --- .../scm/repository/RepositoryImportEvent.java | 2 + scm-ui/ui-api/src/import.ts | 32 +++++++++++++ scm-ui/ui-api/src/index.ts | 1 + scm-ui/ui-components/src/layout/Page.tsx | 2 +- .../ui-webapp/public/locales/de/commons.json | 3 ++ .../ui-webapp/public/locales/en/commons.json | 3 ++ scm-ui/ui-webapp/src/containers/Main.tsx | 2 + .../src/repos/importlog/ImportLog.tsx | 45 +++++++++++++++++++ .../api/v2/resources/IndexDtoGenerator.java | 1 + .../scm/api/v2/resources/ResourceLinks.java | 4 ++ 10 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 scm-ui/ui-api/src/import.ts create mode 100644 scm-ui/ui-webapp/src/repos/importlog/ImportLog.tsx diff --git a/scm-core/src/main/java/sonia/scm/repository/RepositoryImportEvent.java b/scm-core/src/main/java/sonia/scm/repository/RepositoryImportEvent.java index a8fefefef0..45be8caa0d 100644 --- a/scm-core/src/main/java/sonia/scm/repository/RepositoryImportEvent.java +++ b/scm-core/src/main/java/sonia/scm/repository/RepositoryImportEvent.java @@ -39,10 +39,12 @@ import sonia.scm.event.Event; @EqualsAndHashCode(callSuper = true) public class RepositoryImportEvent extends RepositoryEvent { + private final String logId; private final boolean failed; public RepositoryImportEvent(HandlerEventType eventType, Repository repository, boolean failed) { super(eventType, repository); + this.logId = repository.getId(); this.failed = failed; } } diff --git a/scm-ui/ui-api/src/import.ts b/scm-ui/ui-api/src/import.ts new file mode 100644 index 0000000000..f9c4e531e9 --- /dev/null +++ b/scm-ui/ui-api/src/import.ts @@ -0,0 +1,32 @@ +/* + * 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 { ApiResult, useRequiredIndexLink } from "./base"; +import { useQuery } from "react-query"; +import { apiClient } from "./apiclient"; + +export const useImportLog = (logId: string) : ApiResult => { + const link = useRequiredIndexLink("importLog").replace("{logId}", logId); + return useQuery(["importLog", logId], () => apiClient.get(link).then(response => response.text())); +} diff --git a/scm-ui/ui-api/src/index.ts b/scm-ui/ui-api/src/index.ts index 5429990ba4..69ede48603 100644 --- a/scm-ui/ui-api/src/index.ts +++ b/scm-ui/ui-api/src/index.ts @@ -43,6 +43,7 @@ export * from "./plugins"; export * from "./repository-roles"; export * from "./permissions"; export * from "./sources"; +export * from "./import"; export { default as ApiProvider } from "./ApiProvider"; export * from "./ApiProvider"; diff --git a/scm-ui/ui-components/src/layout/Page.tsx b/scm-ui/ui-components/src/layout/Page.tsx index 9f1e749912..22f8dcc85f 100644 --- a/scm-ui/ui-components/src/layout/Page.tsx +++ b/scm-ui/ui-components/src/layout/Page.tsx @@ -39,7 +39,7 @@ type Props = { afterTitle?: ReactNode; subtitle?: string; loading?: boolean; - error?: Error; + error?: Error | null; showContentOnError?: boolean; children: ReactNode; }; diff --git a/scm-ui/ui-webapp/public/locales/de/commons.json b/scm-ui/ui-webapp/public/locales/de/commons.json index c0b9cc8222..1728043152 100644 --- a/scm-ui/ui-webapp/public/locales/de/commons.json +++ b/scm-ui/ui-webapp/public/locales/de/commons.json @@ -121,5 +121,8 @@ }, "fileUpload": { "label": "Datei hochladen" + }, + "importLog": { + "title": "Importprotokoll" } } diff --git a/scm-ui/ui-webapp/public/locales/en/commons.json b/scm-ui/ui-webapp/public/locales/en/commons.json index 1f76ce87bd..2b98ab016d 100644 --- a/scm-ui/ui-webapp/public/locales/en/commons.json +++ b/scm-ui/ui-webapp/public/locales/en/commons.json @@ -122,5 +122,8 @@ }, "fileUpload": { "label": "Upload File" + }, + "importLog": { + "title": "Import Log" } } diff --git a/scm-ui/ui-webapp/src/containers/Main.tsx b/scm-ui/ui-webapp/src/containers/Main.tsx index 965610d668..3cffe27d01 100644 --- a/scm-ui/ui-webapp/src/containers/Main.tsx +++ b/scm-ui/ui-webapp/src/containers/Main.tsx @@ -48,6 +48,7 @@ import Admin from "../admin/containers/Admin"; import Profile from "./Profile"; import NamespaceRoot from "../repos/namespaces/containers/NamespaceRoot"; import ImportRepository from "../repos/containers/ImportRepository"; +import ImportLog from "../repos/importlog/ImportLog"; type Props = { me: Me; @@ -96,6 +97,7 @@ class Main extends React.Component { + { + const {logId} = useParams(); + const {isLoading, data, error} = useImportLog(logId); + const [t] = useTranslation("commons"); + + return +
{data ? data : null}
+
; +} + +export default ImportLog; diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/IndexDtoGenerator.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/IndexDtoGenerator.java index 599af7c6ba..6928f1fd08 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/IndexDtoGenerator.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/IndexDtoGenerator.java @@ -116,6 +116,7 @@ public class IndexDtoGenerator extends HalAppenderMapper { builder.single(link("repositoryTypes", resourceLinks.repositoryTypeCollection().self())); builder.single(link("namespaceStrategies", resourceLinks.namespaceStrategies().self())); builder.single(link("repositoryRoles", resourceLinks.repositoryRoleCollection().self())); + builder.single(link("importLog", resourceLinks.repository().importLog("IMPORT_LOG_ID").replace("IMPORT_LOG_ID", "{logId}"))); } else { builder.single(link("login", resourceLinks.authentication().jsonLogin())); } diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ResourceLinks.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ResourceLinks.java index 3115ded1f7..eefb323998 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ResourceLinks.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ResourceLinks.java @@ -377,6 +377,10 @@ class ResourceLinks { return repositoryImportLinkBuilder.method("getRepositoryImportResource").parameters().method("importFullRepository").parameters(type).href(); } + String importLog(String importLogId) { + return repositoryImportLinkBuilder.method("getRepositoryImportResource").parameters().method("getImportLog").parameters(importLogId).href(); + } + String archive(String namespace, String name) { return repositoryLinkBuilder.method("getRepositoryResource").parameters(namespace, name).method("archive").parameters().href(); }