mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 15:35:49 +01:00
Changes behavior for relative (only hover and context) and absolute links (internal vs external)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -197,10 +197,10 @@ class FileTree extends React.Component<Props, State> {
|
||||
<thead>
|
||||
<tr>
|
||||
<FixedWidthTh />
|
||||
<th>{t("sources.file-tree.name")}</th>
|
||||
<th className="is-hidden-mobile">{t("sources.file-tree.length")}</th>
|
||||
<th className="is-hidden-mobile">{t("sources.file-tree.commitDate")}</th>
|
||||
<th className="is-hidden-touch">{t("sources.file-tree.description")}</th>
|
||||
<th>{t("sources.fileTree.name")}</th>
|
||||
<th className="is-hidden-mobile">{t("sources.fileTree.length")}</th>
|
||||
<th className="is-hidden-mobile">{t("sources.fileTree.commitDate")}</th>
|
||||
<th className="is-hidden-touch">{t("sources.fileTree.description")}</th>
|
||||
{binder.hasExtension("repos.sources.tree.row.right") && <th className="is-hidden-mobile" />}
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
@@ -67,13 +67,13 @@ class FileTreeLeaf extends React.Component<Props> {
|
||||
return content(file);
|
||||
} else if (file.computationAborted) {
|
||||
return (
|
||||
<Tooltip location="top" message={t("sources.file-tree.computationAborted")}>
|
||||
<Tooltip location="top" message={t("sources.fileTree.computationAborted")}>
|
||||
<Icon name="question-circle" />
|
||||
</Tooltip>
|
||||
);
|
||||
} else if (file.partialResult) {
|
||||
return (
|
||||
<Tooltip location="top" message={t("sources.file-tree.notYetComputed")}>
|
||||
<Tooltip location="top" message={t("sources.fileTree.notYetComputed")}>
|
||||
<Icon name="hourglass" />
|
||||
</Tooltip>
|
||||
);
|
||||
|
||||
@@ -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<Props> = ({ 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 <a href={link}>{children}</a>;
|
||||
} else if (link.startsWith(".")) {
|
||||
return <Link to={createRelativeLink(baseUrl, link)}>{children}</Link>;
|
||||
} else if (link.startsWith("ssh://") && isLocalRepository(link)) {
|
||||
link = createRelativeLink(link);
|
||||
if (file.subRepository.revision) {
|
||||
link += "/code/sources/" + file.subRepository.revision;
|
||||
}
|
||||
return <Link to={link}>{children}</Link>;
|
||||
} else {
|
||||
return (
|
||||
<Tooltip location="top" message={t("sources.fileTree.subRepository") + "\n" + link}>
|
||||
{children}
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
}
|
||||
return <Link to={createFolderLink(baseUrl, file)}>{children}</Link>;
|
||||
|
||||
Reference in New Issue
Block a user