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

111 lines
2.6 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";
import classNames from "classnames";
import { binder, ExtensionPoint } from "@scm-manager/ui-extensions";
2018-09-27 16:32:37 +02:00
const styles = {
iconColumn: {
width: "16px"
},
wordBreakMinWidth: {
2018-12-14 10:42:20 +01:00
minWidth: "10em"
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={classNames(classes.wordBreakMinWidth, "is-word-break")}>
{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
className={classNames(
classes.wordBreakMinWidth,
"is-word-break",
"is-hidden-mobile"
)}
>
{file.description}
</td>
{binder.hasExtension("sourceView.right") &&
!file.directory && (
<td>
<ExtensionPoint
name="sourceView.right"
props={{ file }}
renderAll={true}
/>
</td>
)}
2018-09-27 16:32:37 +02:00
</tr>
);
}
}
export default injectSheet(styles)(FileTreeLeaf);