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

115 lines
3.1 KiB
TypeScript
Raw Normal View History

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";
import { DateFromNow, FileSize, Tooltip } from "@scm-manager/ui-components";
import FileIcon from "./FileIcon";
import { Icon } from "@scm-manager/ui-components/src";
import { WithTranslation, withTranslation } from "react-i18next";
2018-09-27 16:32:37 +02:00
type Props = WithTranslation & {
file: File;
baseUrl: string;
2018-09-27 16:32:37 +02:00
};
const MinWidthTd = styled.td`
min-width: 10em;
`;
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;
}
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>;
};
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() {
const { file } = this.props;
2018-09-27 16:32:37 +02:00
const fileSize = file.directory ? "" : <FileSize bytes={file.length} />;
2018-09-27 16:32:37 +02:00
return (
<tr>
<td>{this.createFileIcon(file)}</td>
2019-10-21 10:57:56 +02:00
<MinWidthTd className="is-word-break">{this.createFileName(file)}</MinWidthTd>
2019-12-12 11:52:44 +01:00
<td className="is-hidden-mobile">{this.contentIfPresent(file, fileSize)}</td>
<td className="is-hidden-mobile">{this.contentIfPresent(file, <DateFromNow date={file.lastModified} />)}</td>
<MinWidthTd className={classNames("is-word-break", "is-hidden-mobile")}>
{this.contentIfPresent(file, file.description)}
</MinWidthTd>
{binder.hasExtension("repos.sources.tree.row.right") && (
<td className="is-hidden-mobile">
{!file.directory && (
<ExtensionPoint
2019-08-29 16:27:40 +02:00
name="repos.sources.tree.row.right"
props={{
file
}}
renderAll={true}
/>
)}
</td>
)}
2018-09-27 16:32:37 +02:00
</tr>
);
}
}
export default withTranslation("repos")(FileTreeLeaf);