Make partial file attributes explicit.

This commit is contained in:
Rene Pfeuffer
2019-12-18 11:48:17 +01:00
parent 0d6dcbd6bd
commit cf9d1edb70
16 changed files with 190 additions and 103 deletions

View File

@@ -133,7 +133,7 @@ class FileTree extends React.Component<Props, State> {
<FixedWidthTh />
<th>{t("sources.file-tree.name")}</th>
<th className="is-hidden-mobile">{t("sources.file-tree.length")}</th>
<th className="is-hidden-mobile">{t("sources.file-tree.lastModified")}</th>
<th className="is-hidden-mobile">{t("sources.file-tree.commitDate")}</th>
<th className="is-hidden-touch">{t("sources.file-tree.description")}</th>
{binder.hasExtension("repos.sources.tree.row.right") && <th className="is-hidden-mobile" />}
</tr>

View File

@@ -64,9 +64,11 @@ class FileTreeLeaf extends React.Component<Props> {
return <Link to={this.createLink(file)}>{file.name}</Link>;
};
contentIfPresent = (file: File, content: any) => {
contentIfPresent = (file: File, attribute: string, content: (file: File) => any) => {
const { t } = this.props;
if (file.computationAborted) {
if (file.hasOwnProperty(attribute)) {
return content(file);
} else if (file.computationAborted) {
return (
<Tooltip location="top" message={t("sources.file-tree.computationAborted")}>
<Icon name={"question-circle"} />
@@ -79,23 +81,24 @@ class FileTreeLeaf extends React.Component<Props> {
</Tooltip>
);
} else {
return content;
return content(file);
}
};
render() {
const { file } = this.props;
const fileSize = file.directory ? "" : <FileSize bytes={file.length} />;
const renderFileSize = (file: File) => <FileSize bytes={file.length} />;
const renderCommitDate = (file: File) => <DateFromNow date={file.commitDate} />;
return (
<tr>
<td>{this.createFileIcon(file)}</td>
<MinWidthTd className="is-word-break">{this.createFileName(file)}</MinWidthTd>
<NoWrapTd className="is-hidden-mobile">{fileSize}</NoWrapTd>
<td className="is-hidden-mobile">{this.contentIfPresent(file, <DateFromNow date={file.lastModified} />)}</td>
<NoWrapTd className="is-hidden-mobile">{file.directory ? "" : this.contentIfPresent(file, "length", renderFileSize)}</NoWrapTd>
<td className="is-hidden-mobile">{this.contentIfPresent(file, "commitDate", renderCommitDate)}</td>
<MinWidthTd className={classNames("is-word-break", "is-hidden-touch")}>
{this.contentIfPresent(file, file.description)}
{this.contentIfPresent(file, "description", file => file.description)}
</MinWidthTd>
{binder.hasExtension("repos.sources.tree.row.right") && (
<td className="is-hidden-mobile">

View File

@@ -115,7 +115,7 @@ class Content extends React.Component<Props, State> {
showMoreInformation() {
const collapsed = this.state.collapsed;
const { file, revision, t, repository } = this.props;
const date = <DateFromNow date={file.lastModified} />;
const date = <DateFromNow date={file.commitDate} />;
const description = file.description ? (
<p>
{file.description.split("\n").map((item, key) => {

View File

@@ -49,10 +49,8 @@ const collection = {
name: "src",
path: "src",
directory: true,
description: "",
length: 176,
revision: "76aae4bb4ceacf0e88938eb5b6832738b7d537b4",
lastModified: "",
subRepository: undefined,
_links: {
self: {
@@ -71,7 +69,7 @@ const collection = {
description: "bump version",
length: 780,
revision: "76aae4bb4ceacf0e88938eb5b6832738b7d537b4",
lastModified: "2017-07-31T11:17:19Z",
commitDate: "2017-07-31T11:17:19Z",
subRepository: undefined,
_links: {
self: {