mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 06:55:47 +01:00
keep entered revision in source browser
This commit is contained in:
@@ -13,6 +13,7 @@ const styles = {
|
||||
|
||||
type Props = {
|
||||
tree: SourcesCollection,
|
||||
revision: string,
|
||||
path: string,
|
||||
baseUrl: string,
|
||||
|
||||
@@ -35,8 +36,14 @@ export function findParent(path: string) {
|
||||
|
||||
class FileTree extends React.Component<Props> {
|
||||
render() {
|
||||
const { tree, path, baseUrl, classes, t } = this.props;
|
||||
const baseUrlWithRevision = baseUrl + "/" + tree.revision;
|
||||
const { tree, revision, path, baseUrl, classes, t } = this.props;
|
||||
|
||||
let baseUrlWithRevision = baseUrl;
|
||||
if (revision) {
|
||||
baseUrlWithRevision += "/" + revision;
|
||||
} else {
|
||||
baseUrlWithRevision += "/" + tree.revision;
|
||||
}
|
||||
|
||||
const files = [];
|
||||
if (path) {
|
||||
|
||||
@@ -21,13 +21,24 @@ type Props = {
|
||||
classes: any
|
||||
};
|
||||
|
||||
export function createLink(base: string, file: File) {
|
||||
let link = base;
|
||||
if (file.path) {
|
||||
let path = file.path;
|
||||
if (path.startsWith("/")) {
|
||||
path = path.substring(1);
|
||||
}
|
||||
link += "/" + path;
|
||||
}
|
||||
if (!link.endsWith("/")) {
|
||||
link += "/";
|
||||
}
|
||||
return link;
|
||||
}
|
||||
|
||||
class FileTreeLeaf extends React.Component<Props> {
|
||||
createLink = (file: File) => {
|
||||
let link = this.props.baseUrl;
|
||||
if (file.path) {
|
||||
link += "/" + file.path + "/";
|
||||
}
|
||||
return link;
|
||||
return createLink(this.props.baseUrl, file);
|
||||
};
|
||||
|
||||
createFileIcon = (file: File) => {
|
||||
|
||||
24
scm-ui/src/repos/sources/components/FileTreeLeaf.test.js
Normal file
24
scm-ui/src/repos/sources/components/FileTreeLeaf.test.js
Normal file
@@ -0,0 +1,24 @@
|
||||
// @flow
|
||||
|
||||
import { createLink } from "./FileTreeLeaf";
|
||||
import type { File } from "@scm-manager/ui-types";
|
||||
|
||||
describe("create link tests", () => {
|
||||
function dir(path: string): File {
|
||||
return {
|
||||
name: "dir",
|
||||
path: path,
|
||||
directory: true
|
||||
};
|
||||
}
|
||||
|
||||
it("should create link", () => {
|
||||
expect(createLink("src", dir("main"))).toBe("src/main/");
|
||||
expect(createLink("src", dir("/main"))).toBe("src/main/");
|
||||
expect(createLink("src", dir("/main/"))).toBe("src/main/");
|
||||
});
|
||||
|
||||
it("should return base url if the directory path is empty", () => {
|
||||
expect(createLink("src", dir(""))).toBe("src/");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user