keep entered revision in source browser

This commit is contained in:
Sebastian Sdorra
2018-09-28 12:12:56 +02:00
parent d1a9a1c63a
commit 7b807fa880
4 changed files with 58 additions and 9 deletions

View File

@@ -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) {

View File

@@ -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) => {

View 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/");
});
});