mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 07:25:44 +01:00
Show size for empty files, but not for directories
This commit is contained in:
@@ -6,9 +6,9 @@ type Props = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
class FileSize extends React.Component<Props> {
|
class FileSize extends React.Component<Props> {
|
||||||
static format(bytes) {
|
static format(bytes: number) {
|
||||||
if (!bytes) {
|
if (!bytes) {
|
||||||
return "";
|
return "0 B";
|
||||||
}
|
}
|
||||||
|
|
||||||
const units = ["B", "K", "M", "G", "T", "P", "E", "Z", "Y"];
|
const units = ["B", "K", "M", "G", "T", "P", "E", "Z", "Y"];
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import FileSize from "./FileSize";
|
import FileSize from "./FileSize";
|
||||||
|
|
||||||
it("should format bytes", () => {
|
it("should format bytes", () => {
|
||||||
expect(FileSize.format(160)).toBe("160.00 B");
|
expect(FileSize.format(0)).toBe("0 B");
|
||||||
|
expect(FileSize.format(160)).toBe("160 B");
|
||||||
expect(FileSize.format(6304)).toBe("6.16 K");
|
expect(FileSize.format(6304)).toBe("6.16 K");
|
||||||
expect(FileSize.format(28792588)).toBe("27.46 M");
|
expect(FileSize.format(28792588)).toBe("27.46 M");
|
||||||
expect(FileSize.format(1369510189)).toBe("1.28 G");
|
expect(FileSize.format(1369510189)).toBe("1.28 G");
|
||||||
|
|||||||
@@ -62,13 +62,13 @@ class FileTreeLeaf extends React.Component<Props> {
|
|||||||
render() {
|
render() {
|
||||||
const { file, classes } = this.props;
|
const { file, classes } = this.props;
|
||||||
|
|
||||||
|
const fileSize = file.directory ? "" : <FileSize bytes={file.length} />;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<tr>
|
<tr>
|
||||||
<td className={classes.iconColumn}>{this.createFileIcon(file)}</td>
|
<td className={classes.iconColumn}>{this.createFileIcon(file)}</td>
|
||||||
<td>{this.createFileName(file)}</td>
|
<td>{this.createFileName(file)}</td>
|
||||||
<td>
|
<td>{fileSize}</td>
|
||||||
<FileSize bytes={file.length} />
|
|
||||||
</td>
|
|
||||||
<td>
|
<td>
|
||||||
<DateFromNow date={file.lastModified} />
|
<DateFromNow date={file.lastModified} />
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
Reference in New Issue
Block a user