diff --git a/scm-ui/ui-types/src/Sources.ts b/scm-ui/ui-types/src/Sources.ts index 02443475b2..b6b58b516a 100644 --- a/scm-ui/ui-types/src/Sources.ts +++ b/scm-ui/ui-types/src/Sources.ts @@ -24,7 +24,6 @@ import { Links } from "./hal"; -// TODO ?? check ?? links export type SubRepository = { repositoryUrl: string; browserUrl: string; @@ -39,7 +38,7 @@ export type File = { revision: string; length?: number; commitDate?: string; - subRepository?: SubRepository; // TODO + subRepository?: SubRepository; partialResult?: boolean; computationAborted?: boolean; truncated?: boolean; diff --git a/scm-ui/ui-webapp/public/locales/de/repos.json b/scm-ui/ui-webapp/public/locales/de/repos.json index 658cf86d8a..a2f9f21495 100644 --- a/scm-ui/ui-webapp/public/locales/de/repos.json +++ b/scm-ui/ui-webapp/public/locales/de/repos.json @@ -142,14 +142,14 @@ "dangerZone": "Gefahrenzone" }, "sources": { - "file-tree": { + "fileTree": { "name": "Name", "length": "Größe", "commitDate": "Commitdatum", "description": "Beschreibung", - "branch": "Branch", "notYetComputed": "Noch nicht berechnet; Der Wert wird in Kürze aktualisiert", - "computationAborted": "Die Berechnung dauert zu lange und wurde abgebrochen" + "computationAborted": "Die Berechnung dauert zu lange und wurde abgebrochen", + "subRepository": "Subrepository:" }, "content": { "historyButton": "History", diff --git a/scm-ui/ui-webapp/public/locales/en/repos.json b/scm-ui/ui-webapp/public/locales/en/repos.json index ddd889c512..cb3e79adc5 100644 --- a/scm-ui/ui-webapp/public/locales/en/repos.json +++ b/scm-ui/ui-webapp/public/locales/en/repos.json @@ -142,14 +142,14 @@ "dangerZone": "Danger Zone" }, "sources": { - "file-tree": { + "fileTree": { "name": "Name", "length": "Length", "commitDate": "Commit date", "description": "Description", - "branch": "Branch", "notYetComputed": "Not yet computed, will be updated in a short while", - "computationAborted": "The computation took too long and was aborted" + "computationAborted": "The computation took too long and was aborted", + "subRepository": "Subrepository:" }, "content": { "historyButton": "History", diff --git a/scm-ui/ui-webapp/public/locales/es/repos.json b/scm-ui/ui-webapp/public/locales/es/repos.json index ddada3f8c3..2fcd690fa3 100644 --- a/scm-ui/ui-webapp/public/locales/es/repos.json +++ b/scm-ui/ui-webapp/public/locales/es/repos.json @@ -103,14 +103,14 @@ "initializeRepository": "Initialize repository" }, "sources": { - "file-tree": { + "fileTree": { "name": "Nombre", "length": "Longitud", "commitDate": "Fecha de cometer", "description": "Descripción", - "branch": "Rama", "notYetComputed": "Aún no calculado, se actualizará en poco tiempo", - "computationAborted": "El cálculo tomó demasiado tiempo y fue abortado" + "computationAborted": "El cálculo tomó demasiado tiempo y fue abortado", + "subRepository": "Subrepositorio:" }, "content": { "historyButton": "Historia", diff --git a/scm-ui/ui-webapp/src/repos/sources/components/FileTree.tsx b/scm-ui/ui-webapp/src/repos/sources/components/FileTree.tsx index 3d38cfd596..ac3221c28f 100644 --- a/scm-ui/ui-webapp/src/repos/sources/components/FileTree.tsx +++ b/scm-ui/ui-webapp/src/repos/sources/components/FileTree.tsx @@ -197,10 +197,10 @@ class FileTree extends React.Component { - {t("sources.file-tree.name")} - {t("sources.file-tree.length")} - {t("sources.file-tree.commitDate")} - {t("sources.file-tree.description")} + {t("sources.fileTree.name")} + {t("sources.fileTree.length")} + {t("sources.fileTree.commitDate")} + {t("sources.fileTree.description")} {binder.hasExtension("repos.sources.tree.row.right") && } diff --git a/scm-ui/ui-webapp/src/repos/sources/components/FileTreeLeaf.tsx b/scm-ui/ui-webapp/src/repos/sources/components/FileTreeLeaf.tsx index 129b0da997..33c566ef2c 100644 --- a/scm-ui/ui-webapp/src/repos/sources/components/FileTreeLeaf.tsx +++ b/scm-ui/ui-webapp/src/repos/sources/components/FileTreeLeaf.tsx @@ -67,13 +67,13 @@ class FileTreeLeaf extends React.Component { return content(file); } else if (file.computationAborted) { return ( - + ); } else if (file.partialResult) { return ( - + ); diff --git a/scm-ui/ui-webapp/src/repos/sources/components/content/FileLink.tsx b/scm-ui/ui-webapp/src/repos/sources/components/content/FileLink.tsx index d4b31edf19..063476908a 100644 --- a/scm-ui/ui-webapp/src/repos/sources/components/content/FileLink.tsx +++ b/scm-ui/ui-webapp/src/repos/sources/components/content/FileLink.tsx @@ -23,7 +23,9 @@ */ import React, { FC, ReactNode } from "react"; import { Link } from "react-router-dom"; +import { useTranslation } from "react-i18next"; import { File } from "@scm-manager/ui-types"; +import { Tooltip } from "@scm-manager/ui-components"; type Props = { baseUrl: string; @@ -31,6 +33,24 @@ type Props = { children: ReactNode; }; +const isLocalRepository = (repositoryUrl: string) => { + let host = repositoryUrl.split("/")[2]; + if (host.includes("@")) { + // remove prefix + host = host.split("@")[1]; + } + // remove port + host = host.split(":")[0]; + // remove query + host = host.split("?")[0]; + return host === window.location.hostname; +}; + +const createRelativeLink = (repositoryUrl: string) => { + const paths = repositoryUrl.split("/"); + return "/" + paths.slice(3).join("/"); +}; + const createFolderLink = (base: string, file: File) => { let link = base; if (file.path) { @@ -46,22 +66,30 @@ const createFolderLink = (base: string, file: File) => { return link; }; -const createRelativeLink = (base: string, path: string) => { - let link = base; - link += path.split(".").join(""); - if (!link.endsWith("/")) { - link += "/"; - } - return link; -}; - const FileLink: FC = ({ baseUrl, file, children }) => { + const [t] = useTranslation("repos"); if (file?.subRepository?.repositoryUrl) { - const link = file.subRepository.repositoryUrl; + let link = file.subRepository.repositoryUrl; + if (file.subRepository.browserUrl) { + link = file.subRepository.browserUrl; + } if (link.startsWith("http://") || link.startsWith("https://")) { + if (file.subRepository.revision && isLocalRepository(link)) { + link += "/code/sources/" + file.subRepository.revision; + } return {children}; - } else if (link.startsWith(".")) { - return {children}; + } else if (link.startsWith("ssh://") && isLocalRepository(link)) { + link = createRelativeLink(link); + if (file.subRepository.revision) { + link += "/code/sources/" + file.subRepository.revision; + } + return {children}; + } else { + return ( + + {children} + + ); } } return {children};