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

93 lines
2.1 KiB
JavaScript
Raw Normal View History

2018-09-27 16:32:37 +02:00
//@flow
import * as React from "react";
2018-09-27 16:32:37 +02:00
import injectSheet from "react-jss";
import { DateFromNow } from "@scm-manager/ui-components";
import FileSize from "./FileSize";
import FileIcon from "./FileIcon";
import { Link } from "react-router-dom";
import type { File } from "@scm-manager/ui-types";
const styles = {
iconColumn: {
width: "16px"
},
wordBreakTable: {
WebkitHyphens: "auto",
MozHyphens: "auto",
MsHyphens: "auto",
hyphens: "auto",
wordBreak: "auto"
2018-09-27 16:32:37 +02:00
}
};
type Props = {
file: File,
baseUrl: string,
2018-09-27 16:32:37 +02:00
// context 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;
}
2018-09-27 16:32:37 +02:00
class FileTreeLeaf extends React.Component<Props> {
createLink = (file: File) => {
return createLink(this.props.baseUrl, file);
};
createFileIcon = (file: File) => {
if (file.directory) {
return (
<Link to={this.createLink(file)}>
<FileIcon file={file} />
</Link>
);
}
return (
<Link to={this.createLink(file)}>
<FileIcon file={file} />
</Link>
);
};
createFileName = (file: File) => {
if (file.directory) {
return <Link to={this.createLink(file)}>{file.name}</Link>;
}
return <Link to={this.createLink(file)}>{file.name}</Link>;
};
2018-09-27 16:32:37 +02:00
render() {
const { file, classes } = this.props;
const fileSize = file.directory ? "" : <FileSize bytes={file.length} />;
2018-09-27 16:32:37 +02:00
return (
<tr>
<td className={classes.iconColumn}>{this.createFileIcon(file)}</td>
<td className={classes.wordBreakTable}>{this.createFileName(file)}</td>
<td className="is-hidden-mobile">{fileSize}</td>
<td className="is-hidden-mobile">
2018-09-27 16:32:37 +02:00
<DateFromNow date={file.lastModified} />
</td>
<td>{file.description}</td>
</tr>
);
}
}
export default injectSheet(styles)(FileTreeLeaf);