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";
|
import { Links } from "./hal";
|
||||||
|
|
||||||
// TODO ?? check ?? links
|
|
||||||
export type SubRepository = {
|
export type SubRepository = {
|
||||||
repositoryUrl: string;
|
repositoryUrl: string;
|
||||||
browserUrl: string;
|
browserUrl: string;
|
||||||
@@ -39,7 +38,7 @@ export type File = {
|
|||||||
revision: string;
|
revision: string;
|
||||||
length?: number;
|
length?: number;
|
||||||
commitDate?: string;
|
commitDate?: string;
|
||||||
subRepository?: SubRepository; // TODO
|
subRepository?: SubRepository;
|
||||||
partialResult?: boolean;
|
partialResult?: boolean;
|
||||||
computationAborted?: boolean;
|
computationAborted?: boolean;
|
||||||
truncated?: boolean;
|
truncated?: boolean;
|
||||||
|
|||||||
@@ -142,14 +142,14 @@
|
|||||||
"dangerZone": "Gefahrenzone"
|
"dangerZone": "Gefahrenzone"
|
||||||
},
|
},
|
||||||
"sources": {
|
"sources": {
|
||||||
"file-tree": {
|
"fileTree": {
|
||||||
"name": "Name",
|
"name": "Name",
|
||||||
"length": "Größe",
|
"length": "Größe",
|
||||||
"commitDate": "Commitdatum",
|
"commitDate": "Commitdatum",
|
||||||
"description": "Beschreibung",
|
"description": "Beschreibung",
|
||||||
"branch": "Branch",
|
|
||||||
"notYetComputed": "Noch nicht berechnet; Der Wert wird in Kürze aktualisiert",
|
"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": {
|
"content": {
|
||||||
"historyButton": "History",
|
"historyButton": "History",
|
||||||
|
|||||||
@@ -142,14 +142,14 @@
|
|||||||
"dangerZone": "Danger Zone"
|
"dangerZone": "Danger Zone"
|
||||||
},
|
},
|
||||||
"sources": {
|
"sources": {
|
||||||
"file-tree": {
|
"fileTree": {
|
||||||
"name": "Name",
|
"name": "Name",
|
||||||
"length": "Length",
|
"length": "Length",
|
||||||
"commitDate": "Commit date",
|
"commitDate": "Commit date",
|
||||||
"description": "Description",
|
"description": "Description",
|
||||||
"branch": "Branch",
|
|
||||||
"notYetComputed": "Not yet computed, will be updated in a short while",
|
"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": {
|
"content": {
|
||||||
"historyButton": "History",
|
"historyButton": "History",
|
||||||
|
|||||||
@@ -103,14 +103,14 @@
|
|||||||
"initializeRepository": "Initialize repository"
|
"initializeRepository": "Initialize repository"
|
||||||
},
|
},
|
||||||
"sources": {
|
"sources": {
|
||||||
"file-tree": {
|
"fileTree": {
|
||||||
"name": "Nombre",
|
"name": "Nombre",
|
||||||
"length": "Longitud",
|
"length": "Longitud",
|
||||||
"commitDate": "Fecha de cometer",
|
"commitDate": "Fecha de cometer",
|
||||||
"description": "Descripción",
|
"description": "Descripción",
|
||||||
"branch": "Rama",
|
|
||||||
"notYetComputed": "Aún no calculado, se actualizará en poco tiempo",
|
"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": {
|
"content": {
|
||||||
"historyButton": "Historia",
|
"historyButton": "Historia",
|
||||||
|
|||||||
@@ -197,10 +197,10 @@ class FileTree extends React.Component<Props, State> {
|
|||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<FixedWidthTh />
|
<FixedWidthTh />
|
||||||
<th>{t("sources.file-tree.name")}</th>
|
<th>{t("sources.fileTree.name")}</th>
|
||||||
<th className="is-hidden-mobile">{t("sources.file-tree.length")}</th>
|
<th className="is-hidden-mobile">{t("sources.fileTree.length")}</th>
|
||||||
<th className="is-hidden-mobile">{t("sources.file-tree.commitDate")}</th>
|
<th className="is-hidden-mobile">{t("sources.fileTree.commitDate")}</th>
|
||||||
<th className="is-hidden-touch">{t("sources.file-tree.description")}</th>
|
<th className="is-hidden-touch">{t("sources.fileTree.description")}</th>
|
||||||
{binder.hasExtension("repos.sources.tree.row.right") && <th className="is-hidden-mobile" />}
|
{binder.hasExtension("repos.sources.tree.row.right") && <th className="is-hidden-mobile" />}
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|||||||
@@ -67,13 +67,13 @@ class FileTreeLeaf extends React.Component<Props> {
|
|||||||
return content(file);
|
return content(file);
|
||||||
} else if (file.computationAborted) {
|
} else if (file.computationAborted) {
|
||||||
return (
|
return (
|
||||||
<Tooltip location="top" message={t("sources.file-tree.computationAborted")}>
|
<Tooltip location="top" message={t("sources.fileTree.computationAborted")}>
|
||||||
<Icon name="question-circle" />
|
<Icon name="question-circle" />
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
);
|
);
|
||||||
} else if (file.partialResult) {
|
} else if (file.partialResult) {
|
||||||
return (
|
return (
|
||||||
<Tooltip location="top" message={t("sources.file-tree.notYetComputed")}>
|
<Tooltip location="top" message={t("sources.fileTree.notYetComputed")}>
|
||||||
<Icon name="hourglass" />
|
<Icon name="hourglass" />
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -23,7 +23,9 @@
|
|||||||
*/
|
*/
|
||||||
import React, { FC, ReactNode } from "react";
|
import React, { FC, ReactNode } from "react";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
import { File } from "@scm-manager/ui-types";
|
import { File } from "@scm-manager/ui-types";
|
||||||
|
import { Tooltip } from "@scm-manager/ui-components";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
baseUrl: string;
|
baseUrl: string;
|
||||||
@@ -31,6 +33,24 @@ type Props = {
|
|||||||
children: ReactNode;
|
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) => {
|
const createFolderLink = (base: string, file: File) => {
|
||||||
let link = base;
|
let link = base;
|
||||||
if (file.path) {
|
if (file.path) {
|
||||||
@@ -46,22 +66,30 @@ const createFolderLink = (base: string, file: File) => {
|
|||||||
return link;
|
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 FileLink: FC<Props> = ({ baseUrl, file, children }) => {
|
||||||
|
const [t] = useTranslation("repos");
|
||||||
if (file?.subRepository?.repositoryUrl) {
|
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 (link.startsWith("http://") || link.startsWith("https://")) {
|
||||||
|
if (file.subRepository.revision && isLocalRepository(link)) {
|
||||||
|
link += "/code/sources/" + file.subRepository.revision;
|
||||||
|
}
|
||||||
return <a href={link}>{children}</a>;
|
return <a href={link}>{children}</a>;
|
||||||
} else if (link.startsWith(".")) {
|
} else if (link.startsWith("ssh://") && isLocalRepository(link)) {
|
||||||
return <Link to={createRelativeLink(baseUrl, link)}>{children}</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>;
|
return <Link to={createFolderLink(baseUrl, file)}>{children}</Link>;
|
||||||
|
|||||||
Reference in New Issue
Block a user