2019-10-20 18:02:52 +02:00
|
|
|
import * as React from "react";
|
|
|
|
|
import { Link } from "react-router-dom";
|
|
|
|
|
import classNames from "classnames";
|
|
|
|
|
import styled from "styled-components";
|
|
|
|
|
import { binder, ExtensionPoint } from "@scm-manager/ui-extensions";
|
|
|
|
|
import { File } from "@scm-manager/ui-types";
|
2019-12-12 11:47:03 +01:00
|
|
|
import { DateFromNow, FileSize, Tooltip } from "@scm-manager/ui-components";
|
2019-10-20 18:02:52 +02:00
|
|
|
import FileIcon from "./FileIcon";
|
2019-12-12 11:47:03 +01:00
|
|
|
import { Icon } from "@scm-manager/ui-components/src";
|
|
|
|
|
import { WithTranslation, withTranslation } from "react-i18next";
|
2018-09-27 16:32:37 +02:00
|
|
|
|
2019-12-12 11:47:03 +01:00
|
|
|
type Props = WithTranslation & {
|
2019-10-19 16:38:07 +02:00
|
|
|
file: File;
|
|
|
|
|
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;
|
|
|
|
|
`;
|
|
|
|
|
|
2019-12-11 23:15:52 +01:00
|
|
|
const NoWrapTd = styled.td`
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
`;
|
|
|
|
|
|
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;
|
2019-10-20 18:02:52 +02:00
|
|
|
if (path.startsWith("/")) {
|
2018-09-28 12:12:56 +02:00
|
|
|
path = path.substring(1);
|
|
|
|
|
}
|
2019-10-20 18:02:52 +02:00
|
|
|
link += "/" + path;
|
2018-09-28 12:12:56 +02:00
|
|
|
}
|
2019-10-20 18:02:52 +02:00
|
|
|
if (!link.endsWith("/")) {
|
|
|
|
|
link += "/";
|
2018-09-28 12:12:56 +02:00
|
|
|
}
|
|
|
|
|
return link;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-12 11:47:03 +01:00
|
|
|
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
|
|
|
};
|
|
|
|
|
|
2019-12-12 11:47:03 +01:00
|
|
|
contentIfPresent = (file: File, content: any) => {
|
|
|
|
|
const { t } = this.props;
|
|
|
|
|
if (file.computationAborted) {
|
|
|
|
|
return (
|
|
|
|
|
<Tooltip location="top" message={t("sources.file-tree.computationAborted")}>
|
|
|
|
|
<Icon name={"question-circle"} />
|
|
|
|
|
</Tooltip>
|
|
|
|
|
);
|
|
|
|
|
} else if (file.partialResult) {
|
|
|
|
|
return (
|
|
|
|
|
<Tooltip location="top" message={t("sources.file-tree.notYetComputed")}>
|
|
|
|
|
<Icon name={"hourglass"} />
|
|
|
|
|
</Tooltip>
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
return content;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
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
|
|
|
|
2019-10-20 18:02:52 +02:00
|
|
|
const fileSize = file.directory ? "" : <FileSize bytes={file.length} />;
|
2018-10-17 15:34:22 +02:00
|
|
|
|
2018-09-27 16:32:37 +02:00
|
|
|
return (
|
|
|
|
|
<tr>
|
2019-10-09 16:17:02 +02:00
|
|
|
<td>{this.createFileIcon(file)}</td>
|
2019-10-21 10:57:56 +02:00
|
|
|
<MinWidthTd className="is-word-break">{this.createFileName(file)}</MinWidthTd>
|
2019-12-11 23:15:52 +01:00
|
|
|
<NoWrapTd className="is-hidden-mobile">{fileSize}</NoWrapTd>
|
2019-12-12 11:47:03 +01:00
|
|
|
<td className="is-hidden-mobile">{this.contentIfPresent(file, <DateFromNow date={file.lastModified} />)}</td>
|
2019-12-17 14:14:34 +01:00
|
|
|
<MinWidthTd className={classNames("is-word-break", "is-hidden-touch")}>
|
2019-12-12 11:47:03 +01:00
|
|
|
{this.contentIfPresent(file, file.description)}
|
|
|
|
|
</MinWidthTd>
|
2019-10-20 18:02:52 +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-10-19 16:38:07 +02:00
|
|
|
props={{
|
2019-10-20 18:02:52 +02:00
|
|
|
file
|
2019-10-19 16:38:07 +02:00
|
|
|
}}
|
2019-08-27 15:16:02 +02:00
|
|
|
renderAll={true}
|
|
|
|
|
/>
|
2019-08-28 09:55:48 +02:00
|
|
|
)}
|
|
|
|
|
</td>
|
|
|
|
|
)}
|
2018-09-27 16:32:37 +02:00
|
|
|
</tr>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-12-12 11:47:03 +01:00
|
|
|
|
|
|
|
|
export default withTranslation("repos")(FileTreeLeaf);
|