2018-09-27 16:32:37 +02:00
|
|
|
//@flow
|
2018-09-28 11:31:38 +02:00
|
|
|
import * as React from "react";
|
2018-09-27 16:32:37 +02:00
|
|
|
import { Link } from "react-router-dom";
|
2018-12-19 08:40:04 +01:00
|
|
|
import classNames from "classnames";
|
2019-10-09 16:17:02 +02:00
|
|
|
import styled from "styled-components";
|
2019-08-27 15:16:02 +02:00
|
|
|
import { binder, ExtensionPoint } from "@scm-manager/ui-extensions";
|
2019-10-09 16:17:02 +02:00
|
|
|
import type { File } from "@scm-manager/ui-types";
|
|
|
|
|
import { DateFromNow, FileSize } from "@scm-manager/ui-components";
|
|
|
|
|
import FileIcon from "./FileIcon";
|
2018-09-27 16:32:37 +02:00
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
file: File,
|
2019-10-09 16:17:02 +02:00
|
|
|
baseUrl: string
|
2018-09-27 16:32:37 +02:00
|
|
|
};
|
|
|
|
|
|
2019-10-09 16:17:02 +02:00
|
|
|
const MinWidthTd = styled.td`
|
|
|
|
|
min-width: 10em;
|
|
|
|
|
`;
|
|
|
|
|
|
2018-09-28 12:12:56 +02:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-09 16:17:02 +02:00
|
|
|
export default class FileTreeLeaf extends React.Component<Props> {
|
2018-09-28 11:31:38 +02:00
|
|
|
createLink = (file: File) => {
|
2018-09-28 12:12:56 +02:00
|
|
|
return createLink(this.props.baseUrl, file);
|
2018-09-28 11:31:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
createFileIcon = (file: File) => {
|
|
|
|
|
if (file.directory) {
|
|
|
|
|
return (
|
|
|
|
|
<Link to={this.createLink(file)}>
|
|
|
|
|
<FileIcon file={file} />
|
|
|
|
|
</Link>
|
|
|
|
|
);
|
|
|
|
|
}
|
2018-10-25 11:27:31 +02:00
|
|
|
return (
|
|
|
|
|
<Link to={this.createLink(file)}>
|
|
|
|
|
<FileIcon file={file} />
|
|
|
|
|
</Link>
|
|
|
|
|
);
|
2018-09-28 11:31:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
createFileName = (file: File) => {
|
|
|
|
|
if (file.directory) {
|
|
|
|
|
return <Link to={this.createLink(file)}>{file.name}</Link>;
|
|
|
|
|
}
|
2018-10-25 11:27:31 +02:00
|
|
|
return <Link to={this.createLink(file)}>{file.name}</Link>;
|
2018-09-28 11:31:38 +02:00
|
|
|
};
|
|
|
|
|
|
2018-09-27 16:32:37 +02:00
|
|
|
render() {
|
2019-10-09 16:17:02 +02:00
|
|
|
const { file } = this.props;
|
2018-09-27 16:32:37 +02:00
|
|
|
|
2018-10-17 15:34:22 +02:00
|
|
|
const fileSize = file.directory ? "" : <FileSize bytes={file.length} />;
|
|
|
|
|
|
2018-09-27 16:32:37 +02:00
|
|
|
return (
|
|
|
|
|
<tr>
|
2019-10-09 16:17:02 +02:00
|
|
|
<td>{this.createFileIcon(file)}</td>
|
|
|
|
|
<MinWidthTd className="is-word-break">
|
2019-08-27 15:16:02 +02:00
|
|
|
{this.createFileName(file)}
|
2019-10-09 16:17:02 +02:00
|
|
|
</MinWidthTd>
|
2018-10-24 10:14:42 +02:00
|
|
|
<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>
|
2019-10-09 16:17:02 +02:00
|
|
|
<MinWidthTd className={classNames("is-word-break", "is-hidden-mobile")}>
|
2018-12-19 08:40:04 +01:00
|
|
|
{file.description}
|
2019-10-09 16:17:02 +02:00
|
|
|
</MinWidthTd>
|
2019-08-29 16:27:40 +02:00
|
|
|
{binder.hasExtension("repos.sources.tree.row.right") && (
|
2019-09-11 08:29:34 +02:00
|
|
|
<td className="is-hidden-mobile">
|
2019-08-28 09:55:48 +02:00
|
|
|
{!file.directory && (
|
2019-08-27 15:16:02 +02:00
|
|
|
<ExtensionPoint
|
2019-08-29 16:27:40 +02:00
|
|
|
name="repos.sources.tree.row.right"
|
2019-08-27 15:16:02 +02:00
|
|
|
props={{ file }}
|
|
|
|
|
renderAll={true}
|
|
|
|
|
/>
|
2019-08-28 09:55:48 +02:00
|
|
|
)}
|
|
|
|
|
</td>
|
|
|
|
|
)}
|
2018-09-27 16:32:37 +02:00
|
|
|
</tr>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|