Files
SCM-Manager/scm-ui/src/repos/sources/components/FileTree.js

83 lines
1.8 KiB
JavaScript
Raw Normal View History

2018-09-27 16:32:37 +02:00
//@flow
import React from "react";
import { translate } from "react-i18next";
import injectSheet from "react-jss";
import FileTreeLeaf from "./FileTreeLeaf";
import type { File } from "@scm-manager/ui-types";
2018-09-27 16:32:37 +02:00
const styles = {
iconColumn: {
width: "16px"
}
};
type Props = {
tree: File,
revision: string,
path: string,
baseUrl: string,
2018-09-27 16:32:37 +02:00
// context props
classes: any,
t: string => string
};
export function findParent(path: string) {
if (path.endsWith("/")) {
path = path.substring(path, path.length - 1);
}
const index = path.lastIndexOf("/");
if (index > 0) {
return path.substring(0, index);
}
return "";
}
2018-09-27 16:32:37 +02:00
class FileTree extends React.Component<Props> {
render() {
const { tree, revision, path, baseUrl, classes, t } = this.props;
let baseUrlWithRevision = baseUrl;
if (revision) {
baseUrlWithRevision += "/" + revision;
} else {
baseUrlWithRevision += "/" + tree.revision;
}
2018-09-27 16:32:37 +02:00
const files = [];
if (path) {
files.push({
name: "..",
path: findParent(path),
directory: true
});
}
files.push(...tree._embedded.children);
2018-09-27 16:32:37 +02:00
return (
<table className="table table-hover table-sm is-fullwidth">
<thead>
<tr>
<th className={classes.iconColumn} />
<th>{t("sources.file-tree.name")}</th>
<th>{t("sources.file-tree.length")}</th>
<th>{t("sources.file-tree.lastModified")}</th>
<th>{t("sources.file-tree.description")}</th>
</tr>
</thead>
<tbody>
{files.map(file => (
<FileTreeLeaf
key={file.name}
file={file}
baseUrl={baseUrlWithRevision}
/>
2018-09-27 16:32:37 +02:00
))}
</tbody>
</table>
);
}
}
export default injectSheet(styles)(translate("repos")(FileTree));