mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-15 09:46:16 +01:00
Changes behavior for relative (only hover and context) and absolute links (internal vs external)
This commit is contained in:
@@ -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